Liking cljdoc? Tell your friends :D

fastmath.random

Various random and noise functions.

Namespace defines various random number generators (RNGs), different types of random functions, sequence generators and noise functions.

RNGs

You can use a selection of various RNGs defined in Apache Commons Math library.

Currently supported RNGs:

  • :jdk - default java.util.Random
  • :mersenne - MersenneTwister
  • :isaac - ISAAC
  • :well512a, :well1024a, :well19937a, :well19937c, :well44497a, :well44497b - several WELL variants

To create your RNG use rng multimethod. Pass RNG name and (optional) seed. Returned RNG is equipped with [[RNGProto]] protocol with methods: irandom, lrandom, frandom drandom, grandom, brandom which return random primitive value with given RNG.

(let [rng (rng :isaac 1337)]
  (irandom rng))

For conveniency default RNG (:jdk) with following functions are created: irand, lrand, frand, drand, grand, brand.

Each prefix denotes returned type:

  • i - int
  • l - long
  • f - float
  • d - double
  • g - gaussian (double)
  • b - boolean

Check individual function for parameters description.

Random Vector Sequences

Couple of functions to generate sequences of numbers or vectors.

To create generator call sequence-generator with generator name and vector size. Following generators are available:

  • :halton - Halton low-discrepancy sequence; range [0,1]
  • :sobol - Sobol low-discrepancy sequence; range [0,1]
  • :r2 - R2 low-discrepancy sequence; range [0,1], more...
  • :sphere - uniformly random distributed on unit sphere
  • :ball - uniformly random distributed from unit ball
  • :gaussian - gaussian distributed (mean=0, stddev=1)
  • :default - uniformly random; range:[0,1]

:halton, :sobol and :r2 can be also randomly jittered according to this article. Call jittered-sequence-generator.

After creation you get lazy sequence

Noise

List of continuous noise functions (1d, 2d and 3d):

  • :value - value noise
  • :gradient - gradient noise (improved Ken Perlin version)
  • :simplex - simplex noise

First two (:value and :gradient) can use 4 different interpolation types: :none, :linear, :hermite (cubic) and :quintic.

All can be combined in following variants:

Noise creation requires detailed configuration which is simple map of following keys:

  • :seed - seed as integer
  • :noise-type - type of noise: :value, :gradient (default), :simplex
  • :interpolation - type of interpolation (for value and gradient): :none, :linear, :hermite (default) or :quintic
  • :octaves - number of octaves for combined noise (like FBM), default: 6
  • :lacunarity - scaling factor for combined noise, default: 2.00
  • :gain - amplitude scaling factor for combined noise, default: 0.5
  • :normalize? - should be normalized to [0,1] range (true, default) or to [-1,1] range (false)

For usage convenience 3 ready to use functions are prepared. Returning value from [0,1] range:

  • noise - Perlin Noise (gradient noise, 6 octaves, quintic interpolation)
  • vnoise - Value Noise (as in Processing, 6 octaves, hermite interpolation)
  • simplex - Simplex Noise (6 octaves)

For random noise generation you can use random-noise-cfg and random-noise-fn. Both can be feed with configuration. Additional configuration:

  • :generator can be set to one of the noise variants, defaults to :fbm
  • :warp-scale - 0.0 - do not warp, >0.0 warp
  • :warp-depth - depth for warp (default 1.0, if warp-scale is positive)

Discrete Noise

discrete-noise is a 1d or 2d hash function for given integers. Returns double from [0,1] range.

Distribution

Various real and integer distributions. See [[DistributionProto]] and [[RNGProto]] for functions.

To create distribution call distribution multimethod with name as a keyword and map as parameters.

Various random and noise functions.

Namespace defines various random number generators (RNGs), different types of random functions, sequence generators and noise functions.

### RNGs

You can use a selection of various RNGs defined in [Apache Commons Math](http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/random/package-summary.html) library.

Currently supported RNGs:

* `:jdk` - default java.util.Random
* `:mersenne` - MersenneTwister
* `:isaac` - ISAAC
* `:well512a`, `:well1024a`, `:well19937a`, `:well19937c`, `:well44497a`, `:well44497b` - several WELL variants

