Code covered by the BSD License

# Generation of Random Variates

### James Huntley (view profile)

generates random variates from over 870 univariate distributions

iplogser_pdf(n, ppi, rho)
```% iplogser_pdf.m - evaluates an Inflated Parameter Logarithmic Series 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] = iplogser_pdf(n, ppi, rho)

%persistent log1mpr logrho mlnppi lmlnppi pn

%Initializations.
%if(isempty(pn))
pn = 0;
ompr = (1-ppi) * (1-rho);
log1mpr = log(ompr);
logrho = log(rho);
mlnppi = -log(ppi);
lmlnppi = log(mlnppi);
%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 + factorial(sumx-1) * ompr^sumx * rho^sumdx / pfx / mlnppi;
sum1 = sum1 + exp(gammaln(sumx) + sumx*log1mpr + sumdx*logrho - pfx - lmlnppi);
end
pdf = sum1;

end % conditional for n > 0.

return

```