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

gurland_pdf(n, k, alpha, bet, theta)
% gurland_pdf.m - evaluates a Gurland H2 Probability denisity.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   Wiley, p.298, 2005.  
%
%   Created by  J. Huntley,  03/12/06.
%

function [pdf] = gurland_pdf(n, k, alpha, bet, theta)

%persistent apb lngamapb lngama

%if(isempty(apb))
    apb = alpha + bet;
    %gamapb = gamma(apb);
    %gama = gamma(alpha);
    lngamapb = gammaln(apb);
    lngama = gammaln(alpha);
%end

%pdf = max(real((binomial_coef(k+n-1,n) * theta^n * gamma(alpha+n) * gamapb * ...
%      hypergeom([k+n alpha+n],apb,-theta) / (gama * gamma(apb+n)))),0);

pdf = max(real(exp(log(binomial_coef(k+n-1,n)) + log(theta^n) + gammaln(alpha+n) + lngamapb + ...
      log(genHyper([k+n alpha+n],apb+n,-theta)) - (lngama + gammaln(apb+n)))),0);

return

    

Contact us