Class StableSampler.CMSStableSampler
- All Implemented Interfaces:
ContinuousSampler
,SharedStateContinuousSampler
,SharedStateSampler<SharedStateContinuousSampler>
- Enclosing class:
StableSampler
alpha < 2
and
beta != 0
. This routine assumes alpha != 1
.
Implements the Chambers-Mallows-Stuck (CMS) method from Chambers, et al (1976) A Method for Simulating Stable Random Variables. Journal of the American Statistical Association Vol. 71, No. 354, pp. 340-344.
The formula produces a stable deviate from the 0-parameterization that is
continuous at alpha=1
.
This is an implementation of the Fortran routine RSTAB. In the event the
computation fails then an alternative computation is performed 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. The error correction path is extremely unlikely to occur during
use unless alpha -> 0
. In general use it requires the random deviates
w or u are extreme. See the unit tests for conditions that create them.
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
FieldsModifier and TypeFieldDescriptionprivate static final double
1/2.private final double
Cache of expression value used in generation.Fields inherited from class org.apache.commons.rng.sampling.distribution.StableSampler.WeronStableSampler
atanZeta, eps, epsDiv1mEps, inv1mEps, lower, meps1, scale, upper, zeta
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static double
getTau
(double alpha, double beta) Gets tau.double
sample()
Generate a sample from a stable distribution.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.WeronStableSampler
createSample
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 Details
-
HALF
private static final double HALF1/2.- See Also:
-
tau
private final double tauCache of expression value used in generation.
-
-
Constructor Details
-
CMSStableSampler
CMSStableSampler(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]
.
-
CMSStableSampler
CMSStableSampler(UniformRandomProvider rng, StableSampler.CMSStableSampler source) - Parameters:
rng
- Underlying source of randomnesssource
- Source to copy.
-
-
Method Details
-
getTau
static double getTau(double alpha, double beta) Gets tau. This is a factor used in the CMS algorithm. If this is zero then a special case ofbeta -> 0
has occurred.- Parameters:
alpha
- Stability parameter. Must be in the interval(0, 2]
.beta
- Skewness parameter. Must be in the interval[-1, 1]
.- Returns:
- tau
-
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
- Overrides:
sample
in classStableSampler.WeronStableSampler
- Returns:
- a sample.
-
withUniformRandomProvider
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>
- Overrides:
withUniformRandomProvider
in classStableSampler.WeronStableSampler
- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-