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

poistgam_pdf(n, a, b, p, t)
% poistgam_pdf.m - evaluates a Poisson Truncated Gamma Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, 2005, p.369.    
%
%  Created by Jim Huntley,  9/11/07
%

function [pdf] = poistgam_pdf(n, a, b, p, t)

%persistent coef pt ap ptap lpt lptap 

%if(isempty(coef))
    pt = p * t;
    ap = a * p;
    ptap = pt + ap;
    %coef = ap^b / (gammainc(ap,b)*gamma(b));
    lpt = log(pt);
    lptap = log(ptap);
    coef = b*log(ap) - log(gammainc(ap,b)) - gammaln(b);
%end

bpn = b + n;
%pdf = coef * pt^n * gammainc(ptap,bpn) * gamma(bpn) / (ptap^bpn * gamma(n+1));
pdf = exp(coef + n*lpt + log(gammainc(ptap,bpn)) + gammaln(bpn) - ...
              (bpn*lptap + gammaln(n+1)));

return

Contact us