Package com.irurueta.statistics
Class GaussianRandomizer
java.lang.Object
com.irurueta.statistics.Randomizer
com.irurueta.statistics.GaussianRandomizer
Generates pseudo-random values following a Gaussian distribution having
the specified mMean and standard deviation. By default, mMean is equal to
DEFAULT_MEAN and the standard deviation is equal to
DEFAULT_STANDARD_DEVIATION.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
Specifies mMean value to be used for random value generation if no mMean is provided.static final double
Specifies standard deviation to be used for random value generation if none is provided.private double
Contains mMean value to be used for random value generation.private double
Standard deviation value to be used for random value generation.Fields inherited from class com.irurueta.statistics.Randomizer
DEFAULT_RANDOMIZER_TYPE, USE_SECURE_RANDOM_BY_DEFAULT
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.GaussianRandomizer
(double mean, double standardDeviation) Constructor.GaussianRandomizer
(Random internalRandom) Constructor.GaussianRandomizer
(Random internalRandom, double mean, double standardDeviation) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
fill
(boolean[] array, double threshold) Fills provided array with random booleans where the probability of returning true is equal to obtaining a Gaussian value below the provided threshold, which is equal to erfc function.double
getMean()
Returns mMean value to be used for Gaussian random value generation.double
Returns standard deviation to be used for Gaussian random value generation.getType()
Returns the randomizer type of this instance.boolean
Returns next random boolean value.boolean
nextBoolean
(double threshold) Returns next random boolean value.boolean[]
nextBooleans
(int length, double threshold) Returns array of booleans having provided length and containing random boolean values.double
Returns next random Gaussian double precision floating-point value having provided mMean and standard deviation.float
Returns next random Gaussian floating-point value having provided mMean and standard deviation.int
nextInt()
Returns next random Gaussian integer value having provided mMean and standard deviation.long
nextLong()
Returns next random Gaussian long value having provided mMean and standard deviation.void
setMean
(double mean) Sets mMean value to be used for Gaussian random value generation.void
setStandardDeviation
(double standardDeviation) Sets standard deviation to be used for Gaussian random value generation.Methods inherited from class com.irurueta.statistics.Randomizer
create, create, create, create, create, create, fill, fill, fill, fill, fill, getInternalRandom, nextBooleans, nextDoubles, nextFloats, nextInts, nextLongs, setInternalRandom, setSeed
-
Field Details
-
DEFAULT_MEAN
public static final double DEFAULT_MEANSpecifies mMean value to be used for random value generation if no mMean is provided.- See Also:
-
DEFAULT_STANDARD_DEVIATION
public static final double DEFAULT_STANDARD_DEVIATIONSpecifies standard deviation to be used for random value generation if none is provided.- See Also:
-
mean
private double meanContains mMean value to be used for random value generation. -
standardDeviation
private double standardDeviationStandard deviation value to be used for random value generation.
-
-
Constructor Details
-
GaussianRandomizer
public GaussianRandomizer()Constructor. Uses defaultRandom
implementation. -
GaussianRandomizer
public GaussianRandomizer(double mean, double standardDeviation) Constructor. Uses defaultRandom
implementation.- Parameters:
mean
- Mean value of generated Gaussian values.standardDeviation
- Standard deviation of generated Gaussian values.- Throws:
IllegalArgumentException
- thrown if provided standard deviation is negative or zero.NullPointerException
- if provided internal Random instance is null.
-
GaussianRandomizer
Constructor. Because neither mMean nor standard deviation are provided, values DEFAULT_MEAN and DEFAULT_STANDARD_DEVIATION will be used instead.- Parameters:
internalRandom
- Internal Random instance in charge of generating pseudo-random values.- Throws:
NullPointerException
- thrown if provided internal random is null.
-
GaussianRandomizer
Constructor.- Parameters:
internalRandom
- Internal Random instance if charge of generating pseudo-random values.mean
- Mean value of generated Gaussian values.standardDeviation
- Standard deviation of generated Gaussian values.- Throws:
IllegalArgumentException
- thrown if provided standard deviation is negative or zero.NullPointerException
- if provided internal Random instance is null.
-
-
Method Details
-
getMean
public double getMean()Returns mMean value to be used for Gaussian random value generation.- Returns:
- Mean value.
-
setMean
public void setMean(double mean) Sets mMean value to be used for Gaussian random value generation.- Parameters:
mean
- Mean value.
-
getStandardDeviation
public double getStandardDeviation()Returns standard deviation to be used for Gaussian random value generation.- Returns:
- Standard deviation.
-
setStandardDeviation
public void setStandardDeviation(double standardDeviation) Sets standard deviation to be used for Gaussian random value generation.- Parameters:
standardDeviation
- Standard deviation.- Throws:
IllegalArgumentException
- exception thrown if provided standard deviation is negative or zero.
-
nextBoolean
public boolean nextBoolean()Returns next random boolean value. The probability of returning true is equal to obtaining a Gaussian value below the mMean, which is 50%.- Specified by:
nextBoolean
in classRandomizer
- Returns:
- Next boolean value.
-
nextBoolean
public boolean nextBoolean(double threshold) Returns next random boolean value. The probability of returning true is equal to obtaining a Gaussian value below the provided threshold, which is equal to erfc function.- Parameters:
threshold
- Threshold to determine whether returned values will be true or false.- Returns:
- Next random boolean value.
-
fill
public void fill(boolean[] array, double threshold) Fills provided array with random booleans where the probability of returning true is equal to obtaining a Gaussian value below the provided threshold, which is equal to erfc function.- Parameters:
array
- array to be filled.threshold
- Threshold to determine whether generated values will be true or false.
-
nextBooleans
public boolean[] nextBooleans(int length, double threshold) Returns array of booleans having provided length and containing random boolean values. The probability of returning true is equal to obtaining a Gaussian value below the provided threshold, which is equal to erfc function.- Parameters:
length
- Length of array to be created.threshold
- Threshold to determine whether returned values will be true or false.- Returns:
- Array of random booleans.
- Throws:
IllegalArgumentException
- if provided length is zero or negative.
-
nextInt
public int nextInt()Returns next random Gaussian integer value having provided mMean and standard deviation.- Specified by:
nextInt
in classRandomizer
- Returns:
- Next random Gaussian integer value.
-
nextLong
public long nextLong()Returns next random Gaussian long value having provided mMean and standard deviation.- Specified by:
nextLong
in classRandomizer
- Returns:
- Next random Gaussian long value.
-
nextFloat
public float nextFloat()Returns next random Gaussian floating-point value having provided mMean and standard deviation.- Specified by:
nextFloat
in classRandomizer
- Returns:
- Next random Gaussian floating-point value.
-
nextDouble
public double nextDouble()Returns next random Gaussian double precision floating-point value having provided mMean and standard deviation.- Specified by:
nextDouble
in classRandomizer
- Returns:
- Next random Gaussian double precision floating-point value.
-
getType
Returns the randomizer type of this instance.- Specified by:
getType
in classRandomizer
- Returns:
- Randomizer type.
-