Click or drag to resize
Accord.NET (logo)

EmpiricalDistribution Class

Empirical distribution.
Inheritance Hierarchy
SystemObject
  Accord.Statistics.DistributionsDistributionBase
    Accord.Statistics.Distributions.UnivariateUnivariateContinuousDistribution
      Accord.Statistics.Distributions.UnivariateEmpiricalDistribution

Namespace:  Accord.Statistics.Distributions.Univariate
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.8.0
Syntax
[SerializableAttribute]
public class EmpiricalDistribution : UnivariateContinuousDistribution, 
	IFittableDistribution<double, EmpiricalOptions>, IFittable<double, EmpiricalOptions>, 
	IFittable<double>, IFittableDistribution<double>, IDistribution<double>, 
	IDistribution, ICloneable, ISampleableDistribution<double>, IRandomNumberGenerator<double>
Request Example View Source

The EmpiricalDistribution type exposes the following members.

Constructors
  NameDescription
Public methodEmpiricalDistribution(Double)
Creates a new Empirical Distribution from the data samples.
Public methodEmpiricalDistribution(Double, Double)
Creates a new Empirical Distribution from the data samples.
Public methodEmpiricalDistribution(Double, Double)
Creates a new Empirical Distribution from the data samples.
Public methodEmpiricalDistribution(Double, Int32)
Creates a new Empirical Distribution from the data samples.
Public methodEmpiricalDistribution(Double, Double, Double)
Creates a new Empirical Distribution from the data samples.
Public methodEmpiricalDistribution(Double, Int32, Double)
Creates a new Empirical Distribution from the data samples.
Top
Properties
  NameDescription
Public propertyCounts
Gets the repetition counts associated with each sample. Note that changing values on this array will not result int any effect in this distribution. The distribution must be computed from scratch with new values in case new weights needs to be used.
Public propertyEntropy
Gets the entropy for this distribution.
(Overrides UnivariateContinuousDistributionEntropy.)
Public propertyLength
Gets the total number of samples in this distribution.
Public propertyCode exampleMean
Gets the mean for this distribution.
(Overrides UnivariateContinuousDistributionMean.)
Public propertyMedian
Gets the median for this distribution.
(Inherited from UnivariateContinuousDistribution.)
Public propertyMode
Gets the mode for this distribution.
(Overrides UnivariateContinuousDistributionMode.)
Public propertyQuartiles
Gets the Quartiles for this distribution.
(Inherited from UnivariateContinuousDistribution.)
Public propertySamples
Gets the samples giving this empirical distribution.
Public propertySmoothing
Gets the bandwidth smoothing parameter used in the kernel density estimation.
Public propertyStandardDeviation
Gets the Standard Deviation (the square root of the variance) for the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public propertySupport
Gets the support interval for this distribution.
(Overrides UnivariateContinuousDistributionSupport.)
Public propertyCode exampleVariance
Gets the variance for this distribution.
(Overrides UnivariateContinuousDistributionVariance.)
Public propertyWeights
Gets the fractional weights associated with each sample. Note that changing values on this array will not result int any effect in this distribution. The distribution must be computed from scratch with new values in case new weights needs to be used.
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.
(Inherited from UnivariateContinuousDistribution.)
Public methodCumulativeHazardFunction
Gets the cumulative hazard function for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodDistributionFunction(Double)
Gets the cumulative distribution function (cdf) for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
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.)
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 methodCode exampleFit(Double)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodCode exampleFit(Double, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodCode exampleFit(Double, Double)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodCode exampleFit(Double, Int32)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodFit(Double, Double, EmpiricalOptions)
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 UnivariateContinuousDistributionFit(Double, Double, IFittingOptions).)
Public methodFit(Double, Int32, EmpiricalOptions)
Fits the underlying distribution to a given set of observations.
Public methodCode exampleFit(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.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Random)
Generates a random observation from the current distribution.
(Overrides UnivariateContinuousDistributionGenerate(Random).)
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.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Int32, Random)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Int32, Double, Random)
Generates a random vector of observations from the current distribution.
(Overrides UnivariateContinuousDistributionGenerate(Int32, Double, Random).)
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.)
Protected methodInnerComplementaryDistributionFunction
Gets the complementary cumulative distribution function (ccdf) for this distribution evaluated at point x. This function is also known as the Survival function.
(Inherited from UnivariateContinuousDistribution.)
Protected methodCode exampleInnerDistributionFunction
Gets the cumulative distribution function (cdf) for this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionInnerDistributionFunction(Double).)
Protected methodInnerInverseDistributionFunction
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 UnivariateContinuousDistribution.)
Protected methodInnerLogProbabilityDensityFunction
Gets the log-probability density function (pdf) for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Protected methodCode exampleInnerProbabilityDensityFunction
Gets the probability density function (pdf) for this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionInnerProbabilityDensityFunction(Double).)
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 UnivariateContinuousDistribution.)
Public methodLogCumulativeHazardFunction
Gets the log of the cumulative hazard function for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodLogProbabilityDensityFunction
Gets the log-probability density function (pdf) for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodProbabilityDensityFunction
Gets the probability density function (pdf) for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodQuantileDensityFunction
Gets the first derivative of the inverse distribution function (icdf) for this distribution evaluated at probability p.
(Inherited from UnivariateContinuousDistribution.)
Public methodStatic memberSmoothingRule(Double)
Gets the default estimative of the smoothing parameter.
Public methodStatic memberSmoothingRule(Double, Double)
Gets the default estimative of the smoothing parameter.
Public methodStatic memberSmoothingRule(Double, Int32)
Gets the default estimative of the smoothing parameter.
Public methodStatic memberSmoothingRule(Double, Double, Int32)
Gets the default estimative of the smoothing parameter.
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).)
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

Empirical distributions are based solely on the data. This class uses the empirical distribution function and the Gaussian kernel density estimation to provide an univariate continuous distribution implementation which depends only on sampled data.

References:

Examples

The following example shows how to build an empirical distribution directly from a sample:

// Consider the following univariate samples
double[] samples = { 5, 5, 1, 4, 1, 2, 2, 3, 3, 3, 4, 3, 3, 3, 4, 3, 2, 3 };

// Create a non-parametric, empirical distribution using those samples:
EmpiricalDistribution distribution = new EmpiricalDistribution(samples);

// Common measures
double mean   = distribution.Mean;     // 3
double median = distribution.Median;   // 2.9999993064186787
double var    = distribution.Variance; // 1.2941176470588236

// Cumulative distribution function
double cdf  = distribution.DistributionFunction(x: 4.2);          // 0.88888888888888884
double ccdf = distribution.ComplementaryDistributionFunction(x: 4.2); //0.11111111111111116
double icdf = distribution.InverseDistributionFunction(p: cdf);       // 4.1999999999999993

// Probability density functions
double pdf  = distribution.ProbabilityDensityFunction(x: 4.2);    // 0.15552784414141974
double lpdf = distribution.LogProbabilityDensityFunction(x: 4.2); // -1.8609305013898356

// Hazard (failure rate) functions
double hf  = distribution.HazardFunction(x: 4.2);           // 1.3997505972727771
double chf = distribution.CumulativeHazardFunction(x: 4.2); // 2.1972245773362191

// Automatically estimated smooth parameter (gamma)
double smoothing = distribution.Smoothing; // 1.9144923416414432

// String representation
string str = distribution.ToString(CultureInfo.InvariantCulture); // Fn(x; S)
See Also