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

poisdlog_pdf(n, alpha, rho)
% poisdlog_pdf.m - evaluates a Poisson Discrete Logartihmic Probability Density.
%   See "Univariate Discrete Distributions", Johnson, Kemp, & Kotz, 
%   J. Wiley, 2005, 484. 
%
%   NOTE: Take care with the intergration parameters for alpha, rho > 2 !!!
%
%  Created by Jim Huntley,  9/05/07
%
%   Calls 'kern.m' listed below.
%

function [pdf] = poisdlog_pdf(n, alpha, rho)

%persistent coef rho2 thetamin thetamax nt tol trace dt theta

%if(isempty(coef))
    rho2 = rho^2;
    coef = 1 / sqrt(2*pi*rho2);
    thetamin = 1e-6;
    thetamax = 200;
    nt = 2000;
    tol = 1e-10;
    trace = [];
    dt = (thetamax-thetamin) / (nt-1);
    theta = thetamin:dt:thetamax;
%end

%kern = exp(-theta) .* theta.^n .* exp(-(log(theta)-alpha).^2./(2*rho2)) ./ ...
%      (factorial(n).*theta);
%pdf = coef *trapz(kern * dt;
pdf = coef * quad(@kern,thetamin,thetamax,tol,trace,alpha,rho2,n);
    
return

function [val] = kern(theta, alpha, rho2, n)

%val = exp(-theta) .* theta.^n .* exp(-(log(theta)-alpha).^2./(2*rho2)) ./ ...
%      (factorial(n).*theta);
val = exp(-theta + (n-1).*log(theta) - (log(theta)-alpha).^2./(2*rho2) - ...
      (gammaln(n+1)));
  
return

Contact us