random sampling

0.0.0

Functions to generate random samples with various distributions

This library provides additional functions used in statistics or random generation. It provides a variety of distribution functions to provide a biased random number generation and generators for random numbers on 3D volumes.

How To

This library relies on random-state for uniform random number generation. As such, you can pick from a variety of underlying sources of randomness to drive the other algorithms in this library. For multivariate distributions such as over volumes, it relies on the 3d-math library for vector and matrix representation.

To generate samples, simply invoke one of the various functions exposed by this library. To influence the underlying random source, set or bind the `org.shirakumo.random-state:*generator*`.

Sampling for the following volume types is available:

• `box`

• `convex-mesh`

• `cylinder`

• `disc`

• `half-sphere`

• `normal`

• `pill`

• `sphere`

• `triangle`

The following distribution functions are available:

• `bernoulli`

• `beta`

• `binomial`

• `-binomial`

• `cauchy`

• `chi-squared`

• `exponential`

• `fdist`

• `flat`

• `gamma`

• `gaussian-tail`

• `gaussian`

• `geometric`

• `gumbel-1`

• `gumbel-2`

• `laplace`

• `levy-skew`

• `levy`

• `logarithmic`

• `logistic`

• `lognormal`

• `pareto`

• `poisson`

• `rayleigh-tail`

• `rayleigh`

• `tdist`

• `weibull`

Most distributions also have their probility density function available. You can retrieve it via the `pdf` function.

0.0.0
Yukari Hafner
zlib

Definition Index

• ORG.SHIRAKUMO.RANDOM-SAMPLING

No documentation provided.
• EXTERNAL FUNCTION

-BINOMIAL

• P
• N
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the negative binomial distribution.

See BINOMIAL
See -BINOMIAL-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

-BINOMIAL-PDF

• X
• P
• N
Source
```Computes the probability density of the given sample X under the -binomial distribution.

See PDF
See -BINOMIAL```
• EXTERNAL FUNCTION

BERNOULLI

• P
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the Bernoulli distribution.

See BERNOULLI-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

BERNOULLI-PDF

• X
• P
Source
```Computes the probability density of the given sample X under the Bernoulli distribution.

See PDF
See BERNOULLI```
• EXTERNAL FUNCTION

BETA

• A
• B
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the beta distribution.

See BETA-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

BETA-PDF

• X
• A
• B
Source
```Computes the probability density of the given sample X under the beta distribution.

See PDF
See BETA```
• EXTERNAL FUNCTION

BINOMIAL

• P
• N
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the binomial distribution.

See -BINOMIAL
See BINOMIAL-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

BINOMIAL-PDF

• X
• P
• N
Source
```Computes the probability density of the given sample X under the binomial distribution.

See PDF
See BINOMIAL```
• EXTERNAL FUNCTION

BOX

• BSIZE
• &OPTIONAL
• RESULT0
Source
```Samples a uniform box.

BSIZE should be the half-size of the box in each direction, with the
box being centered at 0,0,0.

See MAP-VOLUME-SAMPLES```
• EXTERNAL FUNCTION

CAUCHY

• A
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the Cauchy distribution.

See CAUCHY-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

CAUCHY-PDF

• X
• A
Source
```Computes the probability density of the given sample X under the Cauchy distribution.

See PDF
See CAUCHY```
• EXTERNAL FUNCTION

CHI-SQUARED

• NU
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the chi-squared distribution.

See CHI-SQUARED-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

CHI-SQUARED-PDF

• X
• NU
Source
```Computes the probability density of the given sample X under the chi-squared distribution.

See PDF
See CHI-SQUARED```
• EXTERNAL FUNCTION

CONVEX-MESH

• VERTICES
• FACES
• &OPTIONAL
• RESULT0
Source
```Samples a uniform convex mesh.

VERTICES must be a (SIMPLE-ARRAY SINGLE-FLOAT (*)) that contains the
packed representation of the vertex coordinates.
FACES must be a (SIMPLE-ARRAY (UNSIGNED-BYTE 16) (*)) that contains
the packed indices of the vertices that compose the faces. The
vertices of each face must occur in counter-clockwise order.
Both arrays must have a length that is a multiple of 3.

The consequences are undefined if the mesh described by VERTICES and
FACES is not convex and manifold.

See MAP-VOLUME-SAMPLES```
• EXTERNAL FUNCTION

CYLINDER

• HEIGHT
• &OPTIONAL
• NORMAL
• RESULT0
Source
```Samples a uniform cylinder.

HEIGHT is the half-height of the cylinder with the cylinder's center
always at 0,0,0.
NORMAL may be a normalised vector pointing in the UP direction of the
cylinder.

See MAP-VOLUME-SAMPLES```
• EXTERNAL FUNCTION

DISC

• &OPTIONAL
• NORMAL
• RESULT0
Source
```Samples a uniform disc.

NORMAL may be a normalised vector pointing in the UP direction of the
disc's plane.

See MAP-VOLUME-SAMPLES```
• EXTERNAL FUNCTION

EXPONENTIAL

• MU
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the exponential distribution.

See EXPONENTIAL-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

EXPONENTIAL-PDF

