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

tadikau_cdf(xv,p_value)
% tadikau_rnd.m - generates Tadikamalla-Johnson U Cumulative Distribution.
%   See "Random Variate Generation in One Line of Code", L. Devroye.
%
%   Created by: J. Huntley,  01/10/07
%
%   Vector form of CDF!!!
%

function [cdf,fhold] = tadikau_cdf(xv,p_value)

% Initializations.
lambda = p_value(1);
delta = p_value(2);
gam = p_value(3);
tsi = p_value(4);
rand('state',0);
nsamples = size(xv,2);

% Evaluate PPF for evenly-spaced CDF values on [0,1].
xhold = rand(nsamples,1);
Z = log(xhold./(1-xhold));
fhold = tsi + lambda.*sinh((Z-gam)./delta);
fmin = min(fhold);
fmax = max(fhold);

% Sort "range" values of PPF into "domain" order.
[xsort, index] = sort(xhold);
fsort = fhold(index);

% Interpolate CDF values to uniform spacing, xi.
xi = fmin:(fmax-fmin)/(nsamples-1):fmax;
cdf = interp1(fsort,xsort,xi,'linear');

return

Contact us