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

pigam_pdf(n, mu, alpha)
% pigam_pdf.m - evaluates a Poisson Inverse Gamma Probability Density.
%   See "On recursive Evaluation of Mixed Poisson Probabilities and Related Quantities", 
%   Scand. Actuarial J., vol.2, p.114, 1993.
%
%  Created by Jim Huntley,  05/11/09
%

function [pdf] = pigam_pdf(n, mu, alpha)

%persistent p0 p1 pnm1 pnm2 rtmu

%if(isempty(p0))
    rtmu = sqrt(mu);
    p0 = 2 * mu^(alpha/2) * besselk(-alpha,2*rtmu) / gamma(alpha);
    p1 = 2 * mu^((1+alpha)/2) * besselk(1-alpha,2*rtmu) / gamma(alpha);
    pnm1 = p1;
    pnm2 = p0;   
%end

if(n == 0)
    pdf = p0;
elseif(n == 1)
    pdf = p1;
elseif(n > 1)
    c1 = (n-1-alpha) / n;
    c2 = mu  / ((n-1)*n);
    pdf = c1 * pnm1 + c2 * pnm2;
    pnm2 = pnm1;
    pnm1 = pdf;
end

return

Contact us