Click or drag to resize
Accord.NET (logo)

GeneralDiscreteDistribution Class

Univariate general discrete distribution, also referred as the Categorical distribution.
Inheritance Hierarchy
SystemObject
  Accord.Statistics.DistributionsDistributionBase
    Accord.Statistics.Distributions.UnivariateUnivariateDiscreteDistribution
      Accord.Statistics.Distributions.UnivariateGeneralDiscreteDistribution

Namespace:  Accord.Statistics.Distributions.Univariate
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.8.0
Syntax
[SerializableAttribute]
public sealed class GeneralDiscreteDistribution : UnivariateDiscreteDistribution, 
	IUnivariateFittableDistribution, IFittableDistribution<double>, IFittable<double>, 
	IDistribution<double>, IDistribution, ICloneable, IUnivariateDistribution<double>, 
	IUnivariateDistribution, IFittableDistribution<double, GeneralDiscreteOptions>, IFittable<double, GeneralDiscreteOptions>, 
	IFittableDistribution<double[], GeneralDiscreteOptions>, IFittable<double[], GeneralDiscreteOptions>, 
	IFittable<double[]>, IFittableDistribution<double[]>, IDistribution<double[]>, 
	IFittableDistribution<int, GeneralDiscreteOptions>, IFittable<int, GeneralDiscreteOptions>, 
	IFittable<int>, IFittableDistribution<int>, IDistribution<int>, 
	ISampleableDistribution<int>, IRandomNumberGenerator<int>, ISampleableDistribution<double>, 
	IRandomNumberGenerator<double>
Request Example View Source

The GeneralDiscreteDistribution type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyEntropy
Gets the entropy for this distribution.
(Overrides UnivariateDiscreteDistributionEntropy.)
Public propertyFrequencies
Gets the probabilities associated with each discrete variable value. Note: if the frequencies in this property are manually changed, the rest of the class properties (Mode, Mean, ...) will not be automatically updated to reflect the actual inserted values.
Public propertyItem
Gets the probability value associated with the symbol i.
Public propertyLength
Gets the number of symbols in the distribution.
Public propertyMaximum
Gets the integer value where the discrete distribution ends.
Public propertyMean
Gets the mean for this distribution.
(Overrides UnivariateDiscreteDistributionMean.)
Public propertyMedian
Gets the median for this distribution.
(Inherited from UnivariateDiscreteDistribution.)
Public propertyMinimum
Gets the integer value where the discrete distribution starts.
Public propertyMode
Gets the mode for this distribution.
(Overrides UnivariateDiscreteDistributionMode.)
Public propertyQuartiles
Gets the Quartiles for this distribution.
(Inherited from UnivariateDiscreteDistribution.)
Public propertyStandardDeviation
Gets the Standard Deviation (the square root of the variance) for the current distribution.
(Inherited from UnivariateDiscreteDistribution.)
Public propertySupport
Gets the support interval for this distribution.
(Overrides UnivariateDiscreteDistributionSupport.)
Public propertyVariance
Gets the variance for this distribution.
(Overrides UnivariateDiscreteDistributionVariance.)
Top
Methods
  NameDescription
