FiniteDiscreteDistribution Class |
Namespace: Novacta.Analytics
The FiniteDiscreteDistribution type exposes the following members.
Name | Description | |
---|---|---|
FiniteDiscreteDistribution |
Initializes a new instance of
the FiniteDiscreteDistribution class
having the specified values and masses.
|
Name | Description | |
---|---|---|
CanInvertCdf |
Gets a value indicating whether this instance can invert its
cumulative distribution function.
(Overrides ProbabilityDistributionCanInvertCdf.) | |
Masses |
Gets the probabilities of the Values of
this instance.
| |
RandomNumberGenerator |
Gets or sets the basic random generator for this instance.
(Inherited from RandomDevice.) | |
Values |
Gets the distinct values whose probabilities are explicitly
assigned by this instance.
|
Name | Description | |
---|---|---|
Cdf(Double) |
Computes the cumulative distribution function
of this instance at the specified argument.
(Overrides ProbabilityDistributionCdf(Double).) | |
Cdf(DoubleMatrix) |
Computes the cumulative distribution function
of this instance at the specified arguments.
(Inherited from ProbabilityDistribution.) | |
Cdf(ReadOnlyDoubleMatrix) |
Computes the cumulative distribution function
of this instance at the specified arguments.
(Inherited from ProbabilityDistribution.) | |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
InverseCdf(Double) |
Throws a NotSupportedException.
(Overrides ProbabilityDistributionInverseCdf(Double).) | |
InverseCdf(DoubleMatrix) |
Throws a NotSupportedException.
(Overrides ProbabilityDistributionInverseCdf(DoubleMatrix).) | |
InverseCdf(ReadOnlyDoubleMatrix) |
Computes the inverse of the cumulative distribution function
of this instance at the specified arguments.
(Inherited from ProbabilityDistribution.) | |
Mean |
Computes the mean of this instance.
(Overrides ProbabilityDistributionMean.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
OnSample |
Called when drawing a sample from this instance having the given size
and returns it
in a given destination array.
(Overrides ProbabilityDistributionOnSample(Int32, Double, Int32).) | |
Pdf(Double) |
Computes the probability density function
of this instance at the specified argument.
(Overrides ProbabilityDistributionPdf(Double).) | |
Pdf(DoubleMatrix) |
Computes the probability density function
of this instance at the specified arguments.
(Inherited from ProbabilityDistribution.) | |
Pdf(ReadOnlyDoubleMatrix) |
Computes the probability density function
of this instance at the specified arguments.
(Inherited from ProbabilityDistribution.) | |
Sample |
Draws a sample point from this instance.
(Overrides ProbabilityDistributionSample.) | |
Sample(Int32) |
Draws a sample from this instance having the specified size
and returns it as a matrix.
(Inherited from ProbabilityDistribution.) | |
Sample(Int32, Double, Int32) |
Draws a sample from this instance having the specified size
and returns it
in a destination array.
(Inherited from ProbabilityDistribution.) | |
SetMasses |
Sets the probabilities of the Values of
this instance.
| |
StandardDeviation |
Computes the standard deviation of this instance.
(Inherited from ProbabilityDistribution.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
Uniform |
Creates a finite discrete distribution having the
specified values and assigns to them equal masses.
| |
Variance |
Computes the variance of this instance.
(Overrides ProbabilityDistributionVariance.) |
A FiniteDiscreteDistribution instance represents the probability distribution of a random variable which can take only a finite number of values. Property Values returns the matrix of such distinct values, say , whose probabilities are explicitly assigned by a FiniteDiscreteDistribution instance.
Property Masses returns a matrix,
say , having the same dimensions
Values, whose nonnegative entries sum up to 1
and represent the probabilities of the
corresponding entries in Values.
More thoroughly, method Pdf(Double) represents a
probability mass function satisfying:
The Values of a FiniteDiscreteDistribution instance are immutable. Their Masses can be updated via method SetMasses(DoubleMatrix).
In the following example, a FiniteDiscreteDistribution instance is exploited to execute some statistical tasks.
using System; namespace Novacta.Analytics.CodeExamples { public class FiniteDiscreteDistributionExample0 { public void Main() { // Create the values. var values = DoubleMatrix.Dense( 3, 2, new double[6] { 2, -1, 0, 1, 3, -4 }); // Create the corresponding probabilities. var probabilities = DoubleMatrix.Dense( 3, 2, new double[6] { 1.0 / 8, 0.0, 2.0 / 8, 1.0 / 8, 3.0 / 8, 1.0 / 8 }); // Create the finite discrete distribution. var distribution = new FiniteDiscreteDistribution(values, probabilities); Console.WriteLine("Values:"); Console.WriteLine(distribution.Values); Console.WriteLine(); Console.WriteLine("Probabilities:"); Console.WriteLine(distribution.Masses); Console.WriteLine(); // Compute the mean value. double mean = distribution.Mean(); Console.WriteLine("Expected value: {0}", mean); Console.WriteLine(); // Draw a sample from the distribution. int sampleSize = 100000; var sample = distribution.Sample(sampleSize); // Compute the sample mean. double sampleMean = Stat.Mean(sample); Console.WriteLine("Sample mean: {0}", sampleMean); Console.WriteLine(); // Get a specific value. int valueIndex = 3; double value = distribution.Values[valueIndex]; // Get its mass. double mass = distribution.Masses[valueIndex]; Console.WriteLine("Mass of value {0}: {1}", value, mass); Console.WriteLine(); // Compute its sample frequency. IndexCollection valuePositions = sample.Find(value); double frequency = (valuePositions == null) ? 0.0 : (double)valuePositions.Count / sampleSize; Console.WriteLine("Sample frequency of value {0}: {1}", value, frequency); } } } // Executing method Main() produces the following output: // // Values: // 2 1 // -1 3 // 0 -4 // // // // Probabilities: // 0.125 0.125 // 0 0.375 // 0.25 0.125 // // // // Expected value: 1 // // Sample mean: 0.99149 // // Mass of value 1: 0.125 // // Sample frequency of value 1: 0.1244