Code covered by the BSD License

# Generation of Random Variates

### James Huntley (view profile)

generates random variates from over 870 univariate distributions

ippois_pdf(n, lambda, rho)
```% ippois_pdf.m - evaluates an Inflated Parameter Poisson Probability denisity.
%   See "Inflated-Parameter Family of Generalized Power Series Distributions
%   and their Application in Analysis of Overdispersed Insurance Data",
%   N. Kolev et al. ARCH 00V211.PDF
%
%  Created by Jim Huntley,  10/27/09
%
%

function [pdf] = ippois_pdf(n, lambda, rho)

%persistent loglam1mr logrho pn

%Initializations.
%if(isempty(pn))
pn = exp(-lambda);
loglam1mr = log(lambda*(1-rho));
logrho = log(rho);
%end

% Evaluate PDF.
if(n == 0)
pdf = pn;

elseif(n > 0)
% Fetch pre-stored partitions of 'n'. Frequencies returned in array, "d".
pname = ['partition' num2str(n)];
spc = size(d,2);
d = double(d);

% Calculate PDF.
% Sum over all partition frequencies to get solution to Diophantine Equation.
sum1 = 0;
d1 = size(d,1);
for jr = 1:d1
for jc = 1:spc
x(jc) = d(jr,jc);
dx(jc) = (jc-1) * x(jc);
%fx(jc) = factorial(x(jc));
fx(jc) = gammaln(x(jc)+1);
end
sumx = sum(x);
sumdx = sum(dx);
%pfx = prod(fx);
pfx = sum(fx);
%sum1 = sum1 + (lambda*(1-rho))^sumx * rho^sumdx / pfx;
sum1 = sum1 + exp(sumx*loglam1mr + sumdx*logrho - pfx);
end
pdf = pn * sum1;

end % conditional for n > 0.

return

```