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

thomas_pdf(n, m, lambda)
% thomas_pdf.m - evaluates a Thomas Probability Density.
%   See "Quantitative Spatial Analysis", R. Reich & R. Davis, CSU, 2000, web.
%
%  Created by Jim Huntley,  4/8/05
%

function [pdf] = thomas_pdf(n, m, lambda)

%persistent expmm logm

%if(isempty(logm))
    expmm = exp(-m);
    logm = log(m);
%end

pdf = expmm;
if(n > 0)
    sum1 = 0;
    for jr = 1:n
        %sum1 = sum1 + m^jr * (jr*lambda)^(n-jr) * exp(-jr*lambda) * expmm / ...
        %             (factorial(jr) * factorial(n-jr));
        sum1 = sum1 + exp(jr*logm + (n-jr)*log(jr*lambda) - jr*lambda - m - ...
                     (gammaln(jr+1) + gammaln(n-jr+1)));
    end
    pdf = sum1;
 end

return

Contact us