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

binpois_pdf(n, p, m, M)
% binpois_pdf.m - evaluates a Binomial Poisson Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, p.333, 2005. 
%
%  Created by Jim Huntley,  11/28/06
%

function [pdf] = binpois_pdf(n, p, m, M)

%persistent q t1 

%if(isempty(q))
% Initializations.
    q = 1 - p;
    t1 = log(M*q^m);
%end

% Calculate PDF.
%pdf = exp(-M) * (M*q^m)^n * hypergeom([1-n -m*n],[],p/(M*q)) / factorial(n);
pdf = exp(-M + n*t1 + log(genHyper([1-n -m*n],[],p/(M*q))) - gammaln(n+1));

return


Contact us