Code covered by the BSD License  

Highlights from
Generation of Random Variates

image thumbnail

Generation of Random Variates

by

 

generates random variates from over 870 univariate distributions

dlinnik_pdf(klim, gam, lambda, bet)
% test_dlinnik3_pdf.m - tests a Discrete Stable Probability Density.
%   See "Discrete Self-Decomposable Distributions", K. Schreiber Dissertation,
%   U. Magdeburg, 30 August, 1999.
%
%  Created by Jim Huntley,  8/08/06
%

function [pdf] = dlinnik_pdf(klim, gam, lambda, bet)

%persistent p llampbet llam

%if(isempty(p))
    p = bet / (lambda+bet);
    llampbet = log(lambda + bet);
    llam = log(lambda);
%end

for kk = 1:klim+1
    k = kk - 1;
    coef = (-1)^k * p^bet;
    sum1 = 0;
    for mm = 1:k+1
        m = mm - 1;
        for jj = 1:m+1
            j = jj - 1;
            bc1 = binomial_coef(m,j);
            prod1 = 1;
            prod2 = 1;            
            for jm = 1:m
                prod1 = prod1 * (bet+jm-1);
            end
            for jk = 1:k
                prod2 = prod2 * (gam*j-jk+1);
            end
            %sum1 = sum1 + (-1)^j * lambda^m * bc1 * prod1 * prod2 / ...
            %      (factorial(k)*factorial(m)*(lambda+bet)^m);
            sum1 = sum1 + (-1)^j * exp(m*llam + log(bc1 * prod1 * prod2 + 1e-8) - ...
                  (gammaln(k+1) + gammaln(m+1) + m*llampbet));  
            yy(k+1) = coef * sum1;
        end
    end       
end

pdf = yy(end);

return

Contact us