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

poisbin_pdf(n, theta, q, nn)
% poisbin_pdf.m - evaluates a Poisson Binomial Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, 2005, p.333.    
%
%  Created by Jim Huntley,  8/17/07
%

function [pdf] = poisbin_pdf(n, theta, q, nn)

%persistent coef p P0 arg0

%if(isempty(coef))
    P0 = q^nn;
    p = 1 - q;
    coef = log(nn * p * q^(nn-1));
    arg0 = p / (theta*q);
%end

if(n == 0) 
    pdf = P0;
elseif(n > 0)
    arg = arg0 / n
    pdf = exp(coef + (n-1)*log(theta*n) - (theta*n) + ...
              log(genHyper([1-n 1-nn],[],arg)) - gammaln(n+1))    
end

return

Contact us