NAME

Math::Random::Zipf - Generate Zipf-distributed random integers

SYNOPSIS

use Math::Random::Zipf;

my $zipf = Math::Random::Zipf->new($N, $exponent);

# generate random deviate based on system rand()
$rand = $zipf->rand();

# generated random deviate based on your own version of rand()
$rand = $zipf->rand(my_uniform_rng());

# get probability(x)
$prob = $zipf->pmf($x)

# get cumulative probability x <= X
$cdf = $zipf->cdf($X)

# get X given probability
$X = $zipf->inv_cdf(P);

DESCRIPTION

This module generates random integers k that follow the Zipf distribution,

P(k) = C / k^s

for k = [ 1, 2, .. N ], s a fixed exponent and C a normalisation constant. It is related to the Zeta distribution (infinite N) and Pareto distribution (continuous equivalent).

The samples are generated using the inverse transform method.

METHODS

new

$zipf = Math::Random::Zipf->new($N, $exponent);

Creates a new Math::Random::Zipf object using parameters $N (maximum integer) and $exponent ( 's' in P(k) = C / k^s ).

rand

$rand = $zipf->rand();
$rand = $zipf->rand(my_uniform_rng());

Returns a random deviate. Uses perl's built-in rand() by default, but may be supplied with samples from an alternative source of uniformly distributed numbers in the range [0,1].

pmf_ref, cmf_ref

$pmf = $zipf->pmf_ref();
$cdf = $zipf->cdf_ref();

Returns references to arrays of the probability mass and cumulative distribution functions respectively.

pmf, cmf

$p = $zipf->pmf($x)
$P = $zipf->cdf($x)

Returns probability and cumulative probability respectively of a specific integer value $x.

SEE ALSO

http://en.wikipedia.org/wiki/Zipf%27s_law

AUTHOR

Jon Schutz, <jon at jschutz.net> http://notes.jschutz.net/

BUGS

Please report any bugs or feature requests to bug-math-random-zipf at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Math-Random-Zipf. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Math::Random::Zipf

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2010 Jon Schutz, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.