Code covered by the BSD License  

Highlights from
Generation of Random Variates

image thumbnail

Generation of Random Variates

by

James Huntley (view profile)

 

generates random variates from over 870 univariate distributions

genpoisdif_pdf(n, theta1, theta2, lambda)
% genpoisdif_pdf.m - evaluates a Generalized Poisson Difference Probability Density.
%   See "Generalized Poisson Distributions", P. C. Consul, Dekker, 1989,p.74.  
%
%  Created by Jim Huntley,  11/03/08
%

function [pdf] = genpoisdif_pdf(n, theta1, theta2, lambda)

%persistent coef ylim

%if(isempty(coef))
    coef = exp(-theta1-theta2);
    ylim = 20;
%end

for jn = 1:size(n,2)
    sumy = 0;
    for jy = 1:ylim
        y = jy - 1;
        pdf1 = genpoiss(y+n,theta1,lambda);
        pdf2 = genpoiss(y,theta2,lambda);
        sumy = sumy + pdf1 * pdf2 * exp(-2*lambda*y);
    end
    pdf = coef * sumy * exp(-lambda*n);
end

function[pdf0] = genpoiss(n,theta,lambda)

pdf0 = 0;
if(n >= 0)
    pdf0 = theta * (n*lambda+theta)^(n-1);
    pdf0 = exp(log(pdf0) - gammaln(n+1));
end

return

Contact us