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

compnorm_pdf(x, phi, sigma, theta, p)
% compnorm_pdf.m - evaluatess a Compound Normal Probability Density.
%   See "Continuous Univariate Distributions", Vol.2, Johnson, Kotz, and Balakrishnan,   
%   J. Wiley, 1995, p.193.  
%
%  Created by Jim Huntley,  10/07/08
%

function[pdf] = compnorm_pdf(x, phi, sigma, theta, p)

%persistent t1 coef

%if(isempty(t1))
    t1 = sqrt(0.5*pi);
    coef = exp(0.5*sigma^2/phi^2) / (phi*sqrt(2*pi));
%end

dif = (x - theta);
dds = dif ./ sigma;
S1 = sigma/phi - dds;
S2 = sigma/phi + dds;
arg0 = dif ./ phi;
arg1 = -0.5.*S1.^2;
arg2 = -0.5.*S2.^2;
for jx = 1:size(x,2)
    h1(jx) = genHyper(0.5,1.5,arg1(jx));
    h2(jx) = genHyper(0.5,1.5,arg2(jx));
end
pdf = coef .* (p.*exp(-arg0).*(t1-S1.*h1(0.5,1.5,arg1)) + ...
               (1-p).*exp(arg0).*(t1-S2.*genHyper(0.5,1.5,arg2)));

return



Contact us