CauchyDistribution Class 
Namespace: Accord.Statistics.Distributions.Univariate
[SerializableAttribute] public class CauchyDistribution : UnivariateContinuousDistribution, IFittableDistribution<double, CauchyOptions>, IFittable<double, CauchyOptions>, IFittable<double>, IFittableDistribution<double>, IDistribution<double>, IDistribution, ICloneable, ISampleableDistribution<double>, IRandomNumberGenerator<double>, IFormattable
The CauchyDistribution type exposes the following members.
Name  Description  

CauchyDistribution 
Constructs a CauchyLorentz distribution
with location parameter 0 and scale 1.
 
CauchyDistribution(Double, Double) 
Constructs a CauchyLorentz distribution
with given location and scale parameters.

Name  Description  

Entropy 
Gets the entropy for this distribution.
(Overrides UnivariateContinuousDistributionEntropy.)  
Location 
Gets the distribution's
location parameter x0.
 
Mean 
Cauchy's mean is undefined.
(Overrides UnivariateContinuousDistributionMean.)  
Median 
Gets the median for this distribution.
(Overrides UnivariateContinuousDistributionMedian.)  
Mode 
Gets the mode for this distribution.
(Overrides UnivariateContinuousDistributionMode.)  
Quartiles 
Gets the Quartiles for this distribution.
(Inherited from UnivariateContinuousDistribution.)  
Scale 
Gets the distribution's
scale parameter gamma.
 
Standard 
Gets the Standard Cauchy Distribution,
with zero location and unitary shape.
 
StandardDeviation 
Gets the Standard Deviation (the square root of
the variance) for the current distribution.
(Inherited from UnivariateContinuousDistribution.)  
Support 
Gets the support interval for this distribution.
(Overrides UnivariateContinuousDistributionSupport.)  
Variance 
Cauchy's variance is undefined.
(Overrides UnivariateContinuousDistributionVariance.) 
Name  Description  

Clone 
Creates a new object that is a copy of the current instance.
(Overrides DistributionBaseClone.)  
ComplementaryDistributionFunction 
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.)  
CumulativeHazardFunction 
Gets the cumulative hazard function for this
distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)  
DistributionFunction(Double) 
Gets the cumulative distribution function (cdf) for
this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)  
DistributionFunction(Double, Double) 
Gets the cumulative distribution function (cdf) for this
distribution in the semiclosed interval (a; b] given as
P(a < X ≤ b).
(Inherited from UnivariateContinuousDistribution.)  
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.)  
Fit(Double) 
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)  
Fit(Double, IFittingOptions) 
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)  
Fit(Double, Double) 
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)  
Fit(Double, Int32) 
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)  
Fit(Double, Double, CauchyOptions) 
Fits the underlying distribution to a given set of observations.
 
Fit(Double, Double, IFittingOptions) 
Fits the underlying distribution to a given set of observations.
(Overrides UnivariateContinuousDistributionFit(Double, Double, IFittingOptions).)  
Fit(Double, Int32, IFittingOptions) 
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)  
Generate 
Generates a random observation from the current distribution.
(Inherited from UnivariateContinuousDistribution.)  
Generate(Random) 
Generates a random observation from the current distribution.
(Overrides UnivariateContinuousDistributionGenerate(Random).)  
Generate(Int32) 
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)  
Generate(Int32, Double) 
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)  
Generate(Int32, Random) 
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)  
Generate(Int32, Double, Random) 
Generates a random vector of observations from the current distribution.
(Overrides UnivariateContinuousDistributionGenerate(Int32, Double, Random).)  
GetHashCode  Serves as the default hash function. (Inherited from Object.)  
GetRange 
Gets the distribution range within a given percentile.
(Inherited from UnivariateContinuousDistribution.)  
GetType  Gets the Type of the current instance. (Inherited from Object.)  
HazardFunction 
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.)  
InnerComplementaryDistributionFunction 
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.)  
InnerDistributionFunction 
Gets the cumulative distribution function (cdf) for
this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionInnerDistributionFunction(Double).)  
InnerInverseDistributionFunction 
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.)  
InnerLogProbabilityDensityFunction 
Gets the logprobability density function (pdf) for
this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionInnerLogProbabilityDensityFunction(Double).)  
InnerProbabilityDensityFunction 
Gets the probability density function (pdf) for
this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionInnerProbabilityDensityFunction(Double).)  
InverseDistributionFunction 
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.)  
LogCumulativeHazardFunction 
Gets the log of the cumulative hazard function for this
distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)  
LogProbabilityDensityFunction 
Gets the logprobability density function (pdf) for
this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)  
MemberwiseClone  Creates a shallow copy of the current Object. (Inherited from Object.)  
ProbabilityDensityFunction 
Gets the probability density function (pdf) for
this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)  
QuantileDensityFunction 
Gets the first derivative of the
inverse distribution function (icdf) for this distribution evaluated
at probability p.
(Inherited from UnivariateContinuousDistribution.)  
Random(Double, Double) 
Generates a random observation from the
Cauchy distribution with the given parameters.
 
