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

genneyman_pdf(n, alpha, bet, phi, lambda, nn)
% genneyman_pdf.m - evaluates a Generalized Neyman Type A Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, & Kotz,
%   J. Wiley, 2005, p.417.
%
%  Created by Jim Huntley,  7/23/07
%

function [pdf] = genneyman_pdf(n, alpha, bet, phi, lambda, nn)

%persistent Fj P0 P1 PP

%if(isempty(Fj))
    for j = 1:nn+2
        jj = j-1;
        Fj(j) = exp(j*log(phi) + gammaln(alpha+jj+1) + gammaln(alpha+bet) + log(genHyper(alpha+j,alpha+bet+j,-phi)) - ...
                 (gammaln(j)+gammaln(alpha)+gammaln(alpha+bet+j)));
    end
    P0 = exp(lambda*genHyper(alpha,alpha+bet,-phi)-lambda);
    P1 = lambda * Fj(1) * P0;
    PP(1:nn+2) = 0;
%end

pdf = P0;
if(n >= 1)
    pdf = P1;
end
if(n >= 2)
    for jn = 3:n+1
        PP(1) = P0;
        PP(2) = P1;
        sum1 = 0;
        for jt = 1:n
            sum1 =  sum1 + Fj(jt) * PP(n-jt+1);
        end
        if(PP(jn) <= 0)
            PP(jn) = lambda * sum1 / (n);
        end
        pdf =  PP(jn);
    end    
end

return

Contact us