Class StableSampler.SpecialMath
java.lang.Object
org.apache.commons.rng.sampling.distribution.StableSampler.SpecialMath
- Enclosing class:
StableSampler
Implement special math functions required by the CMS algorithm.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double4/pi.private static final doubletan2 product constant.private static final doubletan2 product constant.private static final doubletan2 product constant.private static final doubletan2 product constant.private static final doubletan2 product constant.private static final doublepi/4.private static final doubletan2 quotient constant.private static final doubletan2 quotient constant.private static final doubletan2 quotient constant.private static final doubletan2 quotient constant.private static final doubletan2 quotient constant.private static final doubleThe threshold to switch to usingMath.expm1(double). -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
PI_4
private static final double PI_4pi/4.- See Also:
-
FOUR_PI
private static final double FOUR_PI4/pi.- See Also:
-
P0
private static final double P0tan2 product constant.- See Also:
-
P1
private static final double P1tan2 product constant.- See Also:
-
P2
private static final double P2tan2 product constant.- See Also:
-
P3
private static final double P3tan2 product constant.- See Also:
-
P4
private static final double P4tan2 product constant.- See Also:
-
Q0
private static final double Q0tan2 quotient constant.- See Also:
-
Q1
private static final double Q1tan2 quotient constant.- See Also:
-
Q2
private static final double Q2tan2 quotient constant.- See Also:
-
Q3
private static final double Q3tan2 quotient constant.- See Also:
-
Q4
private static final double Q4tan2 quotient constant.- See Also:
-
SWITCH_TO_EXPM1
private static final double SWITCH_TO_EXPM1The threshold to switch to usingMath.expm1(double). The following table shows the mean (max) ULP difference between using expm1 and exp using random +/-x with different exponents (n=2^30):x exp positive x negative x 64.0 6 0.10004021506756544 (2) 0.0 (0) 32.0 5 0.11177831795066595 (2) 0.0 (0) 16.0 4 0.0986650362610817 (2) 9.313225746154785E-10 (1) 8.0 3 0.09863092936575413 (2) 4.9658119678497314E-6 (1) 4.0 2 0.10015273280441761 (2) 4.547201097011566E-4 (1) 2.0 1 0.14359260816127062 (2) 0.005623611621558666 (2) 1.0 0 0.20160607434809208 (2) 0.03312791418284178 (2) 0.5 -1 0.3993037799373269 (2) 0.28186883218586445 (2) 0.25 -2 0.6307008266448975 (2) 0.5192863345146179 (2) 0.125 -3 1.3862918205559254 (4) 1.386285437270999 (4) 0.0625 -4 2.772640804760158 (8) 2.772612397558987 (8)
The threshold of 0.5 has a mean ULP below 0.5 and max ULP of 2. The transition is monotonic. Neither is true for the next threshold of 0.25.
- See Also:
-
-
Constructor Details
-
SpecialMath
private SpecialMath()No instances.
-
-
Method Details
-
d2
static double d2(double x) Evaluate(exp(x) - 1) / x. Forxin the range[-inf, inf]returns a result in[0, inf].- For
x=-infthis returns0. - For
x=0this returns1. - For
x=infthis returnsinf. - For
x=nanthis returnsnan.
This corrects
0 / 0andinf / infdivision fromNaNto either1or the upper bound respectively.- Parameters:
x- value to evaluate- Returns:
(exp(x) - 1) / x.
- For
-
tan2
static double tan2(double x) Evaluatetan(x) / x.For
xin the range[0, pi/4]this returns a value in the range[1, 4 / pi].The following properties are desirable for the CMS algorithm:
- For
x=0this returns1. - For
x=pi/4this returns4/pi. - For
x=pi/4this multiplied byxreturns1.
This method is called by the CMS algorithm when
x < pi/4. In this case the method is almost as accurate asMath.tan(x) / x, does not require checking forx=0and is faster.- Parameters:
x- the x- Returns:
tan(x) / x.
- For
-