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

expgam_pdf(x, a, mu, alpha, bet, lambda)
% expgam_pdf.m - evaluates Exponential Gamma Mix Probability Density.
%   See "On the Linear Combination of Exponential and Gamma Random Variables",
%   S. Nadarajah and S. Kotz, Entropy, vol.7, no.2, 2005, p.161.
%
%  Created by Jim Huntley,  01/03/08
%

function [pdf] = expgam_pdf(x, a, mu, alpha, bet, lambda)

%persistent mdb gama mal mala lb ldal albet malmlba arg cdf0

%if(isempty(mdb))
    mdb = mu / bet;
    gama = gammaln(a);
    mal = mu * alpha;
    mala = mal^a;
    lb = lambda * bet;
    ldal = lambda / alpha;
    albet = alpha * bet;
    malmlba = (mal - lb)^a;
    arg = (mal-lb) / albet;
    cdf0 = mala/malmlba;
%end

if(bet >= 0)
    %pdf = lambda * mala * exp(-ldal*x) * gammainc(arg*x,a) / (malmlba * alpha * gama);
    pdf = exp(-ldal*x + log(eps + lambda * mala * gammainc(arg*x,a)) - log(malmlba) - log(alpha) - gama);
elseif(bet < 0)
    pdf = lambda * mala * exp(-ldal*x) / (malmlba * alpha * cdf0);
end

return

Contact us