Math::Random::Zipf - Generate Zipf-distributed random integers
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);
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.
$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 = $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 = $zipf->pmf_ref(); $cdf = $zipf->cdf_ref();
Returns references to arrays of the probability mass and cumulative distribution functions respectively.
$p = $zipf->pmf($x) $P = $zipf->cdf($x)
Returns probability and cumulative probability respectively of a specific integer value $x.
http://en.wikipedia.org/wiki/Zipf%27s_law
Jon Schutz, <jon at jschutz.net> http://notes.jschutz.net/
<jon at jschutz.net>
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.
bug-math-random-zipf at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Math::Random::Zipf
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Math-Random-Zipf
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Math-Random-Zipf
CPAN Ratings
http://cpanratings.perl.org/d/Math-Random-Zipf
Search CPAN
http://search.cpan.org/dist/Math-Random-Zipf/
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.
To install Math::Random::Zipf, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::Random::Zipf
CPAN shell
perl -MCPAN -e shell install Math::Random::Zipf
For more information on module installation, please visit the detailed CPAN module installation guide.