Namespaces

Types in MathNet.Numerics.Distributions

Type Categorical

Namespace MathNet.Numerics.Distributions

Interfaces IDiscreteDistribution

Discrete Univariate Categorical distribution. For details about this distribution, see. This distribution is sometimes called the Discrete distribution.
The distribution is parameterized by a vector of ratios: in other words, the parameter does not have to be normalized and sum to 1. The reason is that some vectors can't be exactly normalized to sum to 1 in floating point representation.

Constructors

Static Functions

Methods

Properties

Public Constructors

Categorical(Histogram histogram)

Initializes a new instance of the Categorical class from a histogram. The distribution will not be automatically updated when the histogram changes. The categorical distribution will have one value for each bucket and a probability for that value proportional to the bucket count.
Parameters
Histogram histogram

The histogram from which to create the categorical variable.

Categorical(Double[] probabilityMass, Random randomSource)

Initializes a new instance of the Categorical class.
Parameters
Double[] probabilityMass

An array of nonnegative ratios: this array does not need to be normalized as this is often impossible using floating point arithmetic.

Random randomSource

The random number generator which is used to draw random samples.

Categorical(Double[] probabilityMass)

Initializes a new instance of the Categorical class.
Parameters
Double[] probabilityMass

An array of nonnegative ratios: this array does not need to be normalized as this is often impossible using floating point arithmetic.

Public Static Functions

double CDF(Double[] probabilityMass, double x)

Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X ≤ x).
Parameters
Double[] probabilityMass

An array of nonnegative ratios: this array does not need to be normalized as this is often impossible using floating point arithmetic.

double x

The location at which to compute the cumulative distribution function.

Return
double

the cumulative distribution at location x.

int InvCDF(Double[] probabilityMass, double probability)

Computes the inverse of the cumulative distribution function (InvCDF) for the distribution at the given probability.
Parameters
Double[] probabilityMass

An array of nonnegative ratios: this array does not need to be normalized as this is often impossible using floating point arithmetic.

double probability

A real number between 0 and 1.

Return
int

An integer between 0 and the size of the categorical (exclusive), that corresponds to the inverse CDF for the given probability.

int InvCDFWithCumulativeDistribution(Double[] cdfUnnormalized, double probability)

Computes the inverse of the cumulative distribution function (InvCDF) for the distribution at the given probability.
Parameters
Double[] cdfUnnormalized

An array corresponding to a CDF for a categorical distribution. Not assumed to be normalized.

double probability

A real number between 0 and 1.

Return
int

An integer between 0 and the size of the categorical (exclusive), that corresponds to the inverse CDF for the given probability.

bool IsValidCumulativeDistribution(Double[] cdf)

Checks whether the parameters of the distribution are valid.
Parameters
Double[] cdf

An array of nonnegative ratios: this array does not need to be normalized as this is often impossible using floating point arithmetic.

Return
bool

If any of the probabilities are negative returns false , or if the sum of parameters is 0.0; otherwise true

bool IsValidProbabilityMass(Double[] p)

Checks whether the parameters of the distribution are valid.
Parameters
Double[] p

An array of nonnegative ratios: this array does not need to be normalized as this is often impossible using floating point arithmetic.

Return
bool

If any of the probabilities are negative returns false , or if the sum of parameters is 0.0; otherwise true

double PMF(Double[] probabilityMass, int k)

Computes the probability mass (PMF) at k, i.e. P(X = k).
Parameters
Double[] probabilityMass

An array of nonnegative ratios: this array does not need to be normalized as this is often impossible using floating point arithmetic.

int k

The location in the domain where we want to evaluate the probability mass function.

Return
double

the probability mass at location k.

double PMFLn(Double[] probabilityMass, int k)

Computes the log probability mass (lnPMF) at k, i.e. ln(P(X = k)).
Parameters
Double[] probabilityMass

An array of nonnegative ratios: this array does not need to be normalized as this is often impossible using floating point arithmetic.

int k

The location in the domain where we want to evaluate the log probability mass function.

Return
double

the log probability mass at location k.

int Sample(Double[] probabilityMass)

Samples one categorical distributed random variable; also known as the Discrete distribution.
Parameters
Double[] probabilityMass

An array of nonnegative ratios. Not assumed to be normalized.

Return
int

One random integer between 0 and the size of the categorical (exclusive).

int Sample(Random rnd, Double[] probabilityMass)

Samples one categorical distributed random variable; also known as the Discrete distribution.
Parameters
Random rnd

The random number generator to use.

Double[] probabilityMass

An array of nonnegative ratios. Not assumed to be normalized.

Return
int

One random integer between 0 and the size of the categorical (exclusive).

IEnumerable<int> Samples(Random rnd, Double[] probabilityMass)

Samples a categorically distributed random variable.
Parameters
Random rnd

The random number generator to use.

Double[] probabilityMass

An array of nonnegative ratios. Not assumed to be normalized.

Return
IEnumerable<int>

random integers between 0 and the size of the categorical (exclusive).

IEnumerable<int> Samples(Double[] probabilityMass)

Samples a categorically distributed random variable.
Parameters
Double[] probabilityMass

An array of nonnegative ratios. Not assumed to be normalized.

Return
IEnumerable<int>

