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

git8_pdf(n, nn, p, q)
% git8_pdf.m - evaluates an Generalized Inverse Trinomial 8 Probability Density.
%   See "A Generalization of the Inverse Trinomial", K. Aoyama and K. Shimizu, Keio U., 
%   23 June, 2005.
%
%  Created by Jim Huntley,  8/31/06
%

function [pdf] = git8_pdf(n, nn, p, q)

%persistent lnn lp lq lr r

%if(isempty(lnn))
    r = 1 - p - q;
    lnn = log(nn);
    lp = log(p);
    lq = log(q);
    lr = log(r);    
%end

sum1 = 0;
a = min(nn,n);

for ji = 1:a+1
    %sum1 = sum1 + nn * factorial(nn+n-ji+1) * p^(nn-ji+1) * q^(ji-1) * r^(n-ji+1) / ...
    %      (factorial(nn-ji+1) * factorial(n-ji+1) * factorial(ji-1) * (n+nn-ji+1));
    sum1 = sum1 + exp(lnn + gammaln(nn+n-ji+2) + (nn-ji+1)*lp + (ji-1)*lq + (n-ji+1)*lr - ...
           (gammaln(nn-ji+2) + gammaln(n-ji+2) + gammaln(ji) + log(n+nn-ji+1)));
end

pdf = sum1;

return

Contact us