Probability Distributions
Math.NET Numerics provides a wide range of probability distributions. Given the distribution parameters they can be used to investigate their statistical properties or to sample nonuniform random numbers.
All the distributions implement a common set of operations such as evaluating the density (PDF) and the cumulative distribution (CDF) at a given point, or to compute the mean, standard deviation and other properties. Because it is often numerically more stable and faster to compute such statistical quantities in the logarithmic domain, we also provide a selection of them in the log domain with the "Ln" suffix, e.g. DensityLn for the logarithmic density.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 

Both probability functions and sampling are also available as static functions for simpler usage scenarios:
1: 2: 3: 

Continuous Distributions
 Continuous Uniform
 Normal
 Log Normal
 Beta
 Cauchy (CauchyLorentz)
 Chi
 Chi Squared
 Erlang
 Exponential
 FisherSnedecor (FDistribution)
 Gamma
 Inverse Gamma
 Laplace
 Pareto
 Rayleigh
 Stable
 StundentT
 Weibull
 Triangular
Distribution Parameters
There are many ways to parametrize a distribution in the literature. When using the default constructor, read carefully which parameters it requires. For distributions where multiple ways are common there are also static methods, so you can use the one that fits best. For example, a normal distribution is usually parametrized with mean and standard deviation, but if you'd rather use mean and precision:
1:


Since probability distributions can also be sampled to generate random numbers with the configured distribution, all constructors optionally accept a random generator as last argument.
1: 2: 3: 4: 

A few more examples, this time in F#:
1: 2: 3: 4: 5: 6: 7: 

Some of the distributions also have routines for maximumlikelihood parameter estimation from a set of samples:
1: 2: 3: 

or in C#:
1: 2: 3: 

Sampling a Probability Distribution
Each distribution provides methods to generate random numbers from that distribution.
These random variate generators work by accessing the distribution's member RandomSource
to provide uniform random numbers. By default, this member is an instance of System.Random
but one can easily replace this with more sophisticated random number generators from
MathNet.Numerics.Random
(see Random Numbers for details).
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 

Instead of creating a distribution object we can also sample directly with static functions. Note that no intermediate value caching is possible this way and parameters must be validated on each call.
1: 2: 3: 4: 5: 6: 7: 

If you need to sample not just one or two values but a large number of them,
there are routines that either fill an existing array or return an enumerable.
The variant that fills an array is generally the fastest. Routines to sample
more than one value use the plural form Samples
instead of Sample
.
Let's sample 100'000 values from a laplace distribution with mean 1.0 and scale 2.0 in C#:
1: 2: 

Let's do some random walks in F# (TODO: Graph):
1: 2: 

Distribution Functions and Properties
Distributions can not just be used to generate nonuniform random samples.
Once parametrized they can compute a variety of distribution properties
or evaluate distribution functions. Because it is often numerically more stable
and faster to compute and work with such quantities in the logarithmic domain,
some of them are also available with the Ln
suffix.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 

Composing Distributions
Specifically for F# there is also a Sample
module that allows a somewhat more functional
view on distribution sampling functions by having the random source passed in as last argument.
This way they can be composed and transformed arbitrarily if curried:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 
