Click or drag to resize
Accord.NET (logo)

NormalDistribution Class

Normal (Gaussian) distribution.
Inheritance Hierarchy
SystemObject
  Accord.Statistics.DistributionsDistributionBase
    Accord.Statistics.Distributions.UnivariateUnivariateContinuousDistribution
      Accord.Statistics.Distributions.UnivariateNormalDistribution

Namespace:  Accord.Statistics.Distributions.Univariate
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.5.0
Syntax
[SerializableAttribute]
public class NormalDistribution : UnivariateContinuousDistribution, 
	IFittableDistribution<double, NormalOptions>, IFittable<double, NormalOptions>, 
	IFittable<double>, IFittableDistribution<double>, IDistribution<double>, 
	IDistribution, ICloneable, ISampleableDistribution<double>, IRandomNumberGenerator<double>, 
	IFormattable, IUnivariateFittableDistribution, IUnivariateDistribution<double>, IUnivariateDistribution
Request Example View Source

The NormalDistribution type exposes the following members.

Constructors
  NameDescription
Public methodNormalDistribution
Constructs a Normal (Gaussian) distribution with zero mean and unit standard deviation.
Public methodNormalDistribution(Double)
Constructs a Normal (Gaussian) distribution with given mean and unit standard deviation.
Public methodNormalDistribution(Double, Double)
Constructs a Normal (Gaussian) distribution with given mean and standard deviation.
Top
Properties
  NameDescription
Public propertyEntropy
Gets the Entropy for this Normal distribution.
(Overrides UnivariateContinuousDistributionEntropy.)
Public propertyKurtosis
Gets the excess kurtosis for this distribution. In the Normal distribution, this is always 0.
Public propertyMean
Gets the Mean value μ (mu) for this Normal distribution.
(Overrides UnivariateContinuousDistributionMean.)
Public propertyMedian
Gets the median for this distribution.
(Overrides UnivariateContinuousDistributionMedian.)
Public propertyMode
Gets the mode for this distribution.
(Overrides UnivariateContinuousDistributionMode.)
Public propertyQuartiles
Gets the Quartiles for this distribution.
(Inherited from UnivariateContinuousDistribution.)
Public propertySkewness
Gets the skewness for this distribution. In the Normal distribution, this is always 0.
Public propertyStatic memberStandard
Gets the Standard Gaussian Distribution, with zero mean and unit variance.
Public propertyStandardDeviation
Gets the Standard Deviation σ (sigma), which is the square root of the variance for this Normal distribution.
(Overrides UnivariateContinuousDistributionStandardDeviation.)
Public propertySupport
Gets the support interval for this distribution.
(Overrides UnivariateContinuousDistributionSupport.)
Public propertyVariance
Gets the Variance σ² (sigma-squared), which is the square of the standard deviation σ for this Normal distribution.
(Overrides UnivariateContinuousDistributionVariance.)
Top
Methods
  NameDescription
Public methodClone
Creates a new object that is a copy of the current instance.
(Overrides DistributionBaseClone.)
Public methodComplementaryDistributionFunction
Gets the complementary cumulative distribution function (ccdf) for this distribution evaluated at point x. This function is also known as the Survival function.
(Overrides UnivariateContinuousDistributionComplementaryDistributionFunction(Double).)
Public methodCumulativeHazardFunction
Gets the cumulative hazard function for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodCode exampleDistributionFunction(Double)
Gets the cumulative distribution function (cdf) for the this Normal distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionDistributionFunction(Double).)
Public methodDistributionFunction(Double, Double)
Gets the cumulative distribution function (cdf) for this distribution in the semi-closed interval (a; b] given as P(a < X ≤ b).
(Inherited from UnivariateContinuousDistribution.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodStatic memberEstimate(Double)
Estimates a new Normal distribution from a given set of observations.
Public methodStatic memberEstimate(Double, NormalOptions)
Estimates a new Normal distribution from a given set of observations.
Public methodStatic memberEstimate(Double, Double, NormalOptions)
Estimates a new Normal distribution from a given set of observations.
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 methodFit(Double)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodFit(Double, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodFit(Double, Double)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodFit(Double, Int32)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodFit(Double, Double, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Overrides UnivariateContinuousDistributionFit(Double, Double, IFittingOptions).)
Public methodFit(Double, Double, NormalOptions)
Fits the underlying distribution to a given set of observations.
Public methodFit(Double, Int32, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate
Generates a random observation from the current distribution.
(Overrides UnivariateContinuousDistributionGenerate.)
Public methodGenerate(Int32)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Int32, Double)
Generates a random vector of observations from the current distribution.
(Overrides UnivariateContinuousDistributionGenerate(Int32, Double).)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetRange
Gets the distribution range within a given percentile.
(Inherited from UnivariateContinuousDistribution.)
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 UnivariateContinuousDistribution.)
Public methodCode exampleInverseDistributionFunction
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.
(Overrides UnivariateContinuousDistributionInverseDistributionFunction(Double).)
Public methodLogCumulativeHazardFunction
Gets the log of the cumulative hazard function for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodCode exampleLogProbabilityDensityFunction
Gets the probability density function (pdf) for the Normal distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionLogProbabilityDensityFunction(Double).)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodCode exampleProbabilityDensityFunction
Gets the probability density function (pdf) for the Normal distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionProbabilityDensityFunction(Double).)
Public methodQuantileDensityFunction
Gets the first derivative of the inverse distribution function (icdf) for this distribution evaluated at probability p.
(Inherited from UnivariateContinuousDistribution.)
Public methodStatic memberRandom
Generates a random value from a standard Normal distribution (zero mean and unit standard deviation).
Public methodStatic memberRandom(Double, Double)
Generates a single random observation from the Normal distribution with the given parameters.
Public methodStatic memberRandom(Int32, Double)
Generates a random vector of observations from the standard Normal distribution (zero mean and unit standard deviation).
Public methodStatic memberRandom(Double, Double, Int32)
Generates a random vector of observations from the Normal distribution with the given parameters.
Public methodStatic memberRandom(Double, Double, Int32, Double)
Generates a random vector of observations from the Normal distribution with the given parameters.
Public methodToMultivariateDistribution
Converts this univariate distribution into a 1-dimensional multivariate distribution.
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 methodZScore
Gets the Z-Score for a given value.
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 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.)
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 Matrix.)
Top
Remarks

