org.apache.commons.math.distribution
Class ZipfDistributionImpl

java.lang.Object
  extended by org.apache.commons.math.distribution.AbstractDistribution
      extended by org.apache.commons.math.distribution.AbstractIntegerDistribution
          extended by org.apache.commons.math.distribution.ZipfDistributionImpl
All Implemented Interfaces:
java.io.Serializable, DiscreteDistribution, Distribution, IntegerDistribution, ZipfDistribution

public class ZipfDistributionImpl
extends AbstractIntegerDistribution
implements ZipfDistribution, java.io.Serializable

Implementation for the ZipfDistribution.

Version:
$Id: ZipfDistributionImpl.java 1131229 2011-06-03 20:49:25Z luc $
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution
randomData
 
Constructor Summary
ZipfDistributionImpl(int numberOfElements, double exponent)
          Create a new Zipf distribution with the given number of elements and exponent.
 
Method Summary
protected  double calculateNumericalMean()
          Use this method to actually calculate the mean for the specific distribution.
protected  double calculateNumericalVariance()
          Use this method to actually calculate the variance for the specific distribution.
 double cumulativeProbability(int x)
          The probability distribution function P(X <= x) for a Zipf distribution.
protected  int getDomainLowerBound(double p)
          Access the domain value lower bound, based on p, used to bracket a PDF root.
protected  int getDomainUpperBound(double p)
          Access the domain value upper bound, based on p, used to bracket a PDF root.
 double getExponent()
          Get the exponent characterising the distribution.
 int getNumberOfElements()
          Get the number of elements (e.g. corpus size) for the distribution.
 int getSupportLowerBound()
          Access the lower bound of the support.
 int getSupportUpperBound()
          Access the upper bound of the support.
 double probability(int x)
          The probability mass function P(X = x) for a Zipf distribution.
 
Methods inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution
cumulativeProbability, cumulativeProbability, cumulativeProbability, inverseCumulativeProbability, isSupportLowerBoundInclusive, isSupportUpperBoundInclusive, probability, reseedRandomGenerator, sample, sample
 
Methods inherited from class org.apache.commons.math.distribution.AbstractDistribution
getNumericalMean, getNumericalVariance, isSupportConnected
 
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.IntegerDistribution
cumulativeProbability, inverseCumulativeProbability, reseedRandomGenerator, sample, sample
 
Methods inherited from interface org.apache.commons.math.distribution.DiscreteDistribution
probability
 
Methods inherited from interface org.apache.commons.math.distribution.Distribution
cumulativeProbability, cumulativeProbability, getNumericalMean, getNumericalVariance, isSupportConnected, isSupportLowerBoundInclusive, isSupportUpperBoundInclusive
 

Constructor Detail

ZipfDistributionImpl

public ZipfDistributionImpl(int numberOfElements,
                            double exponent)
Create a new Zipf distribution with the given number of elements and exponent.

Parameters:
numberOfElements - Number of elements.
exponent - Exponent.
Throws:
NotStrictlyPositiveException - if numberOfElements <= 0 or exponent <= 0.
Method Detail

getNumberOfElements

public int getNumberOfElements()
Get the number of elements (e.g. corpus size) for the distribution.

Specified by:
getNumberOfElements in interface ZipfDistribution
Returns:
the number of elements

getExponent

public double getExponent()
Get the exponent characterising the distribution.

Specified by:
getExponent in interface ZipfDistribution
Returns:
the exponent

probability

public double probability(int x)
The probability mass function P(X = x) for a Zipf distribution.

Specified by:
probability in interface IntegerDistribution
Parameters:
x - 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 <= x) for a Zipf distribution.

Specified by:
cumulativeProbability in interface IntegerDistribution
Specified by:
cumulativeProbability in class AbstractIntegerDistribution
Parameters:
x - 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 on p, used to bracket a PDF root.

Specified by:
getDomainLowerBound in class AbstractIntegerDistribution
Parameters:
p - Desired probability for the critical value.
Returns:
the domain value lower bound, i.e. P(X < 'lower bound') < p.

getDomainUpperBound

protected int getDomainUpperBound(double p)
Access the domain value upper bound, based on p, used to bracket a PDF root.

Specified by:
getDomainUpperBound in class AbstractIntegerDistribution
Parameters:
p - Desired probability for the critical value
Returns:
the domain value upper bound, i.e. P(X < 'upper bound') > p.

getSupportLowerBound

public int getSupportLowerBound()
Access the lower bound of the support. The lower bound of the support is always 1 no matter the parameters.

Specified by:
getSupportLowerBound in class AbstractIntegerDistribution
Returns:
lower bound of the support (always 1)

getSupportUpperBound

public int getSupportUpperBound()
Access the upper bound of the support. The upper bound of the support is the number of elements

Specified by:
getSupportUpperBound in class AbstractIntegerDistribution
Returns:
upper bound of the support

calculateNumericalMean

protected double calculateNumericalMean()
Use this method to actually calculate the mean for the specific distribution. Use AbstractDistribution.getNumericalMean() (which implements caching) to actually get the mean. For number of elements N and exponent s, the mean is Hs1 / Hs where

Specified by:
calculateNumericalMean in class AbstractDistribution
Returns:
the mean or Double.NaN if it's not defined

calculateNumericalVariance

protected double calculateNumericalVariance()
Use this method to actually calculate the variance for the specific distribution. Use AbstractDistribution.getNumericalVariance() (which implements caching) to actually get the variance. For number of elements N and exponent s, the mean is (Hs2 / Hs) - (Hs1^2 / Hs^2) where

Specified by:
calculateNumericalVariance in class AbstractDistribution
Returns:
the variance or Double.NaN if it's not defined


Copyright © 2003-2011 The Apache Software Foundation. All Rights Reserved.