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

cascade_pdf(n, d, p, r)
% cascade_pdf.m - evaluates a Cascade Probability Density.
%   See "Dynamical and Probabilistic Approoaches to the Study of Blackout
%   Vulnerability of the Power Transmission Grid", B. A. Carreras et al., 
%   Hawaii Internaltional Conference on System Science, Jan., 2004.
%
%  Created by Jim Huntley,  7/24/06
%

function [pdf] = cascade_pdf(n, d, p, r)

if(n < r)
    arg1 = d;
    arg2 = 1 - n*p - d;
    coef = 1;
    if(arg1 < 0)
        phi1 = 0;
    elseif(arg1 >= 0 && arg1 <= 1)
        coef = binomial_coef(r,n) * (n*p + d) ^(n-1);
        phi1 = arg1;
    elseif(arg1 > 1)
        coef = binomial_coef(r,n) * (n*p + d) ^(n-1);
        phi1 = 1;
    end
    if(arg2 < 0)
        phi2 = 0;
    elseif(arg2 >= 0 && arg2 <= 1)
        coef = binomial_coef(r,n) * (n*p + d) ^(n-1);
        phi2 = arg2;
    elseif(arg2 > 1)
        coef = binomial_coef(r,n) * (n*p + d) ^(n-1);
        phi2 = 1;
    end
    pdf = coef * phi1 * phi2^(r-n);
elseif(n == r)
    sum1 = 0;
    for jn = 1:r
        arg1 = d;
        arg2 = 1 - (jn-1)*p - d;
        coef = 1;
        if(arg1 < 0)
            phi1 = 0;
        elseif(arg1 >= 0 && arg1 <= 1)
            coef = binomial_coef(r,jn-1) * ((jn-1)*p + d) ^(jn-2);
            phi1 = arg1;
        elseif(arg1 > 1)
            coef = binomial_coef(r,jn-1) * ((jn-1)*p + d) ^(jn-2);
            phi1 = 1;
        end
        if(arg2 < 0)
            phi2 = 0;
        elseif(arg2 >= 0 && arg2 <= 1)
            coef = binomial_coef(r,jn-1) * ((jn-1)*p + d) ^(jn-2);  
            phi2 = arg2;
        elseif(arg2 > 1)
            coef = binomial_coef(r,jn-1) * ((jn-1)*p + d) ^(jn-2);
            phi2 = 1;
        end
        sum1 = sum1 + coef * phi1 * phi2^(r-jn+1);
    end
    pdf = 1 - sum1;
end    

return

Contact us