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

paspois_pdf(n, mu, a, c)
% paspois_pdf.m - evaluates a Pascal Poisson Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, 2005, p.244.    
%
%  Created by Jim Huntley,  8/15/07
%

function [pdf] = paspois_pdf(n, mu, a, c)

persistent coef P0 jmax term logc

if(isempty(coef))
    coef = (a*log(a*c/(a*c+mu)) - gammaln(a));
    P0 = (1 - mu*(exp(-c)-1)/(a*c))^(-a);
    jmax = fix(20 * (mu/c)^0.7);                % heuristic.
    term = log(mu/(a*c+mu));
    logc = log(c);
end

pdf = P0;
if(n > 0)
    sumj = 0;
    for j = 1:jmax
        %sumj = sumj + gamma(a+j) * (mu/(a*c+mu))^j * j^n * exp(-j*c) / gamma(j+1);
        sumj = sumj + exp(gammaln(a+j) + j*term + n*log(j) - j*c - gammaln(j+1));
    end
    %pdf = coef * c^n * sumj / gamma(n+1);
    pdf = exp(coef + n*logc + log(sumj) - gammaln(n+1));
end

return

Contact us