To create your RNG use [[rng]] multimethod. Pass RNG name and (optional) seed. Returned RNG is equipped with [[RNGProto]] protocol with methods: [[irandom]], [[lrandom]], [[frandom]] [[drandom]], [[grandom]], [[brandom]] which return random primitive value with given RNG.

```
(let [rng (rng :isaac 1337)]
  (irandom rng))
```

For conveniency default RNG (`:jdk`) with following functions are created: [[irand]], [[lrand]], [[frand]], [[drand]], [[grand]], [[brand]].

Each prefix denotes returned type:

* i - int
* l - long
* f - float
* d - double
* g - gaussian (double)
* b - boolean

Check individual function for parameters description.

### Random Vector Sequences

Couple of functions to generate sequences of numbers or vectors.

To create generator call [[sequence-generator]] with generator name and vector size.
Following generators are available:

* `:halton` - Halton low-discrepancy sequence; range [0,1]
* `:sobol` - Sobol low-discrepancy sequence; range [0,1]
* `:r2` - R2 low-discrepancy sequence; range [0,1], [more...](http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/)
* `:sphere` - uniformly random distributed on unit sphere
* `:ball` - uniformly random distributed from unit ball
* `:gaussian` - gaussian distributed (mean=0, stddev=1)
* `:default` - uniformly random; range:[0,1]

`:halton`, `:sobol` and `:r2` can be also randomly jittered according to this [article](http://extremelearning.com.au/a-simple-method-to-construct-isotropic-quasirandom-blue-noise-point-sequences/). Call [[jittered-sequence-generator]].

After creation you get lazy sequence

### Noise

List of continuous noise functions (1d, 2d and 3d):

* `:value` - value noise
* `:gradient` - gradient noise (improved Ken Perlin version)
* `:simplex` - simplex noise

First two (`:value` and `:gradient`) can use 4 different interpolation types: `:none`, `:linear`, `:hermite` (cubic) and `:quintic`.

All can be combined in following variants:

* Noise - pure noise value, create with [[single-noise]]
* FBM - fractal brownian motion, create with [[fbm-noise]]
* Billow - billow noise, [[billow-noise]]
* RidgedMulti - ridged multi, [[ridgedmulti-noise]]

Noise creation requires detailed configuration which is simple map of following keys:

* `:seed` - seed as integer
* `:noise-type` - type of noise: `:value`, `:gradient` (default), `:simplex`
* `:interpolation` - type of interpolation (for value and gradient): `:none`, `:linear`, `:hermite` (default) or `:quintic`
* `:octaves` - number of octaves for combined noise (like FBM), default: 6
* `:lacunarity` - scaling factor for combined noise, default: 2.00
* `:gain` - amplitude scaling factor for combined noise, default: 0.5
* `:normalize?` - should be normalized to `[0,1]` range (true, default) or to `[-1,1]` range (false)

For usage convenience 3 ready to use functions are prepared. Returning value from `[0,1]` range:

* [[noise]] - Perlin Noise (gradient noise, 6 octaves, quintic interpolation)
* [[vnoise]] - Value Noise (as in Processing, 6 octaves, hermite interpolation)
* [[simplex]] - Simplex Noise (6 octaves)

For random noise generation you can use [[random-noise-cfg]] and [[random-noise-fn]]. Both can be feed with configuration. Additional configuration:

* `:generator` can be set to one of the noise variants, defaults to `:fbm`
* `:warp-scale` - 0.0 - do not warp, >0.0 warp
* `:warp-depth` - depth for warp (default 1.0, if warp-scale is positive)

#### Discrete Noise

[[discrete-noise]] is a 1d or 2d hash function for given integers. Returns double from `[0,1]` range.

### Distribution

Various real and integer distributions. See [[DistributionProto]] and [[RNGProto]] for functions.

To create distribution call [[distribution]] multimethod with name as a keyword and map as parameters.
raw docstring

->seqclj

(->seq)
(->seq rng)
(->seq rng n)
(->seq rng n sampling-method)

Returns lazy sequence of random samples (can be limited to optional n values).

Additionally one of the sampling methods can be provided, ie: :uniform, :antithetic, :systematic and :stratified.

Returns lazy sequence of random samples (can be limited to optional `n` values).

Additionally one of the sampling methods can be provided, ie: `:uniform`, `:antithetic`, `:systematic` and `:stratified`.
sourceraw docstring

ball-randomclj

(ball-random dims)
(ball-random rng dims)

Return random vector from a ball

Return random vector from a ball
sourceraw docstring

billow-noiseclj

(billow-noise)
(billow-noise cfg__2968__auto__)

Create billow-noise function with optional configuration.

Create billow-noise function with optional configuration.
sourceraw docstring

brandclj

Random boolean with default RNG.

Returns true or false with equal probability. You can set p probability for true

Random boolean with default RNG.

Returns true or false with equal probability. You can set `p` probability for `true`
sourceraw docstring

brandomclj

(brandom rng)
(brandom rng p)

Random boolean with provided RNG

Random boolean with provided RNG
sourceraw docstring

ccdfclj

(ccdf d v)

Complementary cumulative probability.

Complementary cumulative probability.
sourceraw docstring

cdfclj

(cdf d v)
(cdf d v1 v2)

Cumulative probability.

Cumulative probability.
sourceraw docstring

continuous?clj

(continuous? d)

Does distribution support continuous domain?

Does distribution support continuous domain?
sourceraw docstring

covarianceclj

(covariance d)

Distribution covariance matrix (for multivariate distributions)

Distribution covariance matrix (for multivariate distributions)
sourceraw docstring

default-normalclj

Default normal distribution (u=0.0, sigma=1.0).

Default normal distribution (u=0.0, sigma=1.0).
sourceraw docstring

default-rngclj

Default RNG - JDK

Default RNG - JDK
sourceraw docstring

dimensionsclj

(dimensions d)

Distribution dimensionality

Distribution dimensionality
sourceraw docstring

discrete-noiseclj

(discrete-noise X)
(discrete-noise X Y)

Discrete noise. Parameters:

  • X (long)
  • Y (long, optional)

Returns double value from [0,1] range

Discrete noise. Parameters:

* X (long)
* Y (long, optional)

Returns double value from [0,1] range
sourceraw docstring

distributioncljmultimethod

Create distribution object.

  • First parameter is distribution as a :key.
  • Second parameter is a map with configuration.

All distributions accept rng under :rng key (default: default-rng) and some of them accept inverse-cumm-accuracy (default set to 1e-9).

Create distribution object.

* First parameter is distribution as a `:key`.
* Second parameter is a map with configuration.

All distributions accept `rng` under `:rng` key (default: [[default-rng]]) and some of them accept `inverse-cumm-accuracy` (default set to `1e-9`).
sourceraw docstring

distribution-idclj

(distribution-id d)

Distribution identifier as keyword.

Distribution identifier as keyword.
sourceraw docstring

distribution-parametersclj

(distribution-parameters d)
(distribution-parameters d all?)

Distribution highest supported value.

When all? is true, technical parameters are included, ie: :rng and :inverser-cumm-accuracy.

Distribution highest supported value.

When `all?` is true, technical parameters are included, ie: `:rng` and `:inverser-cumm-accuracy`.
sourceraw docstring

distribution?clj

(distribution? distr)

Checks if distr is a distribution object.

Checks if `distr` is a distribution object.
sourceraw docstring

distributions-listclj

List of distributions.

List of distributions.
sourceraw docstring

drandclj

(drand)
(drand mx)
(drand mn mx)

Random double number with default RNG.

As default returns random double from [0,1) range. When mx is passed, range is set to [0, mx). When mn is passed, range is set to [mn, mx).

Random double number with default RNG.

As default returns random double from `[0,1)` range.
When `mx` is passed, range is set to `[0, mx)`. When `mn` is passed, range is set to `[mn, mx)`.
sourceraw docstring

drandomclj

(drandom rng)
(drandom rng mx)
(drandom rng mn mx)

Random double number with provided RNG

Random double number with provided RNG
sourceraw docstring

fbm-noiseclj

(fbm-noise)
(fbm-noise cfg__2968__auto__)

Create fbm-noise function with optional configuration.

Create fbm-noise function with optional configuration.
sourceraw docstring

flipclj

(flip)
(flip p)

Returns 1 with given probability, 0 otherwise

Returns 1 with given probability, 0 otherwise
sourceraw docstring

flip-rngclj

(flip-rng rng)
(flip-rng rng p)

Returns 1 with given probability, 0 otherwise, for given rng

Returns 1 with given probability, 0 otherwise, for given rng
sourceraw docstring

flipbclj

(flipb)
(flipb p)

Returns true with given probability, false otherwise

Returns true with given probability, false otherwise
sourceraw docstring

flipb-rngclj

(flipb-rng rng)
(flipb-rng rng p)

Returns true with given probability, false otherwise, for given rng

Returns true with given probability, false otherwise, for given rng
sourceraw docstring

frandclj

(frand)
(frand mx)
(frand mn mx)

Random double number with default RNG.

As default returns random float from [0,1) range. When mx is passed, range is set to [0, mx). When mn is passed, range is set to [mn, mx).

Random double number with default RNG.

As default returns random float from `[0,1)` range.
When `mx` is passed, range is set to `[0, mx)`. When `mn` is passed, range is set to `[mn, mx)`.
sourceraw docstring

frandomclj

(frandom rng)
(frandom rng mx)
(frandom rng mn mx)

Random double number with provided RNG

Random double number with provided RNG
sourceraw docstring

grandclj

(grand)
(grand stddev)
(grand mean stddev)

Random gaussian double number with default RNG.

As default returns random double from N(0,1). When std is passed, N(0,std) is used. When mean is passed, distribution is set to N(mean, std).

Random gaussian double number with default RNG.

As default returns random double from `N(0,1)`.
When `std` is passed, `N(0,std)` is used. When `mean` is passed, distribution is set to `N(mean, std)`.
sourceraw docstring

grandomclj

(grandom rng)
(grandom rng stddev)
(grandom rng mean stddev)

Random gaussian double number with provided RNG

Random gaussian double number with provided RNG
sourceraw docstring

icdfclj

(icdf d v)

Inverse cumulative probability

Inverse cumulative probability
sourceraw docstring

integrate-pdfclj

(integrate-pdf
  pdf-func
  {:keys [mn mx steps interpolator min-iterations]
   :or {mn 0.0 mx 1.0 steps 1000 min-iterations 3 interpolator :linear}})
(integrate-pdf pdf-func mn mx steps)

Integrate PDF function, returns CDF and iCDF

Parameters:

  • pdf-func - univariate function
  • mn - lower bound for integration, value of pdf-func should be 0.0 at this point
  • mx - upper bound for integration
  • steps - how much subintervals to integrate (default 1000)
  • min-iterations - minimum iterations for RombergIntegrator (default 3)
  • interpolator - interpolation method between integrated points (default :spline)

Possible interpolation methods: :linear (default), :spline, :monotone or any function from fastmath.interpolation

Integrate PDF function, returns CDF and iCDF

Parameters:
* `pdf-func` - univariate function
* `mn` - lower bound for integration, value of pdf-func should be 0.0 at this point
* `mx` - upper bound for integration
* `steps` - how much subintervals to integrate (default 1000)
* `min-iterations` - minimum iterations for RombergIntegrator (default 3)
* `interpolator` - interpolation method between integrated points (default :spline)

Possible interpolation methods: `:linear` (default), `:spline`, `:monotone` or any function from `fastmath.interpolation`
sourceraw docstring

irandclj

(irand)
(irand mx)
(irand mn mx)

Random integer number with default RNG.

As default returns random integer from full integer range. When mx is passed, range is set to [0, mx). When mn is passed, range is set to [mn, mx).

Random integer number with default RNG.

As default returns random integer from full integer range. 
When `mx` is passed, range is set to `[0, mx)`. When `mn` is passed, range is set to `[mn, mx)`.
sourceraw docstring

irandomclj

(irandom rng)
(irandom rng mx)
(irandom rng mn mx)

Random integer number with provided RNG

Random integer number with provided RNG
sourceraw docstring

jittered-sequence-generatorclj

(jittered-sequence-generator seq-generator dimensions)
(jittered-sequence-generator seq-generator dimensions jitter)

Create jittered sequence generator.

Suitable for :r2, :sobol and :halton sequences.

jitter parameter range is from 0 (no jitter) to 1 (full jitter). Default: 0.25.

See also sequence-generator.

Create jittered sequence generator.

Suitable for `:r2`, `:sobol` and `:halton` sequences.

`jitter` parameter range is from `0` (no jitter) to `1` (full jitter). Default: 0.25.

See also [[sequence-generator]].
sourceraw docstring

likelihoodclj

(likelihood d vs)

Likelihood of samples

Likelihood of samples
sourceraw docstring

log-likelihoodclj

(log-likelihood d vs)

Log likelihood of samples

Log likelihood of samples
sourceraw docstring

lower-boundclj

(lower-bound d)

Distribution lowest supported value

Distribution lowest supported value
sourceraw docstring

lpdfclj

(lpdf d v)

Log density

Log density
sourceraw docstring

lrandclj

(lrand)
(lrand mx)
(lrand mn mx)

Random long number with default RNG.

As default returns random long from full integer range. When mx is passed, range is set to [0, mx). When mn is passed, range is set to [mn, mx).

Random long number with default RNG.

As default returns random long from full integer range. 
When `mx` is passed, range is set to `[0, mx)`. When `mn` is passed, range is set to `[mn, mx)`.
sourceraw docstring

lrandomclj

(lrandom rng)
(lrandom rng mx)
(lrandom rng mn mx)

Random long number with provided RNG

Random long number with provided RNG
sourceraw docstring

meanclj

(mean d)

Distribution mean

Distribution mean
sourceraw docstring

meansclj

(means d)

Distribution means (for multivariate distributions)

Distribution means (for multivariate distributions)
sourceraw docstring

noiseclj

(noise x)
(noise x y)
(noise x y z)

Improved Perlin Noise.

6 octaves, quintic interpolation.

Improved Perlin Noise.

6 octaves, quintic interpolation.
sourceraw docstring

noise-generatorsclj

List of possible noise generators as a map of names and functions.

List of possible noise generators as a map of names and functions.
sourceraw docstring

noise-interpolationsclj

List of possible noise interpolations as a map of names and values.

List of possible noise interpolations as a map of names and values.
sourceraw docstring

noise-typesclj

List of possible noise types as a map of names and values.

List of possible noise types as a map of names and values.
sourceraw docstring

observecljmacro

(observe d vs)

Log likelihood of samples. Alias for log-likelihood.

Log likelihood of samples. Alias for [[log-likelihood]].
sourceraw docstring

observe1clj

(observe1 d v)

Log of probability/density of the value. Alias for lpdf.

Log of probability/density of the value. Alias for [[lpdf]].
sourceraw docstring

pdfclj

(pdf d v)

Density

Density
sourceraw docstring

probabilityclj

(probability d v)

Probability (PMF)

Probability (PMF)
sourceraw docstring

random-noise-cfgclj

(random-noise-cfg)
(random-noise-cfg pre-config)

Create random noise configuration.

Optional map with fixed values.

Create random noise configuration.

Optional map with fixed values.
sourceraw docstring

random-noise-fnclj

(random-noise-fn)
(random-noise-fn cfg)

Create random noise function from all possible options.

Optionally provide own configuration cfg. In this case one of 4 different blending methods will be selected.

Create random noise function from all possible options.

Optionally provide own configuration `cfg`. In this case one of 4 different blending methods will be selected.
sourceraw docstring

randvalcljmacro

(randval)
(randval prob)
(randval v1 v2)
(randval prob v1 v2)

Return value with given probability (default 0.5)

Return value with given probability (default 0.5)
sourceraw docstring

randval-rngcljmacro

(randval-rng rng)
(randval-rng rng prob)
(randval-rng rng v1 v2)
(randval-rng rng prob v1 v2)

Return value with given probability (default 0.5), for given rng

Return value with given probability (default 0.5), for given rng
sourceraw docstring

ridgedmulti-noiseclj

(ridgedmulti-noise)
(ridgedmulti-noise cfg__2968__auto__)

Create ridgedmulti-noise function with optional configuration.

Create ridgedmulti-noise function with optional configuration.
sourceraw docstring

rngcljmultimethod

Create RNG for given name (as keyword) and optional seed. Return object enhanced with [[RNGProto]]. See: rngs-list for names.

Create RNG for given name (as keyword) and optional seed. Return object enhanced with [[RNGProto]]. See: [[rngs-list]] for names.
sourceraw docstring

rngs-listclj

List of all possible RNGs.

List of all possible RNGs.
sourceraw docstring

roll-a-diceclj

(roll-a-dice sides)
(roll-a-dice dices sides)

Roll a dice with given sides

Roll a dice with given sides
sourceraw docstring

roll-a-dice-rngclj

(roll-a-dice-rng rng sides)
(roll-a-dice-rng rng dices sides)

Roll a dice with given sides and given rng

Roll a dice with given sides and given rng
sourceraw docstring

sampleclj

(sample d)

Random sample

Random sample
sourceraw docstring

sequence-generatorcljmultimethod

Create Sequence generator. See sequence-generators-list for names.

Values:

  • :r2, :halton, :sobol, :default/:uniform - range [0-1] for each dimension
  • :gaussian - from N(0,1) distribution
  • :sphere - from surface of unit sphere (ie. euclidean distance from origin equals 1.0)
  • :ball - from an unit ball

Possible dimensions:

  • :r2 - 1-15
  • :halton - 1-40
  • :sobol - 1-1000
  • the rest - 1+

See also jittered-sequence-generator.

Create Sequence generator. See [[sequence-generators-list]] for names.

Values:

* `:r2`, `:halton`, `:sobol`, `:default`/`:uniform` - range `[0-1] for each dimension`
* `:gaussian` - from `N(0,1)` distribution
* `:sphere` -  from surface of unit sphere (ie. euclidean distance from origin equals 1.0)
* `:ball` - from an unit ball

Possible dimensions:

* `:r2` - 1-15
* `:halton` - 1-40
* `:sobol` - 1-1000
* the rest - 1+

See also [[jittered-sequence-generator]].
sourceraw docstring

sequence-generators-listclj

List of random sequence generator. See sequence-generator.

List of random sequence generator. See [[sequence-generator]].
sourceraw docstring

set-seedclj

(set-seed)
(set-seed v)
(set-seed rng v)

Create and return new RNG

Create and return new RNG
sourceraw docstring

set-seed!clj

(set-seed!)
(set-seed! v)
(set-seed! rng v)

Sets seed.

If rng is :smile calls smile.math.MathEx/setSeed().

Without rng sets both :smile and default-rng

Sets seed.

If `rng` is `:smile` calls `smile.math.MathEx/setSeed()`.

Without `rng` sets both `:smile` and `default-rng`
sourceraw docstring

simplexclj

(simplex x)
(simplex x y)
(simplex x y z)

Simplex noise. 6 octaves.

Simplex noise. 6 octaves.
sourceraw docstring

single-noiseclj

(single-noise)
(single-noise cfg__2968__auto__)

Create single-noise function with optional configuration.

Create single-noise function with optional configuration.
sourceraw docstring

source-objectclj

(source-object d)

Returns Java or proxy object from backend library (if available)

Returns Java or proxy object from backend library (if available)
sourceraw docstring

synced-rngclj

(synced-rng m)
(synced-rng m seed)

Create synchronized RNG for given name and optional seed. Wraps rng method.

Create synchronized RNG for given name and optional seed. Wraps [[rng]] method.
sourceraw docstring

upper-boundclj

(upper-bound d)

Distribution highest supported value

Distribution highest supported value
sourceraw docstring

varianceclj

(variance d)

Distribution variance

Distribution variance
sourceraw docstring

vnoiseclj

(vnoise x)
(vnoise x y)
(vnoise x y z)

Value Noise.

6 octaves, Hermite interpolation (cubic, h01).

Value Noise.

6 octaves, Hermite interpolation (cubic, h01).
sourceraw docstring

warp-noise-fnclj

(warp-noise-fn)
(warp-noise-fn noise)
(warp-noise-fn noise scale)
(warp-noise-fn noise scale depth)

Create warp noise (see Inigo Quilez article).

Parameters:

  • noise function, default: vnoise
  • scale factor, default: 4.0
  • depth (1 or 2), default 1

Normalization of warp noise depends on normalization of noise function.

Create warp noise (see [Inigo Quilez article](http://www.iquilezles.org/www/articles/warp/warp.htm)).

Parameters:

* noise function, default: vnoise
* scale factor, default: 4.0
* depth (1 or 2), default 1

Normalization of warp noise depends on normalization of noise function.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close