PDF

Probability density function interface

interface PDF (
T
) {}

Members

Functions

opCall
T opCall(T x)

Call operator

Examples

1 import std.traits, std.mathspecial;
2 
3 class NormalPDF : PDF!real
4 {
5 	real opCall(real x)
6 	{
7 		// 1/sqrt(2 PI)
8 		enum c = 0.398942280401432677939946L;
9 		return c * exp(-0.5f * x * x);
10 	}
11 }
12 
13 auto pdf = new NormalPDF;
14 auto x = pdf(0.1);
15 assert(x.isNormal);
16 
17 import scid.calculus : integrate;
18 auto result = pdf.integrate(-double.infinity, double.infinity);
19 assert(fabs(result.value - 1) < result.error);

Meta