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

schmeis_cdf(xv,p_value)
% schmeis_cdf.m - Schmeiser-Deutsch Cumulative Distribution Function.
%   See "Random Variate Generation in One Line of Code", L. Devroye.
%
%   Created by: J. Huntley,  09/25/06
%
%   Vector form of CDF!!!
%

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

% Initializations.
lambda = p_value(1);
mu = p_value(2);
rand('state',0);
nsamples = size(xv,2);

% Evaluate PPF for evenly-spaced CDF values on [0,1].
xhold = rand(nsamples,1);
fhold = sign(xhold-lambda) .* (abs(xhold-lambda)).^mu;
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