• X
• MU
Source
```Computes the probability density of the given sample X under the exponential distribution.

See PDF
See EXPONENTIAL```
• EXTERNAL FUNCTION

FDIST

• NU-1
• NU-2
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the F distribution.

See FDIST-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

FDIST-PDF

• X
• NU-1
• NU-2
Source
```Computes the probability density of the given sample X under the F distribution.

See PDF
See FDIST```
• EXTERNAL FUNCTION

FLAT

• A
• B
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the flat distribution.

See FLAT-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

FLAT-PDF

• X
• A
• B
Source
```Computes the probability density of the given sample X under the flat distribution.

See PDF
See FLAT```
• EXTERNAL FUNCTION

GAMMA

• A
• &OPTIONAL
• B
• RESULT0
Source
```Draws a sample from the gamma distribution.

See GAMMA-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

GAMMA-PDF

• X
• A
• &OPTIONAL
• B
Source
```Computes the probability density of the given sample X under the gamma distribution.

See PDF
See GAMMA```
• EXTERNAL FUNCTION

GAUSSIAN

• &OPTIONAL
• SIGMA
• RESULT0
Source
```Draws a sample from the Gaussian distribution.

See GAUSSIAN-TAIL
See GAUSSIAN-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

GAUSSIAN-PDF

• X
• &OPTIONAL
• SIGMA
Source
```Computes the probability density of the given sample X under the Gaussian distribution.

See PDF
See GAUSSIAN```
• EXTERNAL FUNCTION

GAUSSIAN-TAIL

• A
• &OPTIONAL
• SIGMA
• RESULT0
Source
```Draws a sample from the Gaussian-tail distribution.

See GAUSSIAN
See GAUSSIAN-TAIL-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

GAUSSIAN-TAIL-PDF

• X
• A
• &OPTIONAL
• SIGMA
Source
```Computes the probability density of the given sample X under the Gaussian-tail distribution.

See PDF
See GAUSSIAN-TAIL```
• EXTERNAL FUNCTION

GEOMETRIC

• P
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the geometric distribution.

See GEOMETRIC-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

GEOMETRIC-PDF

• X
• P
Source
```Computes the probability density of the given sample X under the geometric distribution.

See PDF
See GEOMETRIC```
• EXTERNAL FUNCTION

GUMBEL-1

• A
• B
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the Gumbel-1 distribution.

See GUMBEL-1-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

GUMBEL-1-PDF

• X
• A
• B
Source
```Computes the probability density of the given sample X under the Gumbel-1 distribution.

See PDF
See GUMBEL-1```
• EXTERNAL FUNCTION

GUMBEL-2

• A
• B
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the Gumbel-2 distribution.

See GUMBEL-2-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

GUMBEL-2-PDF

• X
• A
• B
Source
```Computes the probability density of the given sample X under the Gumbel-2 distribution.

See PDF
See GUMBEL-2```
• EXTERNAL FUNCTION

HALF-SPHERE

• &OPTIONAL
• NORMAL
• RESULT0
Source
```Samples a uniform half-sphere.

RADIUS may either be a real of the radius, or a VEC3 to generate an
ellipsoid. NORMAL may be a normalised vector pointing in the UP
direction of the half-sphere.

See MAP-VOLUME-SAMPLES```
• EXTERNAL FUNCTION

LAPLACE

• A
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the Laplace distribution.

See LAPLACE-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

LAPLACE-PDF

• X
• A
Source
```Computes the probability density of the given sample X under the Laplace distribution.

See PDF
See LAPLACE```
• EXTERNAL FUNCTION

LEVY

• C
• ALPHA
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the Levy distribution.

See LEVY-SKEW
See MAP-SAMPLES```
• EXTERNAL FUNCTION

LEVY-SKEW

• C
• ALPHA
• BETA
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the Levy-skew distribution.

See LEVY
See MAP-SAMPLES```
• EXTERNAL FUNCTION

LOGARITHMIC

• P
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the logarithmic distribution.

See LOGARITHMIC-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

LOGARITHMIC-PDF

• X
• P
Source
```Computes the probability density of the given sample X under the logarithmic distribution.

See PDF
See LOGARITHMIC```
• EXTERNAL FUNCTION

LOGISTIC

• A
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the logistic distribution.

See LOGISTIC-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

LOGISTIC-PDF

• X
• A
Source
```Computes the probability density of the given sample X under the logistic distribution.

See PDF
See LOGISTIC```
• EXTERNAL FUNCTION

LOGNORMAL

• ZETA
• SIGMA
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the lognormal distribution.

See LOGNORMAL-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

LOGNORMAL-PDF

• X
• ZETA
• SIGMA
Source
```Computes the probability density of the given sample X under the lognormal distribution.

See PDF
See LOGNORMAL```
• EXTERNAL FUNCTION

MAP-SAMPLES

• RESULT
• SAMPLE-1
Source
```Gathers samples into RESULT, drawing them from SAMPLE-1.

RESULT may be one of the following:

NULL      --- A single single-float is sampled and returned
INTEGER   --- An array of result size is sampled and returned
SEQUENCE  --- Each element of the sequence is set to a fresh sample

