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

impinshyp_pdf(n,N,k,D,p,pp)
% impinshyp_pdf.m - evaluates an Imperfect Inspection Hypergeometric Distribution.
%  "Univariate Discrete Distributions", Johnson, Kemp, and Kotz,
%  J. Wiley, 2005, p.300. 
%
%   Note that original distribution doesn't normalize properly.  To normalize,
%   set "bc" = 1 and multiply result by "coef".
%
%  Cretaed by:  J. Huntley, 06/18/07.
%

function [pdf] = impinshyp_pdf(n,N,k,D,p,pp)

%persistent ymin ymax bc coef

%if(isempty(ymin))
    ymin = max(0,k-N+D);
    ymax = min(k,D);
    %bc = binomial_coef(N,k);
    bc = 1;
    if(N < D)
        coef = 0;
    elseif(N == D)
        coef = 1;
    elseif(N == D+1)
        if(k <= D)
            coef = 0.5;
        else
            coef = 1;
        end
    else
        coef = 1/min(D+1,min(k+1,N-k+1));
    end
%end

sum1 = 0;
    for jy = ymin+1:ymax+1
        wmin = max(0,n-k+jy-1);
        wmax = ymax;
        for jw = wmin+1:wmax+1
           sum1 = sum1 + binomial_coef(jy-1,jw-1) * binomial_coef(k-jy+1,n-jw+1) * ...
                         p^(jw-1) * (1-p)^(jy-jw) * pp^(n-jw+1) * (1-pp)^(k-jy-n+jw);
        end
    end
pdf = coef * sum1 / bc;

return
    



Contact us