This is the cl-randist Reference Manual, version 0.4.2, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Sep 15 04:22:52 2024 GMT+0.
cl-randist/cl-randist.asd
cl-randist/packages.lisp
cl-randist/jmt.lisp
cl-randist/randist.lisp
cl-randist/normal.lisp
cl-randist/gamma.lisp
cl-randist/dirichlet.lisp
cl-randist/beta.lisp
cl-randist/binomial.lisp
cl-randist/poisson.lisp
cl-randist/nbinomial.lisp
cl-randist/multinomial.lisp
cl-randist/alias_method.lisp
cl-randist/exponential.lisp
cl-randist/f.lisp
cl-randist/pareto.lisp
cl-randist/chisq.lisp
cl-randist/t.lisp
cl-randist/cut-point.lisp
cl-randist/desc-stat.lisp
cl-randist/GIG.lisp
cl-randist/tests.lisp
The main system appears first, followed by any subsystem dependency.
cl-randist
Random Distribution Generation
Leonardo Varuzza <varuzza@gmail.com>
BSD except the optional jmt.lisp file
0.4.2
packages.lisp
(file).
jmt.lisp
(file).
randist.lisp
(file).
normal.lisp
(file).
gamma.lisp
(file).
dirichlet.lisp
(file).
beta.lisp
(file).
binomial.lisp
(file).
poisson.lisp
(file).
nbinomial.lisp
(file).
multinomial.lisp
(file).
alias_method.lisp
(file).
exponential.lisp
(file).
f.lisp
(file).
pareto.lisp
(file).
chisq.lisp
(file).
t.lisp
(file).
cut-point.lisp
(file).
desc-stat.lisp
(file).
gig.lisp
(file).
tests.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
cl-randist/cl-randist.asd
cl-randist/packages.lisp
cl-randist/jmt.lisp
cl-randist/randist.lisp
cl-randist/normal.lisp
cl-randist/gamma.lisp
cl-randist/dirichlet.lisp
cl-randist/beta.lisp
cl-randist/binomial.lisp
cl-randist/poisson.lisp
cl-randist/nbinomial.lisp
cl-randist/multinomial.lisp
cl-randist/alias_method.lisp
cl-randist/exponential.lisp
cl-randist/f.lisp
cl-randist/pareto.lisp
cl-randist/chisq.lisp
cl-randist/t.lisp
cl-randist/cut-point.lisp
cl-randist/desc-stat.lisp
cl-randist/GIG.lisp
cl-randist/tests.lisp
cl-randist/jmt.lisp
packages.lisp
(file).
cl-randist
(system).
*mt-random-state*
(special variable).
make-load-form
(method).
make-mt-random-state
(function).
print-object
(method).
random-mt
(function).
+mt-k-inverse-2^32f+
(constant).
+mt-k2^32+
(constant).
+mt-lower-mask+
(constant).
+mt-m+
(constant).
+mt-n+
(constant).
+mt-tempering-mask-b+
(constant).
+mt-tempering-mask-c+
(constant).
+mt-upper-mask+
(constant).
copy-mt-random-state
(function).
mt-genrand
(function).
mt-internal-make-random-state
(function).
mt-make-random-state-integer
(function).
mt-make-random-state-random
(function).
mt-random-state
(structure).
mt-random-state-arr
(reader).
(setf mt-random-state-arr)
(writer).
mt-random-state-mti
(reader).
(setf mt-random-state-mti)
(writer).
mt-random-state-p
(function).
mt-refill
(function).
mt-tempering-shift-l
(function).
mt-tempering-shift-s
(function).
mt-tempering-shift-t
(function).
mt-tempering-shift-u
(function).
cl-randist/randist.lisp
jmt.lisp
(file).
cl-randist
(system).
random-bernoulli
(function).
random-uniform
(function).
random-pos
(function).
random-uniform-jmt
(function).
random-vector-iid
(function).
cl-randist/normal.lisp
randist.lisp
(file).
cl-randist
(system).
random-normal
(function).
random-normal-bivariate
(function).
random-normal-ziggurat
(function).
cl-randist/gamma.lisp
normal.lisp
(file).
cl-randist
(system).
random-gamma
(function).
random-gamma-int
(function).
random-gamma-mt
(function).
random-gamma1
(function).
+e+
(constant).
gamma-frac
(function).
gamma-large
(function).
cl-randist/dirichlet.lisp
gamma.lisp
(file).
cl-randist
(system).
random-dirichlet1
(function).
cl-randist/beta.lisp
dirichlet.lisp
(file).
cl-randist
(system).
random-beta
(function).
cl-randist/binomial.lisp
beta.lisp
(file).
cl-randist
(system).
random-binomial
(function).
cl-randist/poisson.lisp
binomial.lisp
(file).
cl-randist
(system).
random-poisson
(function).
cl-randist/nbinomial.lisp
poisson.lisp
(file).
cl-randist
(system).
random-negative-binomial
(function).
cl-randist/multinomial.lisp
nbinomial.lisp
(file).
cl-randist
(system).
random-multinomial
(function).
random-multinomial%
(function).
convert-to-double-float-vector
(function).
random-multinomial1
(function).
test-multinomial
(function).
test-multinomial1
(function).
cl-randist/alias_method.lisp
multinomial.lisp
(file).
cl-randist
(system).
make-discrete-random-var
(function).
create-alias-method-vectors
(function).
report-uniform-count
(function).
test-alias-method
(function).
test-alias-method-uniform
(function).
test-alias-method-zeros
(function).
uniform-reference
(function).
cl-randist/exponential.lisp
alias_method.lisp
(file).
cl-randist
(system).
random-exponential
(function).
cl-randist/f.lisp
exponential.lisp
(file).
cl-randist
(system).
random-f
(function).
cl-randist/pareto.lisp
f.lisp
(file).
cl-randist
(system).
random-pareto
(function).
cl-randist/chisq.lisp
pareto.lisp
(file).
cl-randist
(system).
random-chi-square
(function).
cl-randist/t.lisp
chisq.lisp
(file).
cl-randist
(system).
random-t
(function).
random-t-nu<=2
(function).
random-t-nu>2
(function).
cl-randist/cut-point.lisp
t.lisp
(file).
cl-randist
(system).
make-discrete-monotone-random-var
(function).
setup-cut-point-randist
(function).
cl-randist/desc-stat.lisp
cut-point.lisp
(file).
cl-randist
(system).
coefficient-of-variation
(function).
geometric-mean
(function).
mean
(function).
median
(function).
mode
(function).
percentile
(function).
range
(function).
sd
(macro).
square
(function).
standard-deviation
(function).
standard-error-of-the-mean
(function).
var
(macro).
variance
(function).
cl-randist/GIG.lisp
desc-stat.lisp
(file).
cl-randist
(system).
make-random-variable-gig
(function).
make-random-variable-gig-poisson
(function).
random-gig
(function).
random-gig-iid
(function).
%random-gig
(function).
gig-setup
(function).
random-generalized-inverse-poisson
(function).
test-gig-range
(function).
test-gig-speed
(function).
transfer-sign
(function).
zeroin
(function).
cl-randist/tests.lisp
gig.lisp
(file).
cl-randist
(system).
*n*
(special variable).
gen-uniform
(function).
genlist
(function).
profile-gamma
(function).
test-binomial
(function).
test-dist
(function).
test-gamma-mt-speed
(function).
test-gamma-speed
(function).
test-random-uniform-jmt
(function).
test-zigg-speed
(function).
Packages are listed by definition order.
random-distributions
randist
cl-randist
common-lisp
.
*mt-random-state*
(special variable).
make-discrete-monotone-random-var
(function).
make-discrete-random-var
(function).
make-mt-random-state
(function).
make-random-variable-gig
(function).
make-random-variable-gig-poisson
(function).
random-bernoulli
(function).
random-beta
(function).
random-binomial
(function).
random-chi-square
(function).
random-exponential
(function).
random-f
(function).
random-gamma
(function).
random-gamma-int
(function).
random-gamma-mt
(function).
random-gamma1
(function).
random-gig
(function).
random-gig-iid
(function).
random-mt
(function).
random-multinomial
(function).
random-multinomial%
(function).
random-negative-binomial
(function).
random-normal
(function).
random-normal-bivariate
(function).
random-normal-ziggurat
(function).
random-pareto
(function).
random-poisson
(function).
random-uniform
(function).
%random-gig
(function).
*ktab*
(special variable).
*n*
(special variable).
*wtab*
(special variable).
*ytab*
(special variable).
+e+
(constant).
+mt-k-inverse-2^32f+
(constant).
+mt-k2^32+
(constant).
+mt-lower-mask+
(constant).
+mt-m+
(constant).
+mt-n+
(constant).
+mt-tempering-mask-b+
(constant).
+mt-tempering-mask-c+
(constant).
+mt-upper-mask+
(constant).
+r+
(constant).
coefficient-of-variation
(function).
convert-to-double-float-vector
(function).
copy-mt-random-state
(function).
create-alias-method-vectors
(function).
gamma-frac
(function).
gamma-large
(function).
gen-uniform
(function).
genlist
(function).
geometric-mean
(function).
gig-setup
(function).
mean
(function).
median
(function).
mode
(function).
mt-genrand
(function).
mt-internal-make-random-state
(function).
mt-make-random-state-integer
(function).
mt-make-random-state-random
(function).
mt-random-state
(structure).
mt-random-state-arr
(reader).
(setf mt-random-state-arr)
(writer).
mt-random-state-mti
(reader).
(setf mt-random-state-mti)
(writer).
mt-random-state-p
(function).
mt-refill
(function).
mt-tempering-shift-l
(function).
mt-tempering-shift-s
(function).
mt-tempering-shift-t
(function).
mt-tempering-shift-u
(function).
percentile
(function).
profile-gamma
(function).
random-dirichlet1
(function).
random-generalized-inverse-poisson
(function).
random-multinomial1
(function).
random-pos
(function).
random-t
(function).
random-t-nu<=2
(function).
random-t-nu>2
(function).
random-uniform-jmt
(function).
random-vector-iid
(function).
range
(function).
report-uniform-count
(function).
sd
(macro).
setup-cut-point-randist
(function).
square
(function).
standard-deviation
(function).
standard-error-of-the-mean
(function).
test-alias-method
(function).
test-alias-method-uniform
(function).
test-alias-method-zeros
(function).
test-binomial
(function).
test-dist
(function).
test-gamma-mt-speed
(function).
test-gamma-speed
(function).
test-gig-range
(function).
test-gig-speed
(function).
test-multinomial
(function).
test-multinomial1
(function).
test-random-uniform-jmt
(function).
test-zigg-speed
(function).
transfer-sign
(function).
uniform-reference
(function).
var
(macro).
variance
(function).
zeroin
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Unlike the reference implementation, we’ll initialize the random state to a hopefully somewhat random & unique value.
The function MAKE-DISCRETE-RANDOM-VAR takes an array of probabilities and an (optional) array of values. Produces a function which returns each of the values with the specified probability (or the corresponding integer no values have been given).
Analogous to Common Lisp’s MAKE-RANDOM-STATE except that this function
works on random states for JMT’s Mersenne Twister implementation.
Optional state argument is interpreted as follows:
if T – make a new random state.
if NIL – return a copy of the current value of *MT-RANDOM-STATE*
if an integer – return a random state created by expanding the
integer to a full random state
if a list or array – create a new random state object using a copy of
that sequence. CF MT-INTERNAL-MAKE-RANDOM-STATE
if a random state – return a copy of the input state.
AJR-comment: this version is better for statistical computations, since it can be used by an externally defined seed. However, it must be optimized, being the core of any pseudo-stochastic algorithm.
The beta distribution has the form
p(x) dx = (Gamma(a + b)/(Gamma(a) Gamma(b))) x^(a-1) (1-x)^(b-1) dx
The method used here is the one described in Knuth
The binomial distribution has the form,
prob(k) = n!/(k!(n-k)!) * p^k (1-p)^(n-k) for k = 0, 1, ..., n
This is the algorithm from Knuth
Generate random variable for chi square distribution:
p(x) dx = (1/(2*Gamma(nu/2))) (x/2)^(nu/2 - 1) exp(-x/2) dx
Random values for: p(x) dx = exp(-x/mu) dx/mu
Random value for:
p(x) dx = (nu1^(nu1/2) nu2^(nu2/2) Gamma((nu1 + nu2)/2) /
Gamma(nu1/2) Gamma(nu2/2)) *
x^(nu1/2 - 1) (nu2 + nu1 * x)^(-nu1/2 -nu2/2) dx
[syntax suggar] Generate a random variable with gamma distribution using the MT method (see random-gamma-mt)
Random variable with gamma distribution with integer parameter.
New version based on Marsaglia and Tsang, ’A Simple Method for generating gamma variables’, ACM Transactions on Mathematical Software, Vol 26, No 3 (2000), p363-372.
The Gamma distribution of order a>0 is defined by:
p(x) dx = {1 / Gamma(a) b^a } x^{a-1} e^{-x/b} dx
for x>0. If X and Y are independent gamma-distributed random
variables of order a1 and a2 with the same scale parameter b, then
X+Y has gamma distribution of order a1+a2.
The algorithms below are from Knuth, vol 2, 2nd ed, p. 129.
Works only if a > 1, and is most efficient if a is large
This algorithm, reported in Knuth, is attributed to Ahrens. A
faster one, we are told, can be found in: J. H. Ahrens and
U. Dieter, Computing 12 (1974) 223-246.
Random Generalized Inverse Poisson
The algorithm is based on that given by Dagpunar (1989)
Random Generalized Inverse Poisson (vector version)
There is a bit of optimization to do...
The multinomial distribution has the form
N! n_1 n_2 n_K
prob(n_1, n_2, ... n_K) = ——————– p_1 p_2 ... p_K
(n_1! n_2! ... n_K!)
where n_1, n_2, ... n_K are nonnegative integers, sum_{k=1,K} n_k = N,
and p = (p_1, p_2, ..., p_K) is a probability distribution.
Random variates are generated using the conditional binomial method.
This scales well with N and does not require a setup step.
Ref:
C.S. David, The computer generation of multinomial random variates,
Comp. Stat. Data Anal. 16 (1993) 205-217
The negative binomial distribution has the form,
prob(k) = Gamma(n + k)/(Gamma(n) Gamma(k + 1)) p^n (1-p)^k
for k = 0, 1, ... . Note that n does not have to be an integer.
This is the Leger’s algorithm (given in the answers in Knuth)
Generate random variable with normal distribution using ziggurat method
Return a pair of numbers with specific correlation coefficent rho
and with specified variances sigma-x and sigma-y; a direct port of
gsl_ran_bivariate_gaussian from the GNU Scientific Library:
void
gsl_ran_bivariate_gaussian (const gsl_rng * r,
double sigma_x, double sigma_y, double rho,
double *x, double *y)
{
double u, v, r2, scale;
do
{
/* choose x,y in uniform square (-1,-1) to (+1,+1) */
u = -1 + 2 * gsl_rng_uniform (r);
v = -1 + 2 * gsl_rng_uniform (r);
/* see if it is in the unit circle */
r2 = u * u + v * v;
}
while (r2 > 1.0 || r2 == 0);
scale = sqrt (-2.0 * log (r2) / r2);
*x = sigma_x * u * scale;
*y = sigma_y * (rho * u + sqrt(1 - rho*rho) * v) * scale;
}
I need a good test for this one.
This routine is based on the following article, with a couple of
modifications which simplify the implementation.
George Marsaglia, Wai Wan Tsang
The Ziggurat Method for Generating Random Variables
Journal of Statistical Software, vol. 5 (2000), no. 8
http://www.jstatsoft.org/v05/i08/
The modifications are:
1) use 128 steps instead of 256 to decrease the amount of static
data necessary.
2) use an acceptance sampling from an exponential wedge
exp(-R*(x-R/2)) for the tail of the base strip to simplify the
implementation. The area of exponential wedge is used in
calculating ’v’ and the coefficients in ziggurat table, so the
coefficients differ slightly from those in the Marsaglia and Tsang
paper.
See also Leong et al, ’A Comment on the Implementation of the Ziggurat Method’, Journal of Statistical Software, vol 5 (2005), no 7.
Random value for parato distribution:
p(x) dx = (a/b) / (x/b)^(a+1) dx for x >= b
The poisson distribution has the form
p(n) = (mu^n / n!) exp(-mu)
for n = 0, 1, 2, ... . The method used here is the one from Knuth.
[syntax suggar] Random variable with uniform distribution in interval [0,1)
mt-random-state
) &optional environment) ¶mt-random-state
) stream) ¶1/(2^32), as a floating-point number
least significant r bits
most significant w-r bits
Use the single integer to expand into a bunch of
integers to use as an MT-RANDOM-STATE.
Copied from the ’sgenrand’ function in mt19937int.c.
This is mostly an internal function. I recommend using
MAKE-MT-RANDOM-STATE unless specific circumstances dictate otherwise.
Generate a new random state from a new, hopefully somewhat
random, value.
This is mostly an internal function. I recommend using
MAKE-MT-RANDOM-STATE unless specific circumstances dictate otherwise.
arr
.
mti
.
In the C program mt19937int.c, there is a function called ’genrand’, & in that function there is a block of code to execute when the mt[] array is exhausted. This function is that block of code. I’ve removed it from my MT-GENRAND function for clarity.
Return the genrated values in the n vector
Create the sign, i.e. random positive or negative, similar to a binary result.
[syntax suggar] Random variable with uniform distribution in interval [0,1)
Return a vector with n IID instances of variable
zero of the function f(x) is computed in the interval ax,bx .
input..
ax left endpoint of initial interval
bx right endpoint of initial interval
f function subprogram which evaluates f(x) for any x in
the interval ax,bx
tol desired length of the interval of uncertainty of the
final result ( .ge. 0.0d0)
output..
zeroin abcissa approximating a zero of f in the interval ax,bx
it is assumed that f(ax) and f(bx) have opposite signs
without a check. zeroin returns a zero x in the given interval
ax,bx to within a tolerance 4*macheps*abs(x) + tol, where macheps
is the relative machine precision.
this function subprogram is a slightly modified translation of
the algol 60 procedure zero given in richard brent, algorithms for
minimization without derivatives, prentice - hall, inc. (1973).
Jump to: | %
(
C F G M P R S T U V Z |
---|
Jump to: | %
(
C F G M P R S T U V Z |
---|
Jump to: | *
+
A C M S |
---|
Jump to: | *
+
A C M S |
---|
Jump to: | A B C D E F G J M N P R S T |
---|
Jump to: | A B C D E F G J M N P R S T |
---|