Skip to content

Commit eb029fc

Browse files
committed
Mention alg selection
1 parent 8748b98 commit eb029fc

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AlphaStableDistributions"
22
uuid = "f20549b4-2d50-407f-863c-cdd202ba59a3"
33
authors = ["Fredrik Bagge Carlson", "Too Yuen Min"]
4-
version = "0.1.2"
4+
version = "1.0.0"
55

66
[deps]
77
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ AlphaStable{Float64}(α=1.5, β=0.0, scale=1.0, location=0.0)
2121

2222
julia> s = rand(d1, 100000);
2323

24-
julia> d2 = fit(AlphaStable, s)
24+
julia> d2 = fit(AlphaStable, s, alg=QuickSort) # See ThreadsX.QuickSort for a threaded algorithm
2525

2626
AlphaStable{Float64}=1.4748701622930906, β=0.0, scale=1.006340087707924, location=-0.0036724481641865715)
2727

src/AlphaStableDistributions.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ const _ena = [
5454
]
5555

5656
"""
57+
fit(d::Type{<:AlphaStable}, x; alg=QuickSort)
58+
5759
Fit a symmetric α stable distribution to data.
5860
59-
:param x: data
60-
:returns: (α, c, δ)
61+
returns `AlphaStable`
6162
6263
α, c and δ are the characteristic exponent, scale parameter
6364
(dispersion^1/α) and location parameter respectively.
@@ -66,11 +67,11 @@ Fit a symmetric α stable distribution to data.
6667
c is computed based on Fama & Roll (1971) fractile.
6768
δ is the 50% trimmed mean of the sample.
6869
"""
69-
function Distributions.fit(d::Type{<:AlphaStable}, x, alg=QuickSort)
70+
function Distributions.fit(d::Type{<:AlphaStable}, x; alg=QuickSort)
7071
sx = sort(x, alg=alg)
71-
δ = mean(@view(sx[end÷4:(3*end)÷4]))
72-
p = quantile.(Ref(sx), (0.05, 0.25, 0.28, 0.72, 0.75, 0.95), sorted=true)
73-
c = (p[4]-p[3])/1.654
72+
δ = mean(@view(sx[end÷4:(3*end)÷4]))
73+
p = quantile.(Ref(sx), (0.05, 0.25, 0.28, 0.72, 0.75, 0.95), sorted=true)
74+
c = (p[4]-p[3])/1.654
7475
an = (p[6]-p[1])/(p[5]-p[2])
7576
if an < 2.4388
7677
α = 2.

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,9 @@ end
8686
# using Cthulhu
8787
# d = AlphaSubGaussian(n=96)
8888
# @descend_code_warntype rand(Random.GLOBAL_RNG, d)
89+
#
90+
# using AlphaStableDistributions
91+
# d1 = AlphaStable(α=1.5)
92+
# s = rand(d1, 100000)
93+
# using ThreadsX
94+
# @btime fit($AlphaStable, $s, $ThreadsX.MergeSort)

0 commit comments

Comments
 (0)