SAMPLE-1 must be a function of zero arguments and must return the
freshly drawn sample as a single-float.

This function is implicitly used by every distribution sampling
function. The optional RESULT argument of those functions corresponds
to the above.```
• EXTERNAL FUNCTION

MAP-VOLUME-SAMPLES

• RESULT
• SAMPLE-1
Source
```Gathers samples into RESULT, drawing them from SAMPLE-1.

RESULT may be one of the following:

NULL      --- A fresh VEC3 is sampled and returned
VEC3      --- The result is sampled and returned
INTEGER   --- An array of result size is sampled and returned
SEQUENCE  --- Each element of result is sampled and result is
returned. Each element of result must be a VEC3

SAMPLE-1 must be a function of one argument, a VEC3, and must return
said VEC3 after performing its sampling operation to fill the vector's
elements.

This function is implicitly used by every volume sampling
function. The optional RESULT argument of those functions corresponds
to the above.```
• EXTERNAL FUNCTION

NORMAL

• &OPTIONAL
• RESULT0
Source
```Samples a uniform normal vector.

This is equivalent to sampling the surface of a sphere.

RADIUS may either be a real of the radius, or a VEC3 to generate an
ellipsoid.

See MAP-VOLUME-SAMPLES```
• EXTERNAL FUNCTION

PARETO

• A
• B
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the Pareto distribution.

See PARETO-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

PARETO-PDF

• X
• A
• B
Source
```Computes the probability density of the given sample X under the Pareto distribution.

See PDF
See PARETO```
• EXTERNAL FUNCTION

PDF

• DISTRIBUTION
• &OPTIONAL
• ERRORP
Source
```Returns the probability density function for the given distribution.

The distribution must be given as a name. If no PDF exists, and errorp
is true, an error is signalled.

Every PDF takes the same arguments as its corresponding distribution
function, plus an additional first argument, which is the sample for
which to evaluate the PDF.```
• EXTERNAL FUNCTION

PILL

• HEIGHT
• &OPTIONAL
• NORMAL
• RESULT0
Source
```Samples a uniform pill.

A pill is a cylinder with its caps being spheres.

HEIGHT is the half-height of the pill cylinder with the pill's center
always at 0,0,0. If the height is zero, this is equivalent to a
sphere.
NORMAL may be a normalised vector pointing in the UP direction of the
cylinder.

See MAP-VOLUME-SAMPLES```
• EXTERNAL FUNCTION

POISSON

• MU
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the Poisson distribution.

See POISSON-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

POISSON-PDF

• X
• MU
Source
```Computes the probability density of the given sample X under the Poisson distribution.

See PDF
See POISSON```
• EXTERNAL FUNCTION

RAYLEIGH

• SIGMA
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the Rayleigh distribution.

See RAYLEIGH-TAIL
See RAYLEIGH-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

RAYLEIGH-PDF

• X
• SIGMA
Source
```Computes the probability density of the given sample X under the Rayleigh distribution.

See PDF
See RAYLEIGH```
• EXTERNAL FUNCTION

RAYLEIGH-TAIL

• A
• SIGMA
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the Rayleigh-tail distribution.

See RAYLEIGH
See RAYLEIGH-TAIL-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

RAYLEIGH-TAIL-PDF

• X
• A
• SIGMA
Source
```Computes the probability density of the given sample X under the Rayleigh-tail distribution.

See PDF
See RAYLEIGH-TAIL```
• EXTERNAL FUNCTION

REJECTION-SAMPLE

• GENERATOR
• PREDICATE
• &OPTIONAL
• RESULT0
Source
```Perform rejection sampling using GENERATOR to draw samples and PREDICATE to determine whether to keep the sample.

GENERATOR must be a function of one argument, the VEC3 to sample.
PREDICATE must be a function of one argument, the VEC3 to examine, and
must return true if the sample is suitable.

See MAP-VOLUME-SAMPLES```
• EXTERNAL FUNCTION

SPHERE

• &OPTIONAL
• RESULT0
Source
```Samples a uniform sphere.

RADIUS may either be a real of the radius, or a VEC3 to generate an
ellipsoid.

See MAP-VOLUME-SAMPLES```
• EXTERNAL FUNCTION

TDIST

• NU
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the T distribution.

See TDIST-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

TDIST-PDF

• X
• NU
Source
```Computes the probability density of the given sample X under the T distribution.

See PDF
See TDIST```
• EXTERNAL FUNCTION

TRIANGLE

• P0
• P1
• P2
• &OPTIONAL
• RESULT0
Source
```Samples a uniform triangle.

P0, P1, P2 designate the corners of the triangle.

See MAP-VOLUME-SAMPLES```
• EXTERNAL FUNCTION

WEIBULL

• A
• B
• &OPTIONAL
• RESULT0
Source
```Draws a sample from the Weibull distribution.

See WEIBULL-PDF
See MAP-SAMPLES```
• EXTERNAL FUNCTION

WEIBULL-PDF

• X
• A
• B
Source
```Computes the probability density of the given sample X under the Weibull distribution.

See PDF
See WEIBULL```