## org.apache.commons.math.distribution
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:
  java.io.Serializable, DiscreteDistribution, Distribution, IntegerDistribution, ZipfDistribution

    public class ZipfDistributionImpl

extends AbstractIntegerDistribution
implements ZipfDistribution, java.io.Serializable

Implementation for the `ZipfDistribution`.

Version:
  $Revision: 920852 $ $Date: 2010-03-09 07:53:44 -0500 (Tue, 09 Mar 2010) $
See Also:
  Serialized Form

Field Summary
`private double` `exponent` Exponent parameter of the distribution.
`private int` `numberOfElements` Number of elements.
`private static long` `serialVersionUID` Serializable version identifier.

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

Method Summary
`double` `cumulativeProbability(int x)` The probability distribution function P(X <= x) for a Zipf distribution.
`private double` `generalizedHarmonic(int n, double m)` Calculates the Nth generalized harmonic number.
`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.
`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)
`private void` `setExponentInternal(double s)` Set the exponent characterising the distribution.
`void` `setNumberOfElements(int n)` Deprecated. as of 2.1 (class will become immutable in 3.0)
`private void` `setNumberOfElementsInternal(int n)` Set the number of elements (e.g.

Methods inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution
`cumulativeProbability, cumulativeProbability, cumulativeProbability, inverseCumulativeProbability, probability`

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`

Methods inherited from interface org.apache.commons.math.distribution.DiscreteDistribution
`probability`

Methods inherited from interface org.apache.commons.math.distribution.Distribution
`cumulativeProbability, cumulativeProbability`

Field Detail

### serialVersionUID

    private static final long serialVersionUID

  Serializable version identifier.

  See Also:
    Constant Field Values

### numberOfElements

    private int numberOfElements

  Number of elements.

### exponent

    private double exponent

  Exponent parameter of the distribution.

Constructor Detail

### ZipfDistributionImpl

    public ZipfDistributionImpl(int numberOfElements,
                                double exponent)
                         throws java.lang.IllegalArgumentException

  Create a new Zipf distribution with the given number of elements and exponent. Both values must be positive; otherwise an `IllegalArgumentException` is thrown.

  Parameters:
    `numberOfElements` - the number of elements
    `exponent` - the exponent
  Throws:
    `java.lang.IllegalArgumentException` - if n ≤ 0 or s ≤ 0.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

### setNumberOfElements

    @Deprecated
    public void setNumberOfElements(int n)

  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 an `IllegalArgumentException` is thrown.

  Specified by:
    `setNumberOfElements` in interface `ZipfDistribution`
  Parameters:
    `n` - the number of elements
  Throws:
    `java.lang.IllegalArgumentException` - if n ≤ 0

### setNumberOfElementsInternal

    private void setNumberOfElementsInternal(int n)
                                      throws java.lang.IllegalArgumentException

  Set the number of elements (e.g. corpus size) for the distribution. The parameter value must be positive; otherwise an `IllegalArgumentException` is thrown.

  Parameters:
    `n` - the number of elements
  Throws:
    `java.lang.IllegalArgumentException` - if n ≤ 0

### getExponent

    public double getExponent()

  Get the exponent characterising the distribution.

  Specified by:
    `getExponent` in interface `ZipfDistribution`
  Returns:
    the exponent

### setExponent

    @Deprecated
    public void setExponent(double s)

  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 an `IllegalArgumentException` is thrown.

  Specified by:
    `setExponent` in interface `ZipfDistribution`
  Parameters:
    `s` - the exponent
  Throws:
    `java.lang.IllegalArgumentException` - if s ≤ 0.0

### setExponentInternal

    private void setExponentInternal(double s)
                              throws java.lang.IllegalArgumentException

  Set the exponent characterising the distribution. The parameter value must be positive; otherwise an `IllegalArgumentException` is thrown.

  Parameters:
    `s` - the exponent
  Throws:
    `java.lang.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 interface `IntegerDistribution`
  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 <= x) for a Zipf distribution.

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

  Specified by:
    `getDomainLowerBound` in class `AbstractIntegerDistribution`
  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 on `p`, used to bracket a PDF root.

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

### generalizedHarmonic

    private double generalizedHarmonic(int n,
                                       double m)

  Calculates the Nth generalized harmonic number. See Harmonic Series.

  Parameters:
    `n` - the term in the series to calculate (must be ≥ 1)
    `m` - the exponent; special case m == 1.0 is the harmonic series
  Returns:
    the nth generalized harmonic number

Copyright (c) 2003-2011 Apache Software Foundation