Class Distribution

java.lang.Object
com.github.tommyettinger.random.distribution.Distribution
All Implemented Interfaces:
Externalizable, Serializable
Direct Known Subclasses:
ArcsineDistribution, BernoulliDistribution, BetaDistribution, BetaPrimeDistribution, BinomialDistribution, CauchyDistribution, ChiDistribution, ChiSquareDistribution, ContinuousUniformDistribution, DiscreteUniformDistribution, ErlangDistribution, ExponentialDistribution, FisherSnedecorDistribution, FisherTippettDistribution, GammaDistribution, GeometricDistribution, KnobDistribution, KumaraswamyDistribution, LaplaceDistribution, LogCauchyDistribution, LogisticDistribution, LogNormalDistribution, LumpDistribution, NormalDistribution, ParetoDistribution, PoissonDistribution, PowerDistribution, RayleighDistribution, StudentsTDistribution, TriangularDistribution, WeibullDistribution, ZipfianDistribution

public abstract class Distribution extends Object implements Externalizable
The parent (abstract) class for all distributions. This has up to three parameters (just called A, B, and C), which can be doubles or ints (by using a double and casting it to an int). It can provide the values for various properties of the distribution, such as minimum, maximum, and mean, calculated for the current parameters. You get distributed values from this with nextDouble().
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    An EnhancedRandom generator from this library to use.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract Distribution
    Returns an exact copy of this Distribution, with the same parameters and a copy of the generator.
    boolean
     
    abstract double
    Gets the maximum possible value of distributed random numbers.
    abstract double
    Gets the mean of distributed random numbers.
    abstract double
    Gets the median of distributed random numbers.
    abstract double
    Gets the minimum possible value of distributed random numbers.
    abstract double[]
    Gets the mode(s) of distributed random numbers.
    double
    Gets the value of parameter "A" as a double.
    double
    Gets the value of parameter "B" as a double.
    double
    Gets the value of parameter "C" as a double.
    abstract String
    Gets the tag used to identify this type of Distribution, as a String.
    abstract double
    Gets the variance of distributed random numbers.
    abstract double
    Generates a double using this distribution.
    void
    The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.
    abstract boolean
    setParameters(double a, double b, double c)
    Validates, and if all correct, sets up to 3 parameters to this distribution.
    Given a String in the format produced by stringSerialize(), this will attempt to set this Distribution object to match the state in the serialized data.
    stringDeserialize(String data, com.github.tommyettinger.digital.Base base)
    Given a String in the format produced by stringSerialize(Base), and the same Base used by the serialization, this will attempt to set this Distribution object to match the state in the serialized data.
    Serializes the current state of this Distribution to a String that can be used by stringDeserialize(String) to load this state at another time.
    stringSerialize(com.github.tommyettinger.digital.Base base)
    Serializes the current generator and parameters of this Distribution to a String that can be used by stringDeserialize(String) to load this Distribution at another time.
     
    void
    Needs the type of generator registered.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • generator

      public EnhancedRandom generator
      An EnhancedRandom generator from this library to use.
  • Constructor Details

    • Distribution

      public Distribution()
  • Method Details

    • getMaximum

      public abstract double getMaximum()
      Gets the maximum possible value of distributed random numbers.
      Returns:
      the maximum possible value of distributed random numbers
    • getMean

      public abstract double getMean()
      Gets the mean of distributed random numbers.
      Returns:
      the mean of distributed random numbers
    • getMedian

      public abstract double getMedian()
      Gets the median of distributed random numbers.
      Returns:
      the median of distributed random numbers
    • getMinimum

      public abstract double getMinimum()
      Gets the minimum possible value of distributed random numbers.
      Returns:
      the minimum possible value of distributed random numbers
    • getMode

      public abstract double[] getMode()
      Gets the mode(s) of distributed random numbers.
      Returns:
      the mode(s) of distributed random numbers
    • getVariance

      public abstract double getVariance()
      Gets the variance of distributed random numbers.
      Returns:
      the variance of distributed random numbers
    • setParameters

      public abstract boolean setParameters(double a, double b, double c)
      Validates, and if all correct, sets up to 3 parameters to this distribution. If this distribution has fewer than 3 parameters, later arguments are ignored.
      Parameters:
      a - will be used to set parameter A
      b - will be used to set parameter B
      c - will be used to set parameter C
      Returns:
      true if the parameters are valid and are used now; false if they were not changed
    • nextDouble

      public abstract double nextDouble()
      Generates a double using this distribution.
      Returns:
      a distributed double
    • getTag

      public abstract String getTag()
      Gets the tag used to identify this type of Distribution, as a String. This tag should be unique. Unlike the tags for EnhancedRandom types, the names here can vary in length.
      Returns:
      a unique String identifier for this type of Distribution; must be non-null, can be any non-zero length
    • getParameterA

      public double getParameterA()
      Gets the value of parameter "A" as a double. This corresponds to parameter "A" in setParameters(double, double, double); it is usually called by some other name in the generator, and may not be stored as a double internally.
      This defaults to always returning Double.NaN, but any parameters a distribution actually uses should be overridden to return the actual parameter, which is almost certainly not going to be NaN. If a getParameter method returns NaN, you can generally safely assume that the parameter is not used by this distribution.
      Returns:
      the value of parameter "A" as a double.
    • getParameterB

      public double getParameterB()
      Gets the value of parameter "B" as a double. This corresponds to parameter "B" in setParameters(double, double, double); it is usually called by some other name in the generator, and may not be stored as a double internally.
      This defaults to always returning Double.NaN, but any parameters a distribution actually uses should be overridden to return the actual parameter, which is almost certainly not going to be NaN. If a getParameter method returns NaN, you can generally safely assume that the parameter is not used by this distribution.
      Returns:
      the value of parameter "B" as a double.
    • getParameterC

      public double getParameterC()
      Gets the value of parameter "C" as a double. This corresponds to parameter "C" in setParameters(double, double, double); it is usually called by some other name in the generator, and may not be stored as a double internally.
      This defaults to always returning Double.NaN, but any parameters a distribution actually uses should be overridden to return the actual parameter, which is almost certainly not going to be NaN. If a getParameter method returns NaN, you can generally safely assume that the parameter is not used by this distribution.
      Returns:
      the value of parameter "C" as a double.
    • copy

      public abstract Distribution copy()
      Returns an exact copy of this Distribution, with the same parameters and a copy of the generator.
      Returns:
      an exact copy of this Distribution
    • stringSerialize

      public String stringSerialize()
      Serializes the current state of this Distribution to a String that can be used by stringDeserialize(String) to load this state at another time. This always uses Base.BASE16 for its conversions.
      Returns:
      a String storing all data from the Distribution part of this generator
    • stringSerialize

      public String stringSerialize(com.github.tommyettinger.digital.Base base)
      Serializes the current generator and parameters of this Distribution to a String that can be used by stringDeserialize(String) to load this Distribution at another time.
      Parameters:
      base - which Base to use, from the "digital" library, such as Base.BASE10
      Returns:
      a String storing the current generator and parameters of this Distribution
    • stringDeserialize

      public Distribution stringDeserialize(String data)
      Given a String in the format produced by stringSerialize(), this will attempt to set this Distribution object to match the state in the serialized data. This only works if this Distribution is the same implementation that was serialized. Always uses Base.BASE16. Returns this Distribution, after possibly changing its parameters and generator. The implementation for the generator can change, so the reference also changes whenever this is called.
      Parameters:
      data - a String probably produced by stringSerialize()
      Returns:
      this, after setting its state
    • stringDeserialize

      public Distribution stringDeserialize(String data, com.github.tommyettinger.digital.Base base)
      Given a String in the format produced by stringSerialize(Base), and the same Base used by the serialization, this will attempt to set this Distribution object to match the state in the serialized data. This only works if this Distribution is the same implementation that was serialized, and also needs the Bases to be identical. Returns this Distribution, after possibly changing its parameters and generator. The implementation for the generator can change, so the reference also changes whenever this is called.
      Parameters:
      data - a String probably produced by stringSerialize(Base)
      base - which Base to use, from the "digital" library, such as Base.BASE10
      Returns:
      this, after setting its state
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Needs the type of generator registered.
      Specified by:
      writeExternal in interface Externalizable
      Parameters:
      out - the stream to write the object to
      Throws:
      IOException - Includes any I/O exceptions that may occur
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.
      Specified by:
      readExternal in interface Externalizable
      Parameters:
      in - the stream to read data from in order to restore the object
      Throws:
      IOException - if I/O errors occur
      ClassNotFoundException - If the class for an object being restored cannot be found.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object