Class GaussianRandomizer

java.lang.Object
com.irurueta.statistics.Randomizer
com.irurueta.statistics.GaussianRandomizer

public class GaussianRandomizer extends Randomizer
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 Details

    • DEFAULT_MEAN

      public static final double DEFAULT_MEAN
      Specifies 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_DEVIATION
      Specifies standard deviation to be used for random value generation if none is provided.
      See Also:
    • mean

      private double mean
      Contains mMean value to be used for random value generation.
    • standardDeviation

      private double standardDeviation
      Standard deviation value to be used for random value generation.
  • Constructor Details

    • GaussianRandomizer

      public GaussianRandomizer()
      Constructor. Uses default Random implementation.
    • GaussianRandomizer

      public GaussianRandomizer(double mean, double standardDeviation)
      Constructor. Uses default Random 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

      public GaussianRandomizer(Random internalRandom)
      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

      public GaussianRandomizer(Random internalRandom, double mean, double standardDeviation)
      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 class Randomizer
      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 class Randomizer
      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 class Randomizer
      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 class Randomizer
      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 class Randomizer
      Returns:
      Next random Gaussian double precision floating-point value.
    • getType

      public RandomizerType getType()
      Returns the randomizer type of this instance.
      Specified by:
      getType in class Randomizer
      Returns:
      Randomizer type.