Class ZipfianDistribution
java.lang.Object
com.github.tommyettinger.random.distribution.Distribution
com.github.tommyettinger.random.distribution.ZipfianDistribution
A discrete two-parameter distribution with range from integer 1 to
This gets some formulas from dirtyzipf, which is MIT-licensed. It doesn't share any code. See Wikipedia's page on the Zipfian distribution.
alpha
.
This gets some formulas from dirtyzipf, which is MIT-licensed. It doesn't share any code. See Wikipedia's page on the Zipfian distribution.
-
Field Summary
Fields inherited from class com.github.tommyettinger.random.distribution.Distribution
generator
-
Constructor Summary
ConstructorDescriptionUses anAceRandom
, alpha = 16, skew = 0.5 .ZipfianDistribution
(long alpha, double skew) Uses anAceRandom
and the given alpha and skew.ZipfianDistribution
(EnhancedRandom generator, long alpha, double skew) Uses the given EnhancedRandom directly.ZipfianDistribution
(EnhancedRandom generator, long alpha, double skew, double zeta) Uses the given EnhancedRandom directly. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Returns an exact copy of this Distribution, with the same parameters and a copy of the generator.double
getAlpha()
double
Gets the maximum possible value of distributed random numbers.double
getMean()
Gets the mean of distributed random numbers.double
Gets the median of distributed random numbers.double
Gets the minimum possible value of distributed random numbers.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
getSkew()
getTag()
Gets the tag used to identify this type of Distribution, as a String.double
Gets the variance of distributed random numbers.double
getZeta()
static double
harmonic
(long limit, double skew) Gets the nth generalized harmonic number (with n equal to limit) with the given s (as skew).double
Generates a double using this distribution.static double
sample
(EnhancedRandom generator, double alpha, double skew, double zeta, double zetaTwoSkew) static double
sample
(EnhancedRandom generator, long alpha, double skew, double zeta) boolean
setParameters
(double a, double b, double c) Sets all parameters and returns true if they are valid, otherwise leaves parameters unchanged and returns false.void
setZeta
(double zeta) Methods inherited from class com.github.tommyettinger.random.distribution.Distribution
equals, getParameterC, stringDeserialize, stringDeserialize, stringSerialize, stringSerialize, toString
-
Constructor Details
-
ZipfianDistribution
public ZipfianDistribution()Uses anAceRandom
, alpha = 16, skew = 0.5 . -
ZipfianDistribution
public ZipfianDistribution(long alpha, double skew) Uses anAceRandom
and the given alpha and skew. -
ZipfianDistribution
Uses the given EnhancedRandom directly. Uses the given alpha and skew. -
ZipfianDistribution
Uses the given EnhancedRandom directly. Uses the given alpha, skew, and precalculated zeta. Because this does not calculate zeta directly, it may be faster if you already knowgetZeta()
.
-
-
Method Details
-
getTag
Description copied from class:Distribution
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.- Specified by:
getTag
in classDistribution
- Returns:
- a unique String identifier for this type of Distribution; must be non-null, can be any non-zero length
-
copy
Description copied from class:Distribution
Returns an exact copy of this Distribution, with the same parameters and a copy of the generator.- Specified by:
copy
in classDistribution
- Returns:
- an exact copy of this Distribution
-
getAlpha
public double getAlpha() -
getSkew
public double getSkew() -
getZeta
public double getZeta() -
setZeta
public void setZeta(double zeta) -
getParameterA
public double getParameterA()Description copied from class:Distribution
Gets the value of parameter "A" as a double. This corresponds to parameter "A" inDistribution.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 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.- Overrides:
getParameterA
in classDistribution
- Returns:
- the value of parameter "A" as a double.
-
getParameterB
public double getParameterB()Description copied from class:Distribution
Gets the value of parameter "B" as a double. This corresponds to parameter "B" inDistribution.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 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.- Overrides:
getParameterB
in classDistribution
- Returns:
- the value of parameter "B" as a double.
-
harmonic
public static double harmonic(long limit, double skew) Gets the nth generalized harmonic number (with n equal to limit) with the given s (as skew). See Harmonic numbers on Wikipedia.- Parameters:
limit
- N in the formula (a long), or how many values are in the sequence this processesskew
- s in the formula (a non-negative double), or how skewed this is away from Zipf's Law- Returns:
- the Nth generalized harmonic number with the given skew, where N equals limit
-
getMaximum
public double getMaximum()Description copied from class:Distribution
Gets the maximum possible value of distributed random numbers.- Specified by:
getMaximum
in classDistribution
- Returns:
- the maximum possible value of distributed random numbers
-
getMean
public double getMean()Description copied from class:Distribution
Gets the mean of distributed random numbers.- Specified by:
getMean
in classDistribution
- Returns:
- the mean of distributed random numbers
-
getMedian
public double getMedian()Description copied from class:Distribution
Gets the median of distributed random numbers.- Specified by:
getMedian
in classDistribution
- Returns:
- the median of distributed random numbers
-
getMinimum
public double getMinimum()Description copied from class:Distribution
Gets the minimum possible value of distributed random numbers.- Specified by:
getMinimum
in classDistribution
- Returns:
- the minimum possible value of distributed random numbers
-
getMode
public double[] getMode()Description copied from class:Distribution
Gets the mode(s) of distributed random numbers.- Specified by:
getMode
in classDistribution
- Returns:
- the mode(s) of distributed random numbers
-
getVariance
public double getVariance()Description copied from class:Distribution
Gets the variance of distributed random numbers.- Specified by:
getVariance
in classDistribution
- Returns:
- the variance of distributed random numbers
-
setParameters
public boolean setParameters(double a, double b, double c) Sets all parameters and returns true if they are valid, otherwise leaves parameters unchanged and returns false. Note, if you pass a negative value forc
, you must callsetZeta(double)
and provide a value for zeta before you generate any doubles. Typically, whena
is very large, zeta takes a long time to process, so you might want to calculate it once, store the result ofgetZeta()
, and set it on later runs after passing a negativec
here.- Specified by:
setParameters
in classDistribution
- Parameters:
a
- alpha; should be an int or long greater than 0b
- skew; should be greater than or equal to 0.0 and less than 1.0c
- if negative, the (challenging) zeta value will not be calculated here; otherwise ignored- Returns:
- true if the parameters given are valid and will be used
-
nextDouble
public double nextDouble()Description copied from class:Distribution
Generates a double using this distribution.- Specified by:
nextDouble
in classDistribution
- Returns:
- a distributed double
-
sample
public static double sample(EnhancedRandom generator, double alpha, double skew, double zeta, double zetaTwoSkew) -
sample
-