Code covered by the BSD License  

Highlights from
Generation of Random Variates

image thumbnail

Generation of Random Variates

by

 

generates random variates from over 870 univariate distributions

clusize_pdf(n, w, k)
% clusize_pdf.m - evaluates a Cluster Size Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, p.238, 2005 & "Sundt and Jewell's Family of Discrete Distributions",
%   G. Willmot, Astin Bulletin, v.18, no.1, p.19, Apr, 1988.
%
%  Created by Jim Huntley,  12/05/06
%

function [pdf] = clusize_pdf(n, w, k)

%persistent logw glnkp1 t1

%if(isempty(logw))
    logw = log(w);
    glnkp1 = gammaln(k+1);
    t1 = log(1-(1-w)^(-k));
%end

%pdf = w^k * gamma(k+n) * (1-w)^n / (gamma(k+1) * factorial(n) * ((1-(1-w))^(-k) - 1));     % UDD expression (wrong)                                                                                  
%pdf = -k * gamma(k+n) * w^n / (gamma(k+1) * factorial(n) * (1-(1-w)^(-k)));
pdf = -k * exp(gammaln(k+n) + n*logw - (glnkp1 + gammaln(n+1) + t1));

return


Contact us