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
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
Modifier and TypeFieldDescriptionAn EnhancedRandom generator from this library to use. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract Distribution
copy()
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
getMean()
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[]
getMode()
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
getTag()
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.stringDeserialize
(String data) Given a String in the format produced bystringSerialize()
, 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 bystringSerialize(Base)
, and the sameBase
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 bystringDeserialize(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 bystringDeserialize(String)
to load this Distribution at another time.toString()
void
Needs the type ofgenerator
registered.
-
Field Details
-
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 Ab
- will be used to set parameter Bc
- 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
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" insetParameters(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 returningDouble.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" insetParameters(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 returningDouble.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" insetParameters(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 returningDouble.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
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
Serializes the current state of this Distribution to a String that can be used bystringDeserialize(String)
to load this state at another time. This always usesBase.BASE16
for its conversions.- Returns:
- a String storing all data from the Distribution part of this generator
-
stringSerialize
Serializes the current generator and parameters of this Distribution to a String that can be used bystringDeserialize(String)
to load this Distribution at another time.- Parameters:
base
- which Base to use, from the "digital" library, such asBase.BASE10
- Returns:
- a String storing the current generator and parameters of this Distribution
-
stringDeserialize
Given a String in the format produced bystringSerialize()
, 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 usesBase.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 bystringSerialize()
- Returns:
- this, after setting its state
-
stringDeserialize
Given a String in the format produced bystringSerialize(Base)
, and the sameBase
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 bystringSerialize(Base)
base
- which Base to use, from the "digital" library, such asBase.BASE10
- Returns:
- this, after setting its state
-
writeExternal
Needs the type ofgenerator
registered.- Specified by:
writeExternal
in interfaceExternalizable
- Parameters:
out
- the stream to write the object to- Throws:
IOException
- Includes any I/O exceptions that may occur
-
readExternal
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 interfaceExternalizable
- Parameters:
in
- the stream to read data from in order to restore the object- Throws:
IOException
- if I/O errors occurClassNotFoundException
- If the class for an object being restored cannot be found.
-
equals
-
toString
-