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

poislgn_pdf(n, mu, sigma)
% poislgn_pdf.m - evaluates a Poisson Lognormal Probability Density.
%   See "Lognormal Distributions Theory and Applications", ed. E.L. Crow,  
%   K. Shimizu, p.195, Dekker, 1988. 
%
%   NOTE: ROUND-OFF ERRORS LIMIT 'SIGMA' ~< 3  AND 'NMAX' ~< 400 !!!
%
%  Created by Jim Huntley,  08/22/11
%

function [pdf] = poislgn_pdf(n, mu, sigma)

%persistent coef ymax ymin y nmax

%if(isempty(coef))
    nmax = min(400,sigma*140);          %heuristic        
    coef = 1 / (sigma*sqrt(2*pi));
    ymax = nmax;
    ymin = eps;
    ny = 1000;
    dy = (ymax-ymin) / (ny-1);
    y = ymin:dy:ymax;
%end

kern = @(y,mu,sigma)(exp(-y + (n-1).*log(y) - 0.5.*((log(y)-mu).^2)./sigma^2 - gammaln(n+1)));
I = quad(kern,ymin,ymax,1e-15,'',mu,sigma);
pdf = coef * I;

return

Contact us