random integers between 0 and the size of the categorical (exclusive).

void Samples(Random rnd, Int32[] values, Double[] probabilityMass)

Fills an array with samples generated from the distribution.
Parameters
Random rnd

The random number generator to use.

Int32[] values

The array to fill with the samples.

Double[] probabilityMass

An array of nonnegative ratios. Not assumed to be normalized.

Return
void

random integers between 0 and the size of the categorical (exclusive).

void Samples(Int32[] values, Double[] probabilityMass)

Fills an array with samples generated from the distribution.
Parameters
Int32[] values

The array to fill with the samples.

Double[] probabilityMass

An array of nonnegative ratios. Not assumed to be normalized.

Return
void

random integers between 0 and the size of the categorical (exclusive).

IEnumerable<int> SamplesWithCumulativeDistribution(Random rnd, Double[] cdfUnnormalized)

Samples a categorically distributed random variable.
Parameters
Random rnd

The random number generator to use.

Double[] cdfUnnormalized

An array of the cumulative distribution. Not assumed to be normalized.

Return
IEnumerable<int>

random integers between 0 and the size of the categorical (exclusive).

void SamplesWithCumulativeDistribution(Random rnd, Int32[] values, Double[] cdfUnnormalized)

Fills an array with samples generated from the distribution.
Parameters
Random rnd

The random number generator to use.

Int32[] values

The array to fill with the samples.

Double[] cdfUnnormalized

An array of the cumulative distribution. Not assumed to be normalized.

Return
void

random integers between 0 and the size of the categorical (exclusive).

IEnumerable<int> SamplesWithCumulativeDistribution(Double[] cdfUnnormalized)

Samples a categorically distributed random variable.
Parameters
Double[] cdfUnnormalized

An array of the cumulative distribution. Not assumed to be normalized.

Return
IEnumerable<int>

random integers between 0 and the size of the categorical (exclusive).

void SamplesWithCumulativeDistribution(Int32[] values, Double[] cdfUnnormalized)

Fills an array with samples generated from the distribution.
Parameters
Int32[] values

The array to fill with the samples.

Double[] cdfUnnormalized

An array of the cumulative distribution. Not assumed to be normalized.

Return
void

random integers between 0 and the size of the categorical (exclusive).

int SampleWithCumulativeDistribution(Random rnd, Double[] cdfUnnormalized)

Samples one categorical distributed random variable; also known as the Discrete distribution.
Parameters
Random rnd

The random number generator to use.

Double[] cdfUnnormalized

An array of the cumulative distribution. Not assumed to be normalized.

Return
int

One random integer between 0 and the size of the categorical (exclusive).

int SampleWithCumulativeDistribution(Double[] cdfUnnormalized)

Samples one categorical distributed random variable; also known as the Discrete distribution.
Parameters
Double[] cdfUnnormalized

An array of the cumulative distribution. Not assumed to be normalized.

Return
int

One random integer between 0 and the size of the categorical (exclusive).

Public Methods

double CumulativeDistribution(double x)

Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X ≤ x).
Parameters
double x

The location at which to compute the cumulative distribution function.

Return
double

the cumulative distribution at location x.

bool Equals(object obj)

int GetHashCode()

Type GetType()

int InverseCumulativeDistribution(double probability)

Computes the inverse of the cumulative distribution function (InvCDF) for the distribution at the given probability.
Parameters
double probability

A real number between 0 and 1.

Return
int

An integer between 0 and the size of the categorical (exclusive), that corresponds to the inverse CDF for the given probability.

double Probability(int k)

Computes the probability mass (PMF) at k, i.e. P(X = k).
Parameters
int k

The location in the domain where we want to evaluate the probability mass function.

Return
double

the probability mass at location k.

double ProbabilityLn(int k)

Computes the log probability mass (lnPMF) at k, i.e. ln(P(X = k)).
Parameters
int k

The location in the domain where we want to evaluate the log probability mass function.

Return
double

the log probability mass at location k.

int Sample()

Samples a Binomially distributed random variable.
Return
int

The number of successful trials.

IEnumerable<int> Samples()

Samples an array of Bernoulli distributed random variables.
Return
IEnumerable<int>

a sequence of successful trial counts.

void Samples(Int32[] values)

Fills an array with samples generated from the distribution.

string ToString()

A string representation of the distribution.
Return
string

a string representation of the distribution.

Public Properties

double Entropy get;

Gets the entropy of the distribution.

int Maximum get;

Gets the largest element in the domain of the distributions which can be represented by an integer.

double Mean get;

Gets the mean of the distribution.

double Median get;

Gets the median of the distribution.

int Minimum get;

Gets the smallest element in the domain of the distributions which can be represented by an integer.

int Mode get;

Gets he mode of the distribution.
Throws a NotSupportedException.

Double[] P get;

Gets the probability mass vector (non-negative ratios) of the multinomial.
Sometimes the normalized probability vector cannot be represented exactly in a floating point representation.

Random RandomSource get; set;

Gets or sets the random number generator which is used to draw random samples.

double Skewness get;

Gets the skewness of the distribution.
Throws a NotSupportedException.

double StdDev get;

Gets the standard deviation of the distribution.

double Variance get;

Gets the variance of the distribution.