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

poishyper_pdf(n, N, Np, nn, phi)
% poishyper_pdf.m - evaluates a Poisson Hypergeometric Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, 2005, p.509.    
%
%  Created by Jim Huntley,  8/22/07
%

function [pdf] = poishyper_pdf(n, N, Np, nn, phi)

%persistent coef jmax jmin

%if(isempty(coef))
    coef = log(1 / binomial_coef(N,nn));
    jmin = max(0,nn+Np-N) + 1;
    jmax = min(Np,nn) + 1;
%end

sumj = 0;
for jj = jmin:jmax
    j = jj - 1;
    arg = j * phi;
    sumj = sumj + exp(-arg) * arg^n * binomial_coef(Np,j) * binomial_coef(N-Np,nn-j);
end
pdf = exp(coef + log(sumj) - gammaln(n+1));

return

Contact us