Package jsl.utilities.distributions
Class Normal
- java.lang.Object
-
- jsl.utilities.distributions.Distribution
-
- jsl.utilities.distributions.Normal
-
- All Implemented Interfaces:
ControllableIfc
,CDFIfc
,ContinuousDistributionIfc
,DistributionFunctionIfc
,DistributionIfc
,DomainIfc
,FirstOrderLossFunctionIfc
,InverseCDFIfc
,LossFunctionDistributionIfc
,MeanIfc
,PDFIfc
,SecondOrderLossFunctionIfc
,VarianceIfc
,GetNameIfc
,IdentityIfc
,NewInstanceIfc
,ParametersIfc
,GetRVariableIfc
public class Normal extends Distribution implements ContinuousDistributionIfc, LossFunctionDistributionIfc, InverseCDFIfc, GetRVariableIfc
Models normally distributed random variables
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jsl.utilities.distributions.Distribution
Distribution.RandomControls
-
-
Field Summary
-
Fields inherited from class jsl.utilities.distributions.Distribution
myId, myName
-
-
Constructor Summary
Constructors Constructor Description Normal()
Constructs a normal distribution with mean 0.0 and variance 1.0Normal(double[] parameters)
Constructs a normal distribution with mean = parameters[0] and variance = parameters[1]Normal(double mean, double variance)
Constructs a normal distribution with mean and variance.Normal(double mean, double variance, java.lang.String name)
Constructs a normal distribution with mean and variance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description double
cdf(double x)
Returns the F(x) = Pr{X <= x} where F represents the cumulative distribution functiondouble
complementaryCDF(double x)
Computes the complementary cumulative probability distribution function for given value of xdouble
firstOrderLossFunction(double x)
Computes the first order loss function for the function for given value of x, G1(x) = E[max(X-x,0)]Interval
getDomain()
double
getKurtosis()
Gets the kurtosis of the distributiondouble
getMean()
Returns the mean or expected value of a distributiondouble[]
getParameters()
Gets the parameters for the distributionRVariableIfc
getRandomVariable(RNStreamIfc rng)
double
getSkewness()
Gets the skewness of the distributiondouble
getVariance()
Returns the variance of the distribution if defineddouble
invCDF(double p)
Provides the inverse cumulative distribution function for the distribution While closed form solutions for the inverse cdf may not exist, numerical search methods can be used to solve F(X) = U.Normal
newInstance()
Returns a new instancedouble
pdf(double x)
Returns the f(x) where f represents the probability density function for the distribution.double
secondOrderLossFunction(double x)
Computes the 2nd order loss function for the distribution function for given value of x, G2(x) = (1/2)E[max(X-x,0)*max(X-x-1,0)]void
setMean(double mean)
Sets the mean of this normal distributionvoid
setParameters(double[] parameters)
Sets the parameters for the distribution mean = parameters[0] and variance = parameters[1]void
setVariance(double variance)
Sets the variance of this normal distributionstatic double
stdNormalCDF(double z)
Computes the cumulative distribution function for a standard normal distribution using Taylor approximation.static double
stdNormalCDFAbramovitzAndStegun(double z)
Computes the cumulative distribution function for a standard normal distribution from Abramovitz and Stegun, see also Didier H.static double
stdNormalComplementaryCDF(double z)
Computes the complementary cumulative probability for the standard normal distribution function for given value of zstatic double
stdNormalFirstOrderLossFunction(double z)
Computes the first order loss function for the standard normal distribution function for given value of x, G1(z) = E[max(Z-z,0)]static double
stdNormalInvCDF(double p)
Computes the inverse cumulative distribution function for a standard normal distribution see, W.static double
stdNormalPDF(double z)
Computes the pdf function for a standard normal distribution from Abramovitz and Stegun, see also Didier H.static double
stdNormalSecondOrderLossFunction(double z)
Computes the 2nd order loss function for the standard normal distribution function for given value of z, G2(z) = (1/2)E[max(Z-z,0)*max(Z-z-1,0)]-
Methods inherited from class jsl.utilities.distributions.Distribution
getControls, getId, getName, getStandardDeviation, inverseContinuousCDFViaBisection, inverseContinuousCDFViaBisection, inverseDiscreteCDFViaSearchUp, setControls, setId, setName, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jsl.utilities.random.rvariable.GetRVariableIfc
getRandomVariable, getRandomVariable
-
Methods inherited from interface jsl.utilities.distributions.VarianceIfc
getStandardDeviation
-
-
-
-
Constructor Detail
-
Normal
public Normal()
Constructs a normal distribution with mean 0.0 and variance 1.0
-
Normal
public Normal(double[] parameters)
Constructs a normal distribution with mean = parameters[0] and variance = parameters[1]- Parameters:
parameters
- An array with the mean and variance
-
Normal
public Normal(double mean, double variance)
Constructs a normal distribution with mean and variance.- Parameters:
mean
- of the distributionvariance
- must be > 0
-
Normal
public Normal(double mean, double variance, java.lang.String name)
Constructs a normal distribution with mean and variance.- Parameters:
mean
- of the distributionvariance
- must be > 0name
- an optional name/label
-
-
Method Detail
-
newInstance
public final Normal newInstance()
Description copied from interface:NewInstanceIfc
Returns a new instance- Specified by:
newInstance
in interfaceNewInstanceIfc
- Specified by:
newInstance
in classDistribution
- Returns:
- the new instance
-
setMean
public final void setMean(double mean)
Sets the mean of this normal distribution- Parameters:
mean
- of the distribution
-
getMean
public final double getMean()
Description copied from interface:MeanIfc
Returns the mean or expected value of a distribution
-
setVariance
public final void setVariance(double variance)
Sets the variance of this normal distribution- Parameters:
variance
- of the distribution, must be > 0
-
getVariance
public final double getVariance()
Description copied from interface:VarianceIfc
Returns the variance of the distribution if defined- Specified by:
getVariance
in interfaceVarianceIfc
- Returns:
- double the variance of the random variable
-
stdNormalCDFAbramovitzAndStegun
public static double stdNormalCDFAbramovitzAndStegun(double z)
Computes the cumulative distribution function for a standard normal distribution from Abramovitz and Stegun, see also Didier H. Besset Object-oriented Implementation of Numerical Methods, Morgan-Kaufmann (2001)- Parameters:
z
- the z-ordinate to be evaluated- Returns:
- the P(Z<=z) for standard normal
-
stdNormalCDF
public static double stdNormalCDF(double z)
Computes the cumulative distribution function for a standard normal distribution using Taylor approximation. The approximation is accurate to absolute error less than 8 * 10^(-16). * Reference: Evaluating the Normal Distribution by George Marsaglia. * http://www.jstatsoft.org/v11/a04/paper- Parameters:
z
- the z-ordinate to be evaluated- Returns:
- the P(Z<=z) for standard normal
-
stdNormalPDF
public static double stdNormalPDF(double z)
Computes the pdf function for a standard normal distribution from Abramovitz and Stegun, see also Didier H. Besset Object-oriented Implementation of Numerical Methods, Morgan-Kaufmann (2001)- Parameters:
z
- the z-ordinate to be evaluated- Returns:
- the f(z) for standard normal
-
stdNormalInvCDF
public static double stdNormalInvCDF(double p)
Computes the inverse cumulative distribution function for a standard normal distribution see, W. J. Cody, Rational Chebyshev approximations for the error function Math. Comp. pp 631-638 this is without the extra refinement and has relative error of 1.15e-9 http://www.math.uio.no/~jacklam/notes/invnorm/- Parameters:
p
- the probability to be evaluated, p must be within [0,1] p = 0.0 returns Double.NEGATIVE_INFINTITY p = 1.0 returns Double.POSITIVE_INFINITY- Returns:
- the "z" value associated with the p
-
stdNormalComplementaryCDF
public static double stdNormalComplementaryCDF(double z)
Computes the complementary cumulative probability for the standard normal distribution function for given value of z- Parameters:
z
- The value to be evaluated- Returns:
- The probability, 1-P{X<=z}
-
stdNormalFirstOrderLossFunction
public static double stdNormalFirstOrderLossFunction(double z)
Computes the first order loss function for the standard normal distribution function for given value of x, G1(z) = E[max(Z-z,0)]- Parameters:
z
- The value to be evaluated- Returns:
- The loss function value, E[max(Z-z,0)]
-
stdNormalSecondOrderLossFunction
public static double stdNormalSecondOrderLossFunction(double z)
Computes the 2nd order loss function for the standard normal distribution function for given value of z, G2(z) = (1/2)E[max(Z-z,0)*max(Z-z-1,0)]- Parameters:
z
- The value to be evaluated- Returns:
- The loss function value, (1/2)E[max(Z-z,0)*max(Z-z-1,0)]
-
cdf
public final double cdf(double x)
Description copied from interface:CDFIfc
Returns the F(x) = Pr{X <= x} where F represents the cumulative distribution function
-
pdf
public final double pdf(double x)
Description copied from interface:PDFIfc
Returns the f(x) where f represents the probability density function for the distribution. Note this is not a probability.
-
invCDF
public final double invCDF(double p)
Description copied from interface:InverseCDFIfc
Provides the inverse cumulative distribution function for the distribution While closed form solutions for the inverse cdf may not exist, numerical search methods can be used to solve F(X) = U.- Specified by:
invCDF
in interfaceInverseCDFIfc
- Parameters:
p
- The probability to be evaluated for the inverse, p must be [0,1] or an IllegalArgumentException is thrown- Returns:
- The inverse cdf evaluated at the supplied probability
-
getKurtosis
public final double getKurtosis()
Gets the kurtosis of the distribution- Returns:
- the kurtosis
-
getSkewness
public final double getSkewness()
Gets the skewness of the distribution- Returns:
- the skewness
-
complementaryCDF
public double complementaryCDF(double x)
Description copied from interface:CDFIfc
Computes the complementary cumulative probability distribution function for given value of x- Specified by:
complementaryCDF
in interfaceCDFIfc
- Parameters:
x
- The value to be evaluated- Returns:
- The probability, 1-P{X<=x}
-
firstOrderLossFunction
public double firstOrderLossFunction(double x)
Description copied from interface:FirstOrderLossFunctionIfc
Computes the first order loss function for the function for given value of x, G1(x) = E[max(X-x,0)]- Specified by:
firstOrderLossFunction
in interfaceFirstOrderLossFunctionIfc
- Parameters:
x
- The value to be evaluated- Returns:
- The loss function value, E[max(X-x,0)]
-
secondOrderLossFunction
public double secondOrderLossFunction(double x)
Description copied from interface:SecondOrderLossFunctionIfc
Computes the 2nd order loss function for the distribution function for given value of x, G2(x) = (1/2)E[max(X-x,0)*max(X-x-1,0)]- Specified by:
secondOrderLossFunction
in interfaceSecondOrderLossFunctionIfc
- Parameters:
x
- The value to be evaluated- Returns:
- The loss function value, (1/2)E[max(X-x,0)*max(X-x-1,0)]
-
setParameters
public void setParameters(double[] parameters)
Sets the parameters for the distribution mean = parameters[0] and variance = parameters[1]- Specified by:
setParameters
in interfaceParametersIfc
- Parameters:
parameters
- an array of doubles representing the parameters for the distribution
-
getParameters
public double[] getParameters()
Gets the parameters for the distribution- Specified by:
getParameters
in interfaceParametersIfc
- Returns:
- Returns an array of the parameters for the distribution
-
getRandomVariable
public final RVariableIfc getRandomVariable(RNStreamIfc rng)
- Specified by:
getRandomVariable
in interfaceGetRVariableIfc
- Overrides:
getRandomVariable
in classDistribution
- Parameters:
rng
- the stream to use- Returns:
- a random variable
-
-