In probability theory, the normal (or Gaussian) distribution is a very commonly occurring continuous probability distribution—a function that tells the probability that any real observation will fall between any two real limits or real numbers, as the curve approaches zero on either side. Normal distributions are extremely important in statistics and are often used in the natural and social sciences for real-valued random variables whose distributions are not known.

The normal distribution is immensely useful because of the central limit theorem, which states that, under mild conditions, the mean of many random variables independently drawn from the same distribution is distributed approximately normally, irrespective of the form of the original distribution: physical quantities that are expected to be the sum of many independent processes (such as measurement errors) often have a distribution very close to the normal. Moreover, many results and methods (such as propagation of uncertainty and least squares parameter fitting) can be derived analytically in explicit form when the relevant variables are normally distributed.

The Gaussian distribution is sometimes informally called the bell curve. However, many other distributions are bell-shaped (such as Cauchy's, Student's, and logistic). The terms Gaussian function and Gaussian bell curve are also ambiguous because they sometimes refer to multiples of the normal distribution that cannot be directly interpreted in terms of probabilities.

The Gaussian is the most widely used distribution for continuous variables. In the case of a single variable, it is governed by two parameters, the mean and the variance.

References:

Examples

This examples shows how to create a Normal distribution, compute some of its properties and generate a number of random samples from it.

// Create a normal distribution with mean 2 and sigma 3
var normal = new NormalDistribution(mean: 2, stdDev: 3);

// In a normal distribution, the median and
// the mode coincide with the mean, so

double mean = normal.Mean;     // 2
double mode = normal.Mode;     // 2
double median = normal.Median; // 2

// The variance is the square of the standard deviation
double variance = normal.Variance; // 3² = 9

// Let's check what is the cumulative probability of
// a value less than 3 occurring in this distribution:
double cdf = normal.DistributionFunction(3); // 0.63055

// Finally, let's generate 1000 samples from this distribution
// and check if they have the specified mean and standard devs

double[] samples = normal.Generate(1000);

double sampleMean = samples.Mean();             // 1.92
double sampleDev = samples.StandardDeviation(); // 3.00

This example further demonstrates how to compute derived measures from a Normal distribution:

var normal = new NormalDistribution(mean: 4, stdDev: 4.2);

double mean = normal.Mean;     // 4.0
double median = normal.Median; // 4.0
double mode = normal.Mode;     // 4.0
double var = normal.Variance;  // 17.64

double cdf = normal.DistributionFunction(x: 1.4);           // 0.26794249453351904
double pdf = normal.ProbabilityDensityFunction(x: 1.4);     // 0.078423391448155175
double lpdf = normal.LogProbabilityDensityFunction(x: 1.4); // -2.5456330358182586

double ccdf = normal.ComplementaryDistributionFunction(x: 1.4); // 0.732057505466481
double icdf = normal.InverseDistributionFunction(p: cdf);       // 1.4

double hf = normal.HazardFunction(x: 1.4);            // 0.10712736480747137
double chf = normal.CumulativeHazardFunction(x: 1.4); // 0.31189620872601354

string str = normal.ToString(CultureInfo.InvariantCulture); // N(x; μ = 4, σ² = 17.64)
See Also