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 double
The mean of the Normal distribution.private double
The standard deviation of the Normal distribution.Fields inherited from class RNGDistribution
rng, seed, seedSet, testSamples
-
Constructor Summary
ConstructorsConstructorDescriptionNormal()
Creates a standard Normal distribution withmean==0
and standard deviationstdev==1
using and a new instance ofMersenneTwister
.Normal
(double mean, double stdev) Creates Normal distribution withmean
and standard deviationstdev
using and a new instance ofMersenneTwister
.Normal
(MersenneTwister rng, double mean, double stdev) Creates Normal distribution withmean
and standard deviationstdev
using the random number generatorrng
. -
Method Summary
Modifier and TypeMethodDescriptionprivate static double
cdf
(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 double
erf
(double x) Numerical approximation of error functionerf(x)
from Abramowitz & Stegun.double
getMean()
Get the mean of the Normal distribution.double
getStdev()
Get the standard deviation of the Normal distribution.double
next()
Generate a normally distributed random number withmean
and standard deviationstdev
.static double
next
(MersenneTwister rng, double mean, double stdev) Normally distributed random number withmean
and standard deviationstdev
using random number generatorrng
.static void
test
(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==0
and standard deviationstdev==1
using and a new instance ofMersenneTwister
. -
Normal
public Normal(double mean, double stdev) Creates Normal distribution withmean
and standard deviationstdev
using and a new instance ofMersenneTwister
.- Parameters:
mean
- of Normal distributionstdev
- of Normal distribution
-
Normal
Creates Normal distribution withmean
and standard deviationstdev
using 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 withmean
and standard deviationstdev
.- Returns:
- the Normally distributed random number
-
clone
Description copied from class:RNGDistribution
Clone this RNGDistribution to ensure both objects return identical sequences of random numbers.IMPORTANT:
- Specified by:
clone
in classRNGDistribution
- Returns:
- clone of RNGDistribution
-
next
Normally distributed random number withmean
and standard deviationstdev
using 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 thecdf
mean
- the mean valuestdev
- the standard deviation- Returns:
cdf
atx
- See Also:
-
erf
private static double erf(double x) Numerical approximation of error functionerf(x)
from Abramowitz & Stegun.Note: approximation requires
x≥0
. Forx<0
use thaterf(x)
is odd function.- Parameters:
x
- the function argument- Returns:
erf(x)
-