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

cannibal_pdf(n, k, m)
% cannibal_pdf.m - evaluates a Cannibal Urn Probability Density.
%   "Analysis of Some Exactly Solvable Diminishing Urn Problems",
%   H-K. Hwang et al, Formal Power Series and Algeraic Combinatorics, Tainjin, 2007.
%
%  Created by Jim Huntley,  03/05/07
%

function [pdf] = cannibal_pdf(n, k, m)

%persistent mnfac

%if(isempty(mnfac))
    mnfac = gammaln(k+m);
%end

sumj = 0;
for jj = 1:n-k+1
    j = jj - 1;
    coef = (-1)^j;
    suml = 0;
    for ll = 1:min(m,j)+1
        l = ll - 1;
        suml = suml + (-1)^l * exp(log(binomial_coef(m,l)) + (m-l)*log(k+j) ...
               - gammaln(j-l+1));
    end
    sumj = sumj + coef * exp(log(suml) - gammaln(n-k-j+1));    
end
pdf = exp(gammaln(n) + log(abs(sumj)+1e-8) - mnfac);

return


Contact us