Click or drag to resize

FiniteDiscreteDistribution Class

Represents a finite discrete distribution.
Inheritance Hierarchy

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public sealed class FiniteDiscreteDistribution : ProbabilityDistribution

The FiniteDiscreteDistribution type exposes the following members.

Constructors
  NameDescription
Public methodFiniteDiscreteDistribution
Initializes a new instance of the FiniteDiscreteDistribution class having the specified values and masses.
Top
Properties
  NameDescription
Public propertyCanInvertCdf
Gets a value indicating whether this instance can invert its cumulative distribution function.
(Overrides ProbabilityDistributionCanInvertCdf.)
Public propertyMasses
Gets the probabilities of the Values of this instance.
Public propertyRandomNumberGenerator
Gets or sets the basic random generator for this instance.
(Inherited from RandomDevice.)
Public propertyValues
Gets the distinct values whose probabilities are explicitly assigned by this instance.
Top
Methods
  NameDescription
Public methodCdf(Double)
Computes the cumulative distribution function of this instance at the specified argument.
(Overrides ProbabilityDistributionCdf(Double).)
Public methodCdf(DoubleMatrix)
Computes the cumulative distribution function of this instance at the specified arguments.
(Inherited from ProbabilityDistribution.)
Public methodCdf(ReadOnlyDoubleMatrix)
Computes the cumulative distribution function of this instance at the specified arguments.
(Inherited from ProbabilityDistribution.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodInverseCdf(Double) (Overrides ProbabilityDistributionInverseCdf(Double).)
Public methodInverseCdf(DoubleMatrix) (Overrides ProbabilityDistributionInverseCdf(DoubleMatrix).)
Public methodInverseCdf(ReadOnlyDoubleMatrix)
Computes the inverse of the cumulative distribution function of this instance at the specified arguments.
(Inherited from ProbabilityDistribution.)
Public methodMean
Computes the mean of this instance.
(Overrides ProbabilityDistributionMean.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnSample
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).)
Public methodPdf(Double)
Computes the probability density function of this instance at the specified argument.
(Overrides ProbabilityDistributionPdf(Double).)
Public methodPdf(DoubleMatrix)
Computes the probability density function of this instance at the specified arguments.
(Inherited from ProbabilityDistribution.)
Public methodPdf(ReadOnlyDoubleMatrix)
Computes the probability density function of this instance at the specified arguments.
(Inherited from ProbabilityDistribution.)
Public methodSample
Draws a sample point from this instance.
(Overrides ProbabilityDistributionSample.)
Public methodSample(Int32)
Draws a sample from this instance having the specified size and returns it as a matrix.
(Inherited from ProbabilityDistribution.)
Public methodSample(Int32, Double, Int32)
Draws a sample from this instance having the specified size and returns it in a destination array.
(Inherited from ProbabilityDistribution.)
Public methodSetMasses
Sets the probabilities of the Values of this instance.
Public methodStandardDeviation
Computes the standard deviation of this instance.
(Inherited from ProbabilityDistribution.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodStatic memberUniform
Creates a finite discrete distribution having the specified values and assigns to them equal masses.
Public methodVariance
Computes the variance of this instance.
(Overrides ProbabilityDistributionVariance.)
Top
Remarks

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 LaTeX equation, whose probabilities are explicitly assigned by a FiniteDiscreteDistribution instance.

Property Masses returns a matrix, say LaTeX equation, 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:

LaTeX equation

The Values of a FiniteDiscreteDistribution instance are immutable. Their Masses can be updated via method SetMasses(DoubleMatrix).

Examples

In the following example, a FiniteDiscreteDistribution instance is exploited to execute some statistical tasks.

C#
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

See Also