Class ZipfDistributionImpl
java.lang.Object
org.apache.commons.math.distribution.AbstractDistribution
org.apache.commons.math.distribution.AbstractIntegerDistribution
org.apache.commons.math.distribution.ZipfDistributionImpl
- All Implemented Interfaces:
Serializable
,DiscreteDistribution
,Distribution
,IntegerDistribution
,ZipfDistribution
public class ZipfDistributionImpl
extends AbstractIntegerDistribution
implements ZipfDistribution, Serializable
Implementation for the
ZipfDistribution
.- Version:
- $Revision: 1054524 $ $Date: 2011-01-03 05:59:18 +0100 (lun. 03 janv. 2011) $
- See Also:
-
Field Summary
Fields inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution
randomData
-
Constructor Summary
ConstructorsConstructorDescriptionZipfDistributionImpl
(int numberOfElements, double exponent) Create a new Zipf distribution with the given number of elements and exponent. -
Method Summary
Modifier and TypeMethodDescriptiondouble
cumulativeProbability
(int x) The probability distribution function P(X invalid input: '<'= x) for a Zipf distribution.protected int
getDomainLowerBound
(double p) Access the domain value lower bound, based onp
, used to bracket a PDF root.protected int
getDomainUpperBound
(double p) Access the domain value upper bound, based onp
, used to bracket a PDF root.double
Get the exponent characterising the distribution.int
Get the number of elements (e.g.protected double
Returns the mean.protected double
Returns the variance.int
Returns the lower bound of the support for the distribution.int
Returns the upper bound of the support for the distribution.double
probability
(int x) The probability mass function P(X = x) for a Zipf distribution.void
setExponent
(double s) Deprecated.as of 2.1 (class will become immutable in 3.0)void
setNumberOfElements
(int n) Deprecated.as of 2.1 (class will become immutable in 3.0)Methods inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution
cumulativeProbability, cumulativeProbability, cumulativeProbability, inverseCumulativeProbability, isSupportLowerBoundInclusive, isSupportUpperBoundInclusive, probability, reseedRandomGenerator, sample, sample
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.commons.math.distribution.DiscreteDistribution
probability
Methods inherited from interface org.apache.commons.math.distribution.Distribution
cumulativeProbability, cumulativeProbability
Methods inherited from interface org.apache.commons.math.distribution.IntegerDistribution
cumulativeProbability, inverseCumulativeProbability
-
Constructor Details
-
ZipfDistributionImpl
Create a new Zipf distribution with the given number of elements and exponent. Both values must be positive; otherwise anIllegalArgumentException
is thrown.- Parameters:
numberOfElements
- the number of elementsexponent
- the exponent- Throws:
IllegalArgumentException
- if n ≤ 0 or s ≤ 0.0
-
-
Method Details
-
getNumberOfElements
public int getNumberOfElements()Get the number of elements (e.g. corpus size) for the distribution.- Specified by:
getNumberOfElements
in interfaceZipfDistribution
- Returns:
- the number of elements
-
setNumberOfElements
Deprecated.as of 2.1 (class will become immutable in 3.0)Set the number of elements (e.g. corpus size) for the distribution. The parameter value must be positive; otherwise anIllegalArgumentException
is thrown.- Specified by:
setNumberOfElements
in interfaceZipfDistribution
- Parameters:
n
- the number of elements- Throws:
IllegalArgumentException
- if n ≤ 0
-
getExponent
public double getExponent()Get the exponent characterising the distribution.- Specified by:
getExponent
in interfaceZipfDistribution
- Returns:
- the exponent
-
setExponent
Deprecated.as of 2.1 (class will become immutable in 3.0)Set the exponent characterising the distribution. The parameter value must be positive; otherwise anIllegalArgumentException
is thrown.- Specified by:
setExponent
in interfaceZipfDistribution
- Parameters:
s
- the exponent- Throws:
IllegalArgumentException
- if s ≤ 0.0
-
probability
public double probability(int x) The probability mass function P(X = x) for a Zipf distribution.- Specified by:
probability
in interfaceIntegerDistribution
- Parameters:
x
- the value at which the probability density function is evaluated.- Returns:
- the value of the probability mass function at x
-
cumulativeProbability
public double cumulativeProbability(int x) The probability distribution function P(X invalid input: '<'= x) for a Zipf distribution.- Specified by:
cumulativeProbability
in interfaceIntegerDistribution
- Specified by:
cumulativeProbability
in classAbstractIntegerDistribution
- Parameters:
x
- the value at which the PDF is evaluated.- Returns:
- Zipf distribution function evaluated at x
-
getDomainLowerBound
protected int getDomainLowerBound(double p) Access the domain value lower bound, based onp
, used to bracket a PDF root.- Specified by:
getDomainLowerBound
in classAbstractIntegerDistribution
- Parameters:
p
- the desired probability for the critical value- Returns:
- domain value lower bound, i.e.
P(X < lower bound) <
p
-
getDomainUpperBound
protected int getDomainUpperBound(double p) Access the domain value upper bound, based onp
, used to bracket a PDF root.- Specified by:
getDomainUpperBound
in classAbstractIntegerDistribution
- Parameters:
p
- the desired probability for the critical value- Returns:
- domain value upper bound, i.e.
P(X < upper bound) >
p
-
getSupportLowerBound
public int getSupportLowerBound()Returns the lower bound of the support for the distribution. The lower bound of the support is always 1 no matter the parameters.- Returns:
- lower bound of the support (always 1)
- Since:
- 2.2
-
getSupportUpperBound
public int getSupportUpperBound()Returns the upper bound of the support for the distribution. The upper bound of the support is the number of elements- Returns:
- upper bound of the support
- Since:
- 2.2
-
getNumericalMean
protected double getNumericalMean()Returns the mean. For number of elements N and exponent s, the mean isHs1 / Hs
whereHs1 = generalizedHarmonic(N, s - 1)
Hs = generalizedHarmonic(N, s)
- Returns:
- the mean
- Since:
- 2.2
-
getNumericalVariance
protected double getNumericalVariance()Returns the variance. For number of elements N and exponent s, the mean is(Hs2 / Hs) - (Hs1^2 / Hs^2)
whereHs2 = generalizedHarmonic(N, s - 2)
Hs1 = generalizedHarmonic(N, s - 1)
Hs = generalizedHarmonic(N, s)
- Returns:
- the variance
- Since:
- 2.2
-