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

genlogser_pdf(n, b, p)
% genlogser_pdf.m - evaluates a Matching Probability Density.
%   See "Generating Non-Uniform Random Variates", Chap. 10, L. Devroye
%
%  Created by Jim Huntley,  9/7/06
%

function [pdf] = genlogser_pdf(n, b, p)

%persistent lomp lp

%if(isempty(lp))
    lp = log(p);
    lomp = log(1-p);
%end

%pdf = p^n * (1-p)^(b*n-n) * gamma(b*n) / (-n * log(1-p) * gamma(n) * gamma(b*n-n+1));
pdf = exp(n*lp + (b*n-n)*lomp + gammaln(b*n) - ...
    (log(-n*lomp) + gammaln(n) + gammaln(b*n-n+1)));

return

Contact us