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

poistnorm_pdf(n, mu, sigma, nn)
% poistnorm_pdf.m - evaluates a Poisson Truncated Normal Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%   J. Wiley, 2005, p.398.    
%
%  Created by Jim Huntley,  9/18/07
%
%  Calls: kern0, kern1 (located below).
%

function [pdf] = poistnorm_pdf(n, mu, sigma, nn)

%persistent coef ftol trace P0 I1 arg sig2 mumsig2 pdfhold

%if(isempty(coef))
    arg = sigma - mu/sigma;
    sig2 = sigma^2;
    mumsig2 = mu - sig2;
    tmax = 10;
    tmin = arg;
    tmin0 = -mu / sigma;
    ftol = 1e-8;
    trace = '';
    I1 = quad(@kern1,tmin,tmax,ftol,trace,arg); 
    I0 = quad(@kern0,tmin,tmax,ftol,trace);
    I00 = quad(@kern0,tmin0,tmax,ftol,trace); 
    coef = exp(0.5*sigma^2 - mu) / I00;
    P0 = coef * I0;
    pdfhold(1:nn+1) = 0;
    pdfhold(1) = P0;
    pdfhold(2) = coef * sigma * I1;
    for jn = 3:nn+1
        pdfhold(jn) = (mumsig2*pdfhold(jn-1) + sig2*pdfhold(jn-2)) / (jn-1);
    end
%end

pdf = pdfhold(n+1);

return


function [kern] = kern0(t) 

kern = exp(-0.5.*t.^2);

return


function [kern] = kern1(t,arg)

kern = (t-arg) .* exp(-0.5.*t.^2);

return

Contact us