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

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

function [pdf] = poisbinmix_pdf(n, phi, q, nn)

%persistent p logp logq

%if(isempty(p))
    p = 1 - q;
    logp = log(p);
    logq = log(q);
%end

sumj = 0;
for jj = 1:nn+1
    j = jj-1;
    %sumj = sumj + binomial_coef(nn,j) * p^j * q^(nn-j) * exp(-j*phi) * (j*phi)^n / factorial(n);
    sumj = sumj + exp(log(binomial_coef(nn,j)) + j*logp + (nn-j)*logq -  j*phi + n*log(j*phi+eps) - gammaln(n+1));
end
pdf = sumj;

return

Contact us