This project has moved. For the latest updates, please go here.
A probability distribution describes the relative likelihood of obtaining each possible outcome from a random process. For example, the distribution of heights in a group of people (measured as deviations from the mean), might be described by the distribution pictured below.


Meta.Numerics provides you with a large number of commonly used probability distributions. Each probability distribution is represented by a class in the Meta.Numerics.Statistics.Distributions namespace. Continuous distributions, such as NormalDistribution, inherit from
the Distribution class. Discrete distributions, such as BinomialDistribution, inherit from the DiscreteDistribution class.

Summary Data

For any distribution, you can obtain many useful summary statistics.

Member Description
Mean The mean of the distribution.
Median The median of the distribution.
StandardDeviation The standard deviation of the distribution.
Variance The variance of the distribution. This is the square of the standard deviation.
Skewness The skewness of the distribution. Symmetric distributions have zero skew.
Moment(n) The nth raw moment of the distribution.
MomentAboutMean(n) The nth central moment of the distribution.
Support The interval over which the distribution is non-vanishing.
ProbabilityDensity(x) The PDF of the distribution at the given point.
LeftProbability(x) The CDF of the distribution at the given point, i.e. the probability that a value is less than x. This is the area under the PDF to the left of x.
RightProbability(x) The complementary CDF of the distribution at the given point, i.e. the probability that a value is greater than x. This is the area under the PDF to the right of x.
InverseLeftProbability(P) The inverse of the CDF. Given a percentile rank P, this function returns the score x for which a fraction P of values are lower.

Random Deviates

Given any distribution, you can use the .NET Framework's Random class to obtain random number drawn from that distribution.

            // Write out 20 exponentially distributed values
            Random rng = new Random();
            Distribution d = new ExponentialDistribution();
            for (int i = 0; i < 20; i++) {

Provided Distributions

The following continuous probability distributions are provided by the Meta.Numerics library:

Distribution Class Description
NormalDistribution The normal, or Gaussian distribution, appears in the law-of-large-numbers as an approximation to many probabilistic properties. It is commonly used as an approximate model for any symmetric, unimodular distribution.
LognormalDistribution The distribution of values whose logrithms are normally distributed. It is commonly used in financial mathematics to represent the distribution of values of a security whose percent change is subject to Gaussian fluctuations.
ExponentialDistribution The exponential distribution is the result of any constant-hazard process, such as particle decay.
WeibullDistribution The Weibull distribution is a generalization of the exponenial distribution, which allows for a hazard that increases or decreases over time. It is often used as a model for time-to-failure data.
UniformDistribution The uniform distribution represents a process that is equally likely to produce a value anywhere in a given interval.
TriangularDistribution A distribution on an arbitrary interval with a triangular PDF.
BetaDistribution A distribution on the unit interval with a flexible shape.
ChiSquaredDistribution The distribution of a sum of squares of n normal deviates. This is the distribution of the chi squared goodness-of-fit statistic.
FisherDistribution The distribution of a ratio of two chi-squared deviates. This is the distribution of the Fisher F statistic.
StudentDistribution The distribution of the Student t statistic.
KolmogorovDistribution The distribution of the Kolmogorov-Smirnov D statistic.

All the continuous distribution classes inherit from the abstract Distribution class.


Given a distribution, the following code computes many of its properties by numerical integration and compares them with the values returned by the member functions.

        public void TestMoments (Distribution d) {

            // the support gives the limits of integration
            Interval support = d.Support;

            // raw moments
            double[] M = new double[6];
            for (int n = 0; n < 6; n++) {
                // define x^n p(x)
                Function<double, double> raw = delegate(double x) {
                    return (Math.Pow(x, n) * d.ProbabilityDensity(x));
                // integrate it
                M[n] = FunctionMath.Integrate(raw, support);
                // compare with the claimed result
                Console.WriteLine("M{0} {1} v. {2}", n, M[n], d.Moment(n));

            // central moments
            double[] C = new double[6];
            for (int n = 0; n < 6; n++) {
                // define (x-m)^n p(x)
                Function<double, double> central = delegate(double x) {
                    return (Math.Pow(x - M[1], n) * d.ProbabilityDensity(x));
                // integrate it
                C[n] = FunctionMath.Integrate(central, support);
                // compare with the claimed result
                Console.WriteLine("C{0} {1} v. {2}", n, C[n], d.MomentAboutMean(n));

            Console.WriteLine("Mean {0} v. {1}", M[1], d.Mean);
            Console.WriteLine("Standard Deviation {0} v. {1}", Math.Sqrt(C[2]), d.StandardDeviation);


Last edited Apr 1, 2011 at 11:52 PM by ichbin, version 6


No comments yet.