Random(Double, Double, Int32) 
Generates a random vector of observations from the
Cauchy distribution with the given parameters.
 
Random(Double, Double, Random) 
Generates a random observation from the
Cauchy distribution with the given parameters.
 
Random(Double, Double, Int32, Double) 
Generates a random vector of observations from the
Cauchy distribution with the given parameters.
 
Random(Double, Double, Int32, Random) 
Generates a random vector of observations from the
Cauchy distribution with the given parameters.
 
Random(Double, Double, Int32, Double, Random) 
Generates a random vector of observations from the
Cauchy distribution with the given parameters.
 
ToString 
Returns a String that represents this instance.
(Inherited from DistributionBase.)  
ToString(IFormatProvider) 
Returns a String that represents this instance.
(Inherited from DistributionBase.)  
ToString(String) 
Returns a String that represents this instance.
(Inherited from DistributionBase.)  
ToString(String, IFormatProvider) 
Returns a String that represents this instance.
(Overrides DistributionBaseToString(String, IFormatProvider).) 
Name  Description  

HasMethod 
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)  
IsEqual 
Compares two objects for equality, performing an elementwise
comparison if the elements are vectors or matrices.
(Defined by Matrix.)  
To(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.)  
ToT  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.) 
The Cauchy distribution, named after Augustin Cauchy, is a continuous probability distribution. It is also known, especially among physicists, as the Lorentz distribution (after Hendrik Lorentz), Cauchy–Lorentz distribution, Lorentz(ian) function, or Breit–Wigner distribution. The simplest Cauchy distribution is called the standard Cauchy distribution. It has the distribution of a random variable that is the ratio of two independent standard normal random variables.
References:
The following example demonstrates how to instantiate a Cauchy distribution with a given location parameter x0 and scale parameter γ (gamma), calculating its main properties and characteristics:
double location = 0.42; double scale = 1.57; // Create a new Cauchy distribution with x0 = 0.42 and γ = 1.57 CauchyDistribution cauchy = new CauchyDistribution(location, scale); // Common measures double mean = cauchy.Mean; // NaN  Cauchy's mean is undefined. double var = cauchy.Variance; // NaN  Cauchy's variance is undefined. double median = cauchy.Median; // 0.42 // Cumulative distribution functions double cdf = cauchy.DistributionFunction(x: 0.27); // 0.46968025841608563 double ccdf = cauchy.ComplementaryDistributionFunction(x: 0.27); // 0.53031974158391437 double icdf = cauchy.InverseDistributionFunction(p: 0.69358638272337991); // 1.5130304686978195 // Probability density functions double pdf = cauchy.ProbabilityDensityFunction(x: 0.27); // 0.2009112009763413 double lpdf = cauchy.LogProbabilityDensityFunction(x: 0.27); // 1.6048922547266871 // Hazard (failure rate) functions double hf = cauchy.HazardFunction(x: 0.27); // 0.3788491832800277 double chf = cauchy.CumulativeHazardFunction(x: 0.27); // 0.63427516833243092 // String representation string str = cauchy.ToString(CultureInfo.InvariantCulture); // "Cauchy(x; x0 = 0.42, γ = 1.57)
The following example shows how to fit a Cauchy distribution (estimate its location and shape parameters) given a set of observation values.
// Create an initial distribution CauchyDistribution cauchy = new CauchyDistribution(); // Consider a vector of univariate observations double[] observations = { 0.25, 0.12, 0.72, 0.21, 0.62, 0.12, 0.62, 0.12 }; // Fit to the observations cauchy.Fit(observations); // Check estimated values double location = cauchy.Location; // 0.18383 double gamma = cauchy.Scale; // 0.10530
It is also possible to estimate only some of the Cauchy parameters at a time. For this, you can specify a CauchyOptions object and pass it alongside the observations:
// Create options to estimate location only CauchyOptions options = new CauchyOptions() { EstimateLocation = true, EstimateScale = false }; // Create an initial distribution with a predefined scale CauchyDistribution cauchy = new CauchyDistribution(location: 0, scale: 4.2); // Fit to the observations cauchy.Fit(observations, options); // Check estimated values double location = cauchy.Location; // 0.3471218110202 double gamma = cauchy.Scale; // 4.2 (unchanged)