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

hofmann_pdf(n, a, p, c, t)
% hofmann_pdf.m - evaluates a Hofmann Probability Density.
%   See "The Practical replacement of a Bonus-Malus System", 
%   J. F. Walhin and J. Paris, U. de Louvain, ASTIN Bull., Vol.31, No.2, 2001, p.317.
%
%  Created by Jim Huntley,  5/31/07
%

function [pdf] = hofmann_pdf(n, a, p, c, t)

%persistent theta lnga lnterm coef

%if(isempty(theta))
    if(a == 1) 
        theta = p * log(1+c*t) / c;
    else
        theta = p * ((1+c*t)^(1-a) - 1) / (c*(1-a));
    end
    %ga = gamma(a);
    lnga = gammaln(a);
    lnterm = log(c*t/(1+c*t));
    coef = p*t/((1+c*t)^a);
%end

pa(1) = exp(-theta);
for jn = 1:n
    sum1 = 0;
    for js = 1:jn
        %sum1 = sum1 + gamma(a+js-1) * (c*t/(1+c*t))^(js-1) * pa(jn-js+1) / ...
        %         (ga*factorial(js-1));
        sum1 = sum1 + exp(gammaln(a+js-1) + (js-1)*lnterm + log(pa(jn-js+1)) - ...
                      (lnga + gammaln(js)));      
    end
    pa(jn+1) =  coef * sum1 / jn;    
end
if(n == 0) 
    pdf = pa(1);
elseif(n > 0)
    pdf = pa(jn+1);
end

return

Contact us