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

glostgame_pdf(n, p, j, a)
% glostgame_pdf.m - evaluates a Lost Game Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, & Kotz, 
%   J. Wiley, 2005, 504. 
%
%  Created by Jim Huntley,  7/09/07
%

function [pdf] = glostgame_pdf(n, p, j, a)

%persistent q logq loga logp

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

%pdf = gamma(2*n+a-2*j) * a * p^(a+n-j) * q^(n-j) / ...
%      (gamma(n+a-j+1) * gamma(n-j+1));
pdf = exp(gammaln(2*n+a-2*j) + loga + (a+n-j)*logp + (n-j)*logq - ...
      (gammaln(n+a-j+1) + gammaln(n-j+1)));
    
return

Contact us