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

modstev_pdf(n, b, c, s)
% modstev_pdf.m - evaluates an Modified Stevens Craig Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, p.443, 2005. 
%
%  Created by Jim Huntley,  10/04/07
%

function [pdf] = modstev_pdf(n, b, c, s)

%persistent coef

%if(isempty(coef))
   coef = gammaln(c+1) + gammaln(b+1) + gammaln(c*s-b+1) - gammaln(c*s+1);
%end

maxnu = max(fix(n-b/s),0);
sumnu = binomial_coef(s*n,b);
for nu = 1:maxnu
    sumnu = sumnu + (-1)^nu * binomial_coef(n,nu) * binomial_coef(s*(n-nu),b);
end
pdf = exp(coef + log(sumnu) - (gammaln(n+1)+gammaln(c-n+1)));

return


Contact us