Public methodClone
Creates a new object that is a copy of the current instance.
(Overrides DistributionBaseClone.)
Public methodComplementaryDistributionFunction(Int32)
Gets P(X > k) the complementary cumulative distribution function (ccdf) for this distribution evaluated at point k. This function is also known as the Survival function.
(Inherited from UnivariateDiscreteDistribution.)
Public methodCode exampleComplementaryDistributionFunction(Int32, Boolean)
Gets the complementary cumulative distribution function (ccdf) for this distribution evaluated at point k. This function is also known as the Survival function.
(Inherited from UnivariateDiscreteDistribution.)
Public methodCumulativeHazardFunction
Gets the cumulative hazard function for this distribution evaluated at point x.
(Inherited from UnivariateDiscreteDistribution.)
Public methodDistributionFunction(Int32)
Gets P(X ≤ k), the cumulative distribution function (cdf) for this distribution evaluated at point k.
(Inherited from UnivariateDiscreteDistribution.)
Public methodCode exampleDistributionFunction(Int32, Boolean)
Gets P(X ≤ k) or P(X < k), the cumulative distribution function (cdf) for this distribution evaluated at point k, depending on the value of the inclusive parameter.
(Inherited from UnivariateDiscreteDistribution.)
Public methodDistributionFunction(Int32, Int32)
Gets the cumulative distribution function (cdf) for this distribution in the semi-closed interval (a; b] given as P(a < X ≤ b).
(Inherited from UnivariateDiscreteDistribution.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodFit(Double)
Fits the underlying distribution to a given set of observations.
Public methodFit(Double)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateDiscreteDistribution.)
Public methodFit(Int32)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateDiscreteDistribution.)
Public methodFit(Double, Double)
Fits the underlying distribution to a given set of observations.
Public methodFit(Int32, Double)
Fits the underlying distribution to a given set of observations.
Public methodFit(Double, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateDiscreteDistribution.)
Public methodFit(Double, Double)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateDiscreteDistribution.)
Public methodFit(Double, Int32)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateDiscreteDistribution.)
Public methodFit(Int32, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateDiscreteDistribution.)
Public methodFit(Double, Double, GeneralDiscreteOptions)
Fits the underlying distribution to a given set of observations.
Public methodFit(Double, Double, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Overrides UnivariateDiscreteDistributionFit(Double, Double, IFittingOptions).)
Public methodFit(Double, Double, GeneralDiscreteOptions)
Fits the underlying distribution to a given set of observations.
Public methodFit(Int32, Double, GeneralDiscreteOptions)
Fits the underlying distribution to a given set of observations.
Public methodFit(Int32, Double, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Overrides UnivariateDiscreteDistributionFit(Int32, Double, IFittingOptions).)
Public methodFit(Double, Int32, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateDiscreteDistribution.)
Public methodFit(Int32, Int32, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateDiscreteDistribution.)
Public methodStatic memberFromMatrix(Double, Boolean)
Creates general discrete distributions given a matrix of symbol probabilities.
Public methodStatic memberFromMatrix(Double, Boolean)
Creates general discrete distributions given a matrix of symbol probabilities.
Public methodGenerate
Generates a random observation from the current distribution.
(Inherited from UnivariateDiscreteDistribution.)
Public methodGenerate(Random)
Generates a random observation from the current distribution.
(Overrides UnivariateDiscreteDistributionGenerate(Random).)
Public methodGenerate(Int32)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateDiscreteDistribution.)
Public methodGenerate(Int32, Double)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateDiscreteDistribution.)
Public methodGenerate(Int32, Int32)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateDiscreteDistribution.)
Public methodGenerate(Int32, Random)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateDiscreteDistribution.)
Public methodGenerate(Int32, Int32, Random)
Generates a random vector of observations from the current distribution.
(Overrides UnivariateDiscreteDistributionGenerate(Int32, Int32, Random).)
Public methodGenerate(Int32, Double, Random)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateDiscreteDistribution.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetRange
Gets the distribution range within a given percentile.
(Inherited from UnivariateDiscreteDistribution.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodHazardFunction
Gets the hazard function, also known as the failure rate or the conditional failure density function for this distribution evaluated at point x.
(Inherited from UnivariateDiscreteDistribution.)
Public methodInverseDistributionFunction
Gets the inverse of the cumulative distribution function (icdf) for this distribution evaluated at probability p. This function is also known as the Quantile function.
(Inherited from UnivariateDiscreteDistribution.)
Public methodLogCumulativeHazardFunction
Gets the log-cumulative hazard function for this distribution evaluated at point x.
(Inherited from UnivariateDiscreteDistribution.)
Public methodLogProbabilityMassFunction
Gets the log-probability mass function (pmf) for this distribution evaluated at point x.
(Inherited from UnivariateDiscreteDistribution.)
Public methodProbabilityMassFunction
Gets the probability mass function (pmf) for this distribution evaluated at point x.
(Inherited from UnivariateDiscreteDistribution.)
Public methodQuantileDensityFunction
Gets the first derivative of the inverse distribution function (icdf) for this distribution evaluated at probability p.
(Inherited from UnivariateDiscreteDistribution.)
Public methodStatic memberRandom(Double, Boolean)
Returns a random symbol within the given symbol probabilities.
Public methodStatic memberRandom(Double, Int32)
Returns a random sample within the given symbol probabilities.
Public methodStatic memberRandom(Double, Int32, Random)
Returns a random sample within the given symbol probabilities.
Public methodStatic memberRandom(Double, Random, Boolean)
Returns a random symbol within the given symbol probabilities.
Public methodStatic memberRandom(Double, Int32, Int32, Boolean)
Returns a random sample within the given symbol probabilities.
Public methodStatic memberRandom(Double, Int32, Int32, Random, Boolean)
Returns a random sample within the given symbol probabilities.
Public methodToString
Returns a String that represents this instance.
(Inherited from DistributionBase.)
Public methodToString(IFormatProvider)
Returns a String that represents this instance.
(Inherited from DistributionBase.)
Public methodToString(String)
Returns a String that represents this instance.
(Inherited from DistributionBase.)
Public methodToString(String, IFormatProvider)
Returns a String that represents this instance.
(Overrides DistributionBaseToString(String, IFormatProvider).)
Public methodStatic memberUniform
Constructs a new uniform discrete distribution.
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

An univariate categorical distribution is a statistical distribution whose variables can take on only discrete values. Each discrete value defined within the interval of the distribution has an associated probability value indicating its frequency of occurrence.

The discrete uniform distribution is a special case of a generic discrete distribution whose probability values are constant.

Examples
// Create a Categorical distribution for 3 symbols, in which
// the first and second symbol have 25% chance of appearing,
// and the third symbol has 50% chance of appearing.

//                         1st   2nd   3rd
double[] probabilities = { 0.25, 0.25, 0.50 };

// Create the categorical with the given probabilities
var dist = new GeneralDiscreteDistribution(probabilities);

// Common measures
double mean = dist.Mean;     // 1.25
double median = dist.Median; // 1.00
double var = dist.Variance;  // 0.6875

// Cumulative distribution functions
double cdf  = dist.DistributionFunction(k: 2);              // 1.0
double ccdf = dist.ComplementaryDistributionFunction(k: 2); // 0.0

// Probability mass functions
double pdf1 = dist.ProbabilityMassFunction(k: 0); // 0.25
double pdf2 = dist.ProbabilityMassFunction(k: 1); // 0.25
double pdf3 = dist.ProbabilityMassFunction(k: 2); // 0.50
double lpdf = dist.LogProbabilityMassFunction(k: 2); // -0.69314718055994529

// Quantile function
int icdf1 = dist.InverseDistributionFunction(p: 0.17); // 0
int icdf2 = dist.InverseDistributionFunction(p: 0.39); // 1
int icdf3 = dist.InverseDistributionFunction(p: 0.56); // 2

// Hazard (failure rate) functions
double hf = dist.HazardFunction(x: 0); // 0.33333333333333331
double chf = dist.CumulativeHazardFunction(x: 0); // 0.2876820724517809

// String representation
string str = dist.ToString(CultureInfo.InvariantCulture); // "Categorical(x; p = { 0.25, 0.25, 0.5 })"
See Also