NumericQuantile

Class to compute quantile function as root of it's cumulative density function. Unstable algorithm.

abstract
class NumericQuantile : Quantile!T(
T
) {}

Constructors

this
this(CDF!T cdf, T a = -T.max, T b = T.max)

Constructor

Members

Functions

opCall
T opCall(T x)

Call operator

Examples

Numeric quantile function of standard normal distribution

1 import std.traits, std.mathspecial;
2 import atmosphere.pdf;
3 import atmosphere.cdf;
4 
5 class NormalPDF : PDF!real
6 {
7 	real opCall(real x)
8 	{
9 		// 1/sqrt(2 PI)
10 		enum c = 0.398942280401432677939946L;
11 		return c * exp(-0.5f * x * x);
12 	}
13 }
14 
15 class NormalCDF : NumericCDF!real ///$(RED Unstable) algorithm.
16 {
17 	this()
18 	{
19 		super(new NormalPDF, [-3, -1, 0, 1, 3]);
20 	}
21 }
22 
23 class NormalQuantile : NumericQuantile!real ///$(RED Unstable) algorithm.
24 {
25 	this()
26 	{
27 		super(new NormalCDF);
28 	}
29 }
30 
31 auto qf = new NormalQuantile;
32 
33 assert(approxEqual(qf(0.3), normalDistributionInverse(0.3)));

Numeric quantile function of Generalized Hyperbolic distribution

1 import atmosphere.pdf;
2 import atmosphere.cdf;
3 import atmosphere.params;
4 import atmosphere.moment;
5 
6 class GHypCDF: NumericCDF!real ///$(RED Unstable) algorithm.
7 {
8 	this(real lambda, GHypChiPsi!real params)
9 	{
10 		immutable mu = 0;
11 		auto pdf = new GeneralizedHyperbolicPDF!real(lambda, params.alpha, params.beta, params.delta, mu);
12 		immutable mean = generalizedHyperbolicMean!real(lambda, params.beta, params.chi, params.psi);
13 		super(pdf, [mean]);	
14 	}
15 }
16 
17 class GHypQuantile : NumericQuantile!real ///$(RED Unstable) algorithm.
18 {
19 	this(real lambda, GHypChiPsi!real params)
20 	{
21 		super(new GHypCDF(lambda, params), -1000, 1000);	
22 	}
23 }
24 
25 auto qf = new GHypQuantile(0.5, GHypChiPsi!real(5, 0.7, 0.6));
26 assert(approxEqual(qf(0.95), 40.9263));
27 assert(approxEqual(qf(0.99), 64.977));

Meta