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

poislog_pdf(n, lambda, phi)
% poislog_pdf.m - evaluates a Poisson Logarithmic Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, 2005, p.372.    
%
%  Created by Jim Huntley,  8/27/07
%

function [pdf] = poislog_pdf(n, lambda, phi)

%persistent coef lcoef arg larg logphi jmax

%if(isempty(coef))
    coef = (-1 / log(1-lambda));
    lcoef = log(coef);
    arg = lambda * exp(-phi);
    larg = log(arg);
    logphi = log(phi);
    jmax = min(10,40*phi/(1-lambda));
%end

if(n == 0)
    pdf = -coef * log(1-arg);
elseif(n == 1)
    pdf = coef * phi * arg / (1 - arg);
elseif(n > 1)
    sumj = 0;
    for j = 1:jmax
        sumj = sumj + exp((n-1)*log(j) + j*larg - gammaln(n+1));
    end
    pdf = exp(lcoef + n*logphi + log(sumj));
end

return

Contact us