@@ -121,26 +121,40 @@ function Base.rand(rng::AbstractRNG, d::AlphaStable)
121121 bϕ = π/ 2 + β* ϕ
122122 x = 2 / π * (bϕ* tan (ϕ) - β* log (π/ 2 * w* cosϕ/ bϕ))
123123 α == 1 || (x += β * tan (π* α/ 2 ))
124-
124+
125125 return loc + scale* x
126126end
127127
128128
129129"""
130- ...
130+
131+ Generate alpha-sub-Gaussian (aSG) random numbers.
132+
133+ The implementation is based on https://github.com/ahmd-mahm/alpha-SGNm/blob/master/asgn.m
134+
135+ Reference:
136+ A. Mahmood and M. Chitre, "Generating random variates for stable sub-Gaussian processes
137+ with memory", Signal Processing, Volume 131, Pages 271-279, 2017.
138+ (https://doi.org/10.1016/j.sigpro.2016.08.016.)
139+
140+
131141# Arguments
132- - `alpha `: characteristic exponent associated with the aSGN(m) process. This is
142+ - `α `: characteristic exponent associated with the aSGN(m) process. This is
133143a scalar input and should lie within `collect(1.1:0.01:1.98)`.
134144- `R`: covariance matrix of any adjacent `m+1` samples in an aSGN(m) process.
135145The dimension of `R` is equal to `m+1`. It should be a symmetric toeplitz matrix.
136146The maximum acceptable size of `R` is `10x10`
137147- `n`: number of samples required
138- ...
148+
149+ # Examples
150+ ```jldoctest
151+ julia> x = rand(AlphaSubGaussian(n=1000))
152+ ```
139153"""
140154Base. @kwdef struct AlphaSubGaussian{T,M<: AbstractMatrix } <: Distributions.ContinuousUnivariateDistribution
141155 α:: T = 1.50
142156 R:: M = SMatrix {5,5} (collect (SymmetricToeplitz ([1.0000 , 0.5804 , 0.2140 , 0.1444 , - 0.0135 ])))
143- n:: Int = 10000
157+ n:: Int
144158end
145159
146160"""
@@ -184,23 +198,10 @@ function subgausscondprobtabulate(α, x1, x2_ind, invRx1, invR, vjoint, nmin, nm
184198 (1 / sqrt (kappa))* kmarg* vjointR/ vjointR1
185199end
186200
187- """
188- Generate alpha-sub-Gaussian (aSG) random numbers.
189-
190- The implementation is based on https://github.com/ahmd-mahm/alpha-SGNm/blob/master/asgn.m
191201
192- Reference:
193- A. Mahmood and M. Chitre, "Generating random variates for stable sub-Gaussian processes
194- with memory", Signal Processing, Volume 131, Pages 271-279, 2017.
195- (https://doi.org/10.1016/j.sigpro.2016.08.016.)
196-
197- # Examples
198- ```jldoctest
199- julia> x = rand(AlphaSubGaussian(n=1000))
200- ```
201- """
202- function Base. rand (rng:: AbstractRNG , d:: AlphaSubGaussian )
202+ function Random. rand! (rng:: AbstractRNG , d:: AlphaSubGaussian , x:: AbstractArray )
203203 α= d. α; R= d. R; n= d. n
204+ length (x) >= n || throw (ArgumentError (" length of x must be at least n" ))
204205 α ∈ 1.10 : 0.01 : 1.98 || throw (DomainError (α, " α must lie within `1.10:0.01:1.98`" ))
205206 m = size (R, 1 )- 1
206207 funk1 = x -> (2 ^ α)* sin (π* α/ 2 )* gamma ((α+ 2 )/ 2 )* gamma ((α+ x)/ 2 )/ (gamma (x/ 2 )* π* α/ 2 )
@@ -226,13 +227,13 @@ function Base.rand(rng::AbstractRNG, d::AlphaSubGaussian)
226227 S = S/ sqrt (sum (abs2,S))
227228 xtmp = ((sigrootx1* sqrt (A* T))* S)'
228229 if n<= m
229- x = xtmp[1 : n]
230+ copyto! (x, @view ( xtmp[1 : n]))
230231 else
231- x = zeros (n)
232+ # x = zeros(n)
232233 x[onetom] = xtmp
233234 vstud = α+ m
234235 norms = pdf (TDist (vstud), 0.0 )
235- for i = m+ 1 : n
236+ @inbounds for i = m+ 1 : n
236237 x1 = SVector {m,Float64} (view (x,i- m: i- 1 ))
237238 mode = modefactor* x1
238239 norm1 = subgausscondprobtabulate (α, x1, mode, invRx1, invR, vjoint, nmin, nmax, step, rind, kappa, k1, k2, kmarg)
@@ -252,4 +253,7 @@ function Base.rand(rng::AbstractRNG, d::AlphaSubGaussian)
252253 x
253254end
254255
256+
257+ Base. rand (rng:: AbstractRNG , d:: AlphaSubGaussian ) = rand! (rng, d, zeros (d. n))
258+
255259end # module
0 commit comments