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

poisbin2_pdf(n, lambda, q, nn, nmax)
% poisbin2_pdf.m - evaluates a Poisson Binomial 2 Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, 2005, p.401.    
%
%  Created by Jim Huntley,  8/20/07
%

function [pdf] = poisbin2_pdf(n, lambda, q, nn, nmax)

%persistent coef p P0 pdf_hold

%if(isempty(coef))
    P0 = exp(lambda*(q^nn-1));
    p = 1 - q;
    coef = nn * p * lambda;
    pdf_hold(1:nmax+1) = 0;
%end

if(n == 0) 
    pdf = P0;
    pdf_hold(1) = P0;
elseif(n > 0)
    sumj = 0;
    for jj = 1:n
        j = jj-1;
        sumj = sumj + binomial_coef(nn-1,j) * p^j * q^(nn-1-j) * pdf_hold(n-jj+1);
    end
    pdf = coef * sumj / n;
    pdf_hold(n+1) = pdf;
end

return

Contact us