Class StableSampler.WeronStableSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.StableSampler
-
- org.apache.commons.rng.sampling.distribution.StableSampler.BaseStableSampler
-
- org.apache.commons.rng.sampling.distribution.StableSampler.WeronStableSampler
-
- All Implemented Interfaces:
ContinuousSampler
,SharedStateContinuousSampler
,SharedStateSampler<SharedStateContinuousSampler>
- Direct Known Subclasses:
StableSampler.CMSStableSampler
- Enclosing class:
- StableSampler
static class StableSampler.WeronStableSampler extends StableSampler.BaseStableSampler
Implement the generic stable distribution case:alpha < 2
andbeta != 0
. This routine assumesalpha != 1
.Implements the Chambers-Mallows-Stuck (CMS) method using the formula provided in Weron (1996) "On the Chambers-Mallows-Stuck method for simulating skewed stable random variables" Statistics & Probability Letters. 28 (2): 165–171. This method is easier to correct from infinite and NaN results by boxing intermediate infinite values.
The formula produces a stable deviate from the 1-parameterization that is discontinuous at
alpha=1
. A shift is used to create the 0-parameterization. This shift is very large asalpha -> 1
and the output loses bits of precision in the deviate due to cancellation. It is not recommended to use this sampler whenalpha -> 1
except for edge case correction.This produces non-NaN output for all parameters alpha, beta, u and w with the correct orientation for extremes of the distribution support. The formulas used are symmetric with regard to beta and u.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.commons.rng.sampling.distribution.StableSampler
StableSampler.Alpha1CMSStableSampler, StableSampler.Beta0CMSStableSampler, StableSampler.Beta0WeronStableSampler, StableSampler.CMSStableSampler, StableSampler.SpecialMath, StableSampler.WeronStableSampler
-
-
Field Summary
Fields Modifier and Type Field Description protected double
atanZeta
Cache of expression value used in generation.protected double
eps
Epsilon (1 - alpha).protected double
epsDiv1mEps
(1 / alpha) - 1 = eps / (1 - eps).protected double
inv1mEps
1 / alpha = 1 / (1 - eps).protected double
lower
The inclusive lower support for the distribution.protected double
meps1
Alpha (1 - eps).protected double
scale
Cache of expression value used in generation.protected double
upper
The inclusive upper support for the distribution.protected double
zeta
Cache of expression value used in generation.
-
Constructor Summary
Constructors Constructor Description WeronStableSampler(UniformRandomProvider rng, double alpha, double beta)
WeronStableSampler(UniformRandomProvider rng, StableSampler.WeronStableSampler source)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected double
createSample(double phi, double w)
Create the sample.double
sample()
Generate a sample from a stable distribution.StableSampler.WeronStableSampler
withUniformRandomProvider(UniformRandomProvider rng)
Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.-
Methods inherited from class org.apache.commons.rng.sampling.distribution.StableSampler.BaseStableSampler
getOmega, getPhi, getPhiBy2
-
Methods inherited from class org.apache.commons.rng.sampling.distribution.StableSampler
nextLong, of, of, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.rng.sampling.distribution.ContinuousSampler
samples, samples
-
-
-
-
Field Detail
-
eps
protected final double eps
Epsilon (1 - alpha).
-
meps1
protected final double meps1
Alpha (1 - eps).
-
zeta
protected final double zeta
Cache of expression value used in generation.
-
atanZeta
protected final double atanZeta
Cache of expression value used in generation.
-
scale
protected final double scale
Cache of expression value used in generation.
-
inv1mEps
protected final double inv1mEps
1 / alpha = 1 / (1 - eps).
-
epsDiv1mEps
protected final double epsDiv1mEps
(1 / alpha) - 1 = eps / (1 - eps).
-
lower
protected final double lower
The inclusive lower support for the distribution.
-
upper
protected final double upper
The inclusive upper support for the distribution.
-
-
Constructor Detail
-
WeronStableSampler
WeronStableSampler(UniformRandomProvider rng, double alpha, double beta)
- Parameters:
rng
- Underlying source of randomnessalpha
- Stability parameter. Must be in the interval(0, 2]
.beta
- Skewness parameter. Must be in the interval[-1, 1]
.
-
WeronStableSampler
WeronStableSampler(UniformRandomProvider rng, StableSampler.WeronStableSampler source)
- Parameters:
rng
- Underlying source of randomnesssource
- Source to copy.
-
-
Method Detail
-
sample
public double sample()
Description copied from class:StableSampler
Generate a sample from a stable distribution.The distribution uses the 0-parameterization: S(alpha, beta, gamma, delta; 0).
- Specified by:
sample
in interfaceContinuousSampler
- Specified by:
sample
in classStableSampler
- Returns:
- a sample.
-
createSample
protected double createSample(double phi, double w)
Create the sample. This routine is robust to edge cases and returns a deviate at the extremes of the support. It correctly handlesalpha -> 0
when the sample is increasingly likely to be +/- infinity.- Parameters:
phi
- Uniform deviate in(-pi/2, pi/2)
w
- Exponential deviate- Returns:
- x
-
withUniformRandomProvider
public StableSampler.WeronStableSampler withUniformRandomProvider(UniformRandomProvider rng)
Description copied from class:StableSampler
Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.- Specified by:
withUniformRandomProvider
in interfaceSharedStateSampler<SharedStateContinuousSampler>
- Specified by:
withUniformRandomProvider
in classStableSampler
- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-
-