Package com.irurueta.statistics
Class NormalDist
java.lang.Object
com.irurueta.statistics.NormalDist
Contains methods to work with normal (i.e. Gaussian) distributions.
Methods of this class use methods of the Erf class.
This class is based in code of Numerical Recipes 3rd ed. section 6.14.1.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Interface to evaluate a one dimensional function at point x and to obtain its derivative at such point. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double
Term to normalize Gaussian so that its integral from -infinity to infinity is one.private static final double
Square root of 2 divided by 2.private double
Mean value of Gaussian distribution.private double
Standard deviation of Gaussian distribution.private static final double
Square root of 2. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.NormalDist
(double mu, double sig) Constructor with mean and standard deviation. -
Method Summary
Modifier and TypeMethodDescriptiondouble
cdf
(double x) Evaluates the cumulative distribution function (c.d.f.) of a Gaussian distribution having the mean and standard deviation of this instance at provided point x.static double
cdf
(double x, double mu, double sig) Evaluates the cumulative distribution function (c.d.f.) of a Gaussian distribution having mean mu and standard deviation sig at provided point x.double
getMean()
Gets mean value of Gaussian distribution.double
Gets standard deviation of Gaussian distribution.double
Gets variance of Gaussian distribution.private static double
internalCdf
(double x, double mu, double sig) Evaluates the cumulative distribution function (c.d.f.) of a Gaussian distribution having mean mu and standard deviation sig at provided point x.private static double
internalInvcdf
(double p, double mu, double sig) Evaluates the inverse cumulative distribution function of a Gaussian distribution having mean mu and standard deviation sig at provided point p.private static double
internalMahalanobisDistance
(double x, double mu, double sig) Computes the Mahalanobis distance of provided point x for provided mean and standard deviation values.private static double
internalP
(double x, double mu, double sig) Evaluates the probability density function (p.d.f.) of a Gaussian distribution having mean mu and standard deviation sig at provided point x.double
invcdf
(double p) Evaluates the inverse cumulative distribution function of a Gaussian distribution having the mean and standard deviation of this instance at provided point p.static double
invcdf
(double p, double mu, double sig) Evaluates the inverse cumulative distribution function of a Gaussian distribution having mean mu and standard deviation sig at provided point p.double
mahalanobisDistance
(double x) Computes the Mahalanobis distance of provided point x for current mean and standard deviation values.static double
mahalanobisDistance
(double x, double mu, double sig) Computes the Mahalanobis distance of provided point x for provided mean and standard deviation values.double
p
(double x) Evaluates the probability density function (p.d.f.) of a Gaussian distribution having the mean and standard deviation of this instance at provided point x.static double
p
(double x, double mu, double sig) Evaluates the probability density function (p.d.f.) of a Gaussian distribution having mean mu and standard deviation sig at provided point x.static NormalDist
propagate
(NormalDist.DerivativeEvaluator evaluator, double mean, double standardDeviation) Evaluates the derivative and a 1D function at a certain mean point and computes the non-linear propagation of Gaussian uncertainty through such function at such point.static void
propagate
(NormalDist.DerivativeEvaluator evaluator, double mean, double standardDeviation, NormalDist result) Evaluates the derivative and a 1D function at a certain mean point and computes the non-linear propagation of Gaussian uncertainty through such function at such point.static NormalDist
propagate
(NormalDist.DerivativeEvaluator evaluator, NormalDist dist) Evaluates the derivative and a 1D function at a certain mean point and computes the non-linear propagation of Gaussian uncertainty through such function at such point.static void
propagate
(NormalDist.DerivativeEvaluator evaluator, NormalDist dist, NormalDist result) Evaluates the derivative and a 1D function at a certain mean point and computes the non-linear propagation of Gaussian uncertainty through such function at such point.Evaluates the derivative and a 1D function at the mean point of this normal distribution and computes the non-linear propagation of Gaussian uncertainty through such function at such point.void
propagateThisDistribution
(NormalDist.DerivativeEvaluator evaluator, NormalDist result) Evaluates the derivative and a 1D function at the mean point of this normal distribution and computes the non-linear propagation of Gaussian uncertainty through such function at such point.final void
setMean
(double mu) Sets mean value of Gaussian distribution.final void
setStandardDeviation
(double sig) Sets standard deviation of Gaussian distribution.void
setVariance
(double variance) Sets variance of Gaussian distribution.
-
Field Details
-
SQRT2
private static final double SQRT2Square root of 2. -
HALF_SQRT2
private static final double HALF_SQRT2Square root of 2 divided by 2. -
GAUSSIAN_NORM
private static final double GAUSSIAN_NORMTerm to normalize Gaussian so that its integral from -infinity to infinity is one. -
mu
private double muMean value of Gaussian distribution. -
sig
private double sigStandard deviation of Gaussian distribution.
-
-
Constructor Details
-
NormalDist
public NormalDist()Constructor. Initializes a Gaussian distribution with zero mean and unitary standard deviation (i.e. N(0,1)). -
NormalDist
public NormalDist(double mu, double sig) Constructor with mean and standard deviation.- Parameters:
mu
- mean value of Gaussian distribution.sig
- standard deviation of Gaussian distribution.- Throws:
IllegalArgumentException
- if provided standard deviation is zero or negative.
-
-
Method Details
-
getMean
public double getMean()Gets mean value of Gaussian distribution.- Returns:
- mean value of Gaussian distribution.
-
setMean
public final void setMean(double mu) Sets mean value of Gaussian distribution.- Parameters:
mu
- mean value of Gaussian distribution.
-
getStandardDeviation
public double getStandardDeviation()Gets standard deviation of Gaussian distribution.- Returns:
- standard deviation of Gaussian distribution.
-
setStandardDeviation
public final void setStandardDeviation(double sig) Sets standard deviation of Gaussian distribution.- Parameters:
sig
- standard deviation to be set.- Throws:
IllegalArgumentException
- if provided standard deviation is zero or negative.
-
getVariance
public double getVariance()Gets variance of Gaussian distribution.- Returns:
- variance of Gaussian distribution.
-
setVariance
public void setVariance(double variance) Sets variance of Gaussian distribution.- Parameters:
variance
- variance of Gaussian distribution.- Throws:
IllegalArgumentException
- if provided variance is zero or negative.
-
p
public static double p(double x, double mu, double sig) Evaluates the probability density function (p.d.f.) of a Gaussian distribution having mean mu and standard deviation sig at provided point x.- Parameters:
x
- point where p.d.f. is evaluated.mu
- mean of Gaussian distribution.sig
- standard deviation of Gaussian distribution.- Returns:
- evaluation of p.d.f.
- Throws:
IllegalArgumentException
- if provided standard deviation is zero or negative.
-
p
public double p(double x) Evaluates the probability density function (p.d.f.) of a Gaussian distribution having the mean and standard deviation of this instance at provided point x.- Parameters:
x
- point where p.d.f. is evaluated.- Returns:
- evaluation of p.d.f.
-
cdf
public static double cdf(double x, double mu, double sig) Evaluates the cumulative distribution function (c.d.f.) of a Gaussian distribution having mean mu and standard deviation sig at provided point x. The c.d.f is equivalent to the probability of the Gaussian distribution of having a value less than x, and it is computed as the integral from -infinity to x of the Gaussian p.d.f.- Parameters:
x
- point where c.d.f. is evaluated.mu
- mean of Gaussian distribution.sig
- standard deviation of Gaussian distribution.- Returns:
- evaluation of c.d.f.
- Throws:
IllegalArgumentException
- if provided standard deviation is zero or negative.
-
cdf
public double cdf(double x) Evaluates the cumulative distribution function (c.d.f.) of a Gaussian distribution having the mean and standard deviation of this instance at provided point x. The c.d.f is equivalent to the probability of the Gaussian distribution of having a value less than x, and it is computed as the integral from -infinity to x of the Gaussian p.d.f. Because the c.d.f is a probability, it always returns values between 0.0 and 1.0.- Parameters:
x
- point where c.d.f. is evaluated.- Returns:
- evaluation of c.d.f.
-
invcdf
public static double invcdf(double p, double mu, double sig) Evaluates the inverse cumulative distribution function of a Gaussian distribution having mean mu and standard deviation sig at provided point p. Because the c.d.f is a monotonically increasing function with values between 0.0 and 1.0, its inverse is uniquely defined between such range of values.- Parameters:
p
- value to evaluate the inverse c.d.f. at. This value is equivalent to a probability and must be between 0.0 and 1.0.mu
- mean of Gaussian distribution.sig
- standard deviation of Gaussian distribution.- Returns:
- the value x for which the c.d.f. has value p.
- Throws:
IllegalArgumentException
- if provided standard deviation is zero or negative, or if provided probability value is not between 0.0 and 1.0.
-
invcdf
public double invcdf(double p) Evaluates the inverse cumulative distribution function of a Gaussian distribution having the mean and standard deviation of this instance at provided point p. Because the c.d.f is a monotonically increasing function with values between 0.0 and 1.0, its inverse is uniquely defined between such range of values.- Parameters:
p
- value to evaluate the inverse c.d.f. at. This value is equivalent to a probability and must be between 0.0 and 1.0.- Returns:
- the value x for which the c.d.f. has value p.
- Throws:
IllegalArgumentException
- if provided probability value is not between 0.0 and 1.0.
-
mahalanobisDistance
public static double mahalanobisDistance(double x, double mu, double sig) Computes the Mahalanobis distance of provided point x for provided mean and standard deviation values.- Parameters:
x
- point where Mahalanobis distance is evaluated.mu
- mean of Gaussian distribution.sig
- standard deviation of Gaussian distribution.- Returns:
- Mahalanobis distance of provided point respect to mean.
- Throws:
IllegalArgumentException
- if provided standard deviation is zero or negative.
-
mahalanobisDistance
public double mahalanobisDistance(double x) Computes the Mahalanobis distance of provided point x for current mean and standard deviation values.- Parameters:
x
- point where Mahalanobis distance is evaluated.- Returns:
- Mahalanobis distance of provided point respect to current mean.
-
internalP
private static double internalP(double x, double mu, double sig) Evaluates the probability density function (p.d.f.) of a Gaussian distribution having mean mu and standard deviation sig at provided point x. This method is used internally.- Parameters:
x
- point where p.d.f. is evaluated.mu
- mean of Gaussian distribution.sig
- standard deviation of Gaussian distribution.- Returns:
- evaluation of p.d.f.
- Throws:
IllegalArgumentException
- if provided standard deviation is zero or negative.
-
internalCdf
private static double internalCdf(double x, double mu, double sig) Evaluates the cumulative distribution function (c.d.f.) of a Gaussian distribution having mean mu and standard deviation sig at provided point x. The c.d.f is equivalent to the probability of the Gaussian distribution of having a value less than x, and it is computed as the integral from -infinity to x of the Gaussian p.d.f. This method is used internally.- Parameters:
x
- point where c.d.f. is evaluated.mu
- mean of Gaussian distribution.sig
- standard deviation of Gaussian distribution.- Returns:
- evaluation of c.d.f.
- Throws:
IllegalArgumentException
- if provided standard deviation is zero or negative.
-
internalInvcdf
private static double internalInvcdf(double p, double mu, double sig) throws IllegalArgumentException Evaluates the inverse cumulative distribution function of a Gaussian distribution having mean mu and standard deviation sig at provided point p. Because the c.d.f is a monotonically increasing function with values between 0.0 and 1.0, its inverse is uniquely defined between such range of values. This method is used internally.- Parameters:
p
- value to evaluate the inverse c.d.f. at. This value is equivalent to a probability and must be between 0.0 and 1.0.mu
- mean of Gaussian distribution.sig
- standard deviation of Gaussian distribution.- Returns:
- the value x for which the c.d.f. has value p.
- Throws:
IllegalArgumentException
- if provided probability value is not between 0.0 and 1.0.
-
internalMahalanobisDistance
private static double internalMahalanobisDistance(double x, double mu, double sig) Computes the Mahalanobis distance of provided point x for provided mean and standard deviation values.- Parameters:
x
- point where Mahalanobis distance is evaluated.mu
- mean of Gaussian distribution.sig
- standard deviation of Gaussian distribution.- Returns:
- Mahalanobis distance of provided point respect to mean.
-
propagate
public static void propagate(NormalDist.DerivativeEvaluator evaluator, double mean, double standardDeviation, NormalDist result) Evaluates the derivative and a 1D function at a certain mean point and computes the non-linear propagation of Gaussian uncertainty through such function at such point.- Parameters:
evaluator
- interface to evaluate derivative of a function at a certain point.mean
- mean of original Gaussian distribution to be propagated.standardDeviation
- standard deviation of original Gaussian distribution to be propagated.result
- instance where propagated Gaussian distribution will be stored.- See Also:
-
propagate
public static NormalDist propagate(NormalDist.DerivativeEvaluator evaluator, double mean, double standardDeviation) Evaluates the derivative and a 1D function at a certain mean point and computes the non-linear propagation of Gaussian uncertainty through such function at such point.- Parameters:
evaluator
- interface to evaluate derivative of a function at a certain point.mean
- mean of original Gaussian distribution to be propagated.standardDeviation
- standard deviation of original Gaussian distribution to be propagated.- Returns:
- a new propagated Gaussian distribution.
- See Also:
-
propagate
public static void propagate(NormalDist.DerivativeEvaluator evaluator, NormalDist dist, NormalDist result) Evaluates the derivative and a 1D function at a certain mean point and computes the non-linear propagation of Gaussian uncertainty through such function at such point.- Parameters:
evaluator
- interface to evaluate derivative of a function at a certain point.dist
- 1D Gaussian distribution to be propagated.result
- instance where propagated Gaussian distribution will be stored.- See Also:
-
propagate
Evaluates the derivative and a 1D function at a certain mean point and computes the non-linear propagation of Gaussian uncertainty through such function at such point.- Parameters:
evaluator
- interface to evaluate derivative of a function at a certain point.dist
- 1D Gaussian distribution to be propagated.- Returns:
- a new propagated Gaussian distribution.
- See Also:
-
propagateThisDistribution
Evaluates the derivative and a 1D function at the mean point of this normal distribution and computes the non-linear propagation of Gaussian uncertainty through such function at such point.- Parameters:
evaluator
- interface to evaluate derivative of a function at the mean point of this normal distribution.result
- instance where propagated Gaussian distribution will be stored.- See Also:
-
propagateThisDistribution
Evaluates the derivative and a 1D function at the mean point of this normal distribution and computes the non-linear propagation of Gaussian uncertainty through such function at such point.- Parameters:
evaluator
- interface to evaluate derivative of a function at the mean point of this normal distribution.- Returns:
- a new propagated Gaussian distribution.
- See Also:
-