Package org.evoludo.math
Class RNGDistribution.Normal
Object
RNGDistribution
Normal
- Enclosing class:
RNGDistribution
Normally (or Gaussian) distributed random numbers with support
(-Double.MAX_VALUE, Double.MAX_VALUE).- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class RNGDistribution
RNGDistribution.Binomial, RNGDistribution.Exponential, RNGDistribution.Geometric, RNGDistribution.Gillespie, RNGDistribution.Normal, RNGDistribution.TestCommand, RNGDistribution.Uniform -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate doubleThe mean of the Normal distribution.private doubleThe standard deviation of the Normal distribution.Fields inherited from class RNGDistribution
rng, seed, seedSet, testSamples -
Constructor Summary
ConstructorsConstructorDescriptionNormal()Creates a standard Normal distribution withmean==0and standard deviationstdev==1using and a new instance ofMersenneTwister.Normal(double mean, double stdev) Creates Normal distribution withmeanand standard deviationstdevusing and a new instance ofMersenneTwister.Normal(MersenneTwister rng, double mean, double stdev) Creates Normal distribution withmeanand standard deviationstdevusing the random number generatorrng. -
Method Summary
Modifier and TypeMethodDescriptionprivate static doublecdf(double x, double mean, double stdev) Helper method to calculate the cumulative distribution function,cdf, of the Normal distribution.clone()Clone this RNGDistribution to ensure both objects return identical sequences of random numbers.private static doubleerf(double x) Numerical approximation of error functionerf(x)from Abramowitz & Stegun.doublegetMean()Get the mean of the Normal distribution.doublegetStdev()Get the standard deviation of the Normal distribution.doublenext()Generate a normally distributed random number withmeanand standard deviationstdev.static doublenext(MersenneTwister rng, double mean, double stdev) Normally distributed random number withmeanand standard deviationstdevusing random number generatorrng.static voidtest(MersenneTwister rng, Logger logger, MersenneTwister.Chronometer clock) Test Normal distribution.Methods inherited from class RNGDistribution
clearRNGSeed, clone, getRNG, getRNGSeed, isRNGSeedSet, nextBoolean, nextByte, nextBytes, nextDouble, nextGaussian, nextInt, nextInt, random01, random01d, random0n, random0N, setRNG, setRNGSeed, setRNGSeed
-
Field Details
-
mean
private double meanThe mean of the Normal distribution. -
stdev
private double stdevThe standard deviation of the Normal distribution.
-
-
Constructor Details
-
Normal
public Normal()Creates a standard Normal distribution withmean==0and standard deviationstdev==1using and a new instance ofMersenneTwister. -
Normal
public Normal(double mean, double stdev) Creates Normal distribution withmeanand standard deviationstdevusing and a new instance ofMersenneTwister.- Parameters:
mean- of Normal distributionstdev- of Normal distribution
-
Normal
Creates Normal distribution withmeanand standard deviationstdevusing the random number generatorrng.- Parameters:
rng- random number generatormean- of Normal distributionstdev- of Normal distribution- Throws:
IllegalArgumentException- ifman≤0- See Also:
-
-
Method Details
-
getMean
public double getMean()Get the mean of the Normal distribution.- Returns:
- the mean
-
getStdev
public double getStdev()Get the standard deviation of the Normal distribution.- Returns:
- the standard deviation
-
next
public double next()Generate a normally distributed random number withmeanand standard deviationstdev.- Returns:
- the Normally distributed random number
-
clone
Description copied from class:RNGDistributionClone this RNGDistribution to ensure both objects return identical sequences of random numbers.IMPORTANT:
- Specified by:
clonein classRNGDistribution- Returns:
- clone of RNGDistribution
-
next
Normally distributed random number withmeanand standard deviationstdevusing random number generatorrng.Note: no performance difference between the instance method
next()and this static counterpart.- Parameters:
rng- random number generatormean- the mean of the Normal distributionstdev- the standard deviation of the Normal distribution- Returns:
- Normally distributed random number
-
test
Test Normal distribution.The test samples the distribution and bins the random numbers. This sample distribution is compared to the theoretical expectation. The mean deviation is the mean difference between the actual number of events in each bin and their expected number. For a perfect match the mean deviation is
0. The test passes if the mean deviation lies within one standard error from0. This is more stringent than the traditional 95% confidence interval.- Parameters:
rng- the random number generatorlogger- the logger for reporting resultsclock- the stop watch- See Also:
-
cdf
private static double cdf(double x, double mean, double stdev) Helper method to calculate the cumulative distribution function,cdf, of the Normal distribution.- Parameters:
x- the value for which to calculate thecdfmean- the mean valuestdev- the standard deviation- Returns:
cdfatx- See Also:
-
erf
private static double erf(double x) Numerical approximation of error functionerf(x)from Abramowitz & Stegun.Note: approximation requires
x≥0. Forx<0use thaterf(x)is odd function.- Parameters:
x- the function argument- Returns:
erf(x)
-