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

ferreri_pdf(x, a, b, c, mu)
% ferreri_pdf.m - compute Ferreri Probability Density Function.
%   See "Non-Uniform Random Deviates", L. Devroye, McGill, p. 482.
%   NOTE:  Need to use low value of 'ftol' to ensure a solution.
%
%   Vector Form of PDF.
%
%   Created by:     J. Huntley,  07/15/05
%

function[pdf] = ferreri_pdf(x, a, b, c, mu)

%persistent summax gamoh termlim rtb

%if(isempty(gamoh))
    summax = 100;
    gamoh = gamma(0.5);
    termlim = 1e-8;
    rtb = sqrt(b);
%end

for jx = 1:size(x,2)
    sum = 0;
    for js = 1:summax
        term = (-c)^(js-1) * exp(-js*a) / sqrt(js);
        if(js > 6)
            if((term/sum) < termlim)
                break
            end
        end
        sum = sum + term;
    end

    C = gamoh * sum;
    pdf(jx) = rtb / (C * (c + exp(a+b*(x(jx)-mu)^2)));
end

return

Contact us