Liking cljdoc? Tell your friends :D

fastmath.complex

Complex numbers functions.

Complex number is represented as Vec2 type (from [[clojure2d.math.vector]] namespace).

To create complex number use complex, [[vec2]] or [[->Vec2]].

Simplified implementation based on Apache Commons Math. Functions don't check NaNs or INF values.

Graphs are generated as follows, background is based on:

  • argument as HUE
  • absolute value as BRIGHTNESS

with transformed points painted white.

Complex plane (identity) looks as follows:

identity

Complex numbers functions.

Complex number is represented as `Vec2` type (from [[clojure2d.math.vector]] namespace).

To create complex number use [[complex]], [[vec2]] or [[->Vec2]].

Simplified implementation based on Apache Commons Math. Functions don't check NaNs or INF values.

Graphs are generated as follows, background is based on:

* argument as HUE
* absolute value as BRIGHTNESS

with transformed points painted white.

Complex plane (identity) looks as follows:

![identity](images/c/identity.jpg)
raw docstring

fastmath.core

Collection of fast math functions and plethora of constants known from other math libraries.

Primitive math operators

Based on Primitive Math by Zach Tellman several operators are introduced and replace clojure.core functions. All operators are macros and can't be used as functions. List includes:

Known from Clojure: * + - / > < >= <= == rem quot mod bit-or bit-and bit-xor bit-not bit-shift-left bit-shift-right unsigned-bit-shift-right inc dec zero? neg? pos? min max even? odd?

And additionally:

  • bool-and - and working on booleans
  • bool-or - boolean or
  • bool-xor - boolean xor
  • bool-not - boolean not
  • << - bit shift left
  • >> - signed bit shift right
  • >>> - unsigned bit shift right
  • not== - not equal

To turn on primitive math on your namespace call use-primitive-operators. To turn off and revert original versions call unuse-primitive-operators

Fast Math

Almost all math functions are backed by FastMath library. Most of them are macros. Some of them are wrapped in Clojure functions. Almost all operates on primitive double and returns double (with an exception round or qround which returns long).

Other functions

Additionally namespace contains functions which are common in frameworks like OpenFrameworks and Processing.

Collection of fast math functions and plethora of constants known from other math libraries.

#### Primitive math operators

Based on [Primitive Math by Zach Tellman](https://github.com/ztellman/primitive-math) several operators are introduced and replace `clojure.core` functions. All operators are macros and can't be used as functions. List includes:

Known from Clojure: `*` `+` `-` `/` `>` `<` `>=` `<=` `==` `rem` `quot` `mod` `bit-or` `bit-and` `bit-xor` `bit-not` `bit-shift-left` `bit-shift-right` `unsigned-bit-shift-right` `inc` `dec` `zero?` `neg?` `pos?` `min` `max` `even?` `odd?`

And additionally:

* `bool-and` - `and` working on booleans
* `bool-or` - boolean `or`
* `bool-xor` - boolean `xor`
* `bool-not` - boolean `not`
* `<<` - bit shift left
* `>>` - signed bit shift right
* `>>>` - unsigned bit shift right
* `not==` - not equal

To turn on primitive math on your namespace call [[use-primitive-operators]].
To turn off and revert original versions call [[unuse-primitive-operators]]

#### Fast Math

Almost all math functions are backed by [FastMath](https://github.com/jeffhain/jafama) library. Most of them are macros. Some of them are wrapped in Clojure functions. Almost all operates on primitive `double` and returns `double` (with an exception [[round]] or [[qround]] which returns `long`).

#### Other functions

Additionally namespace contains functions which are common in frameworks like OpenFrameworks and Processing.

* For random/noise functions check [[fastmath.random]] namespace.
* [[fastmath.vector]] contains vector (2,3,4 dim. + double array + clojure vector) protocol and implementations.
* [[fastmath.complex]] contains complex number operations.
raw docstring

fastmath.fields

Vector field functions.

Vector fields are functions R^2->R^2.

Names are taken from fractal flames world where such fields are call variations. Most implementations are taken from JWildfire software.

Creation

To create vector field call field multimethod with name of the field as keyword.

Some of the vector fields require additional configuration as a map of parameters as keywords and values. Call parametrization to create random one or to merge with provided.

Additionally you can provide amount parameter which is scaling factor for vector field (default: 1.0).

Derived fields

You can use several method to derive new vector field from the other one(s). Possible options are:

  • derivative, grad-x, grad-y - directional derivative of the field
  • sum - sum of two fields
  • [[multiply]] - multiplication of the fields
  • composition - composition of the fields
  • [[angles]] - angles of the field vectors

Scalar fields

You can derive scalar fields from given vector field(s):

  • jacobian - determinant of jacobian matrix
  • divergence - divergence of the field
  • cross - cross product of the fields (as a determinant of the 2x2 matrix of vectors)
  • dot - dot product
  • angle-between - angle between vectors from fields.

Combinations

The other option is to create vector field using some of the above possibilities. Combination is a tree of field operations with parametrizations. Functions:

Vector field functions.

Vector fields are functions R^2->R^2.

Names are taken from fractal flames world where such fields are call `variations`. Most implementations are taken from [JWildfire](http://jwildfire.org/) software.

## Creation

To create vector field call [[field]] multimethod with name of the field as keyword.

Some of the vector fields require additional configuration as a map of parameters as keywords and values. Call [[parametrization]] to create random one or to merge with provided.

Additionally you can provide `amount` parameter which is scaling factor for vector field (default: `1.0`).

## Derived fields

You can use several method to derive new vector field from the other one(s). Possible options are:

* [[derivative]], [[grad-x]], [[grad-y]] - directional derivative of the field
* [[sum]] - sum of two fields
* [[multiply]] - multiplication of the fields
* [[composition]] - composition of the fields
* [[angles]] - angles of the field vectors

## Scalar fields

You can derive scalar fields from given vector field(s):

* [[jacobian]] - determinant of jacobian matrix
* [[divergence]] - divergence of the field
* [[cross]] - cross product of the fields (as a determinant of the 2x2 matrix of vectors)
* [[dot]] - dot product
* [[angle-between]] - angle between vectors from fields.

## Combinations

The other option is to create vector field using some of the above possibilities. Combination is a tree of field operations with parametrizations. Functions:

* [[combine]] - create vector field randomly of from given parametrization.
* [[random-configuration]] - returns random configuration as a map
* [[randomize-configuration]] - change parametrization for given configuration.
raw docstring

fastmath.interpolation

1d, 2d interpolation functions.

See more:

Note: Smile interpolators doesn't check ranges.

Input data

You provide data as sequence or double array.

1d interpolation

You provide two sequences:

  • xs - x axis coorditanes, strictly monotonic (increasing)
  • ys - function values

See [[kriging-spline-interpolator]]

2d interpolation

This is grid based interpolation.

  • xs - x axis coordinates, strictly monotonic (increasing)
  • ys - y axis coordinates, strictly monotonic (increasing)
  • vs - sequence of sequences of values (2d array) for all possible pairs. Array is column-wise: [ [first column] [second column] ...].

See [[cubic-2d-interpolator]]

1d, 2d interpolation functions.

See more:

* [Apache Commons Math](http://commons.apache.org/proper/commons-math/javadocs/api-3.6.1/org/apache/commons/math3/analysis/interpolation/package-summary.html)
* [Smile Interpolation](http://haifengl.github.io/smile/api/java/smile/interpolation/package-summary.html)

Note: Smile interpolators doesn't check ranges.

### Input data

You provide data as sequence or double array.

#### 1d interpolation

You provide two sequences:

* `xs` - x axis coorditanes, strictly monotonic (increasing)
* `ys` - function values

See [[kriging-spline-interpolator]]

#### 2d interpolation

This is grid based interpolation.

* `xs` - x axis coordinates, strictly monotonic (increasing)
* `ys` - y axis coordinates, strictly monotonic (increasing)
* `vs` - sequence of sequences of values (2d array) for all possible pairs. Array is column-wise: `[ [first column] [second column] ...]`.

See [[cubic-2d-interpolator]]
raw docstring

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. You can generate sequence of double, [[Vec2]], [[Vec3]] or [[Vec4]] types. Just pass the size to creator function.

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

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

After creation you get function equivalent to repeatedly.

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 used as into:

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. Return is normalized to [0,1] range:

  • noise - Perlin Noise (gradient noise, 6 octaves, quintic interpolation)
  • vnoise - Value Noise (as in Processing, 6 octaves, hermite interpolation)
  • simplex - Simpled Noise (6 octaves)
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.
You can generate sequence of `double`, [[Vec2]], [[Vec3]] or [[Vec4]] types. Just pass the size to creator function.

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

* `:halton` - Halton low-discrepancy sequence; range [0,1]
* `:sobol` - Sobol low-discrepancy sequence; range [0,1]
* `:sphere` - uniformly random distributed on unit sphere
* `:gaussian` - gaussian distributed (mean=0, stddev=1)
* `:default` - uniformly random; range:[0,1]

After creation you get function equivalent to `repeatedly`.

#### 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 used as into:

* 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. Return is normalized to `[0,1]` range:

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

##### 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

fastmath.rbf

Radial Basis Function

Create with multifunction rbf.

All of them accept scaling factor scale. Only polyharmonic is defined with integer exponent k. See rbfs-list for all names.

rbf-obj returns SMILE library object for defined function.

Radial Basis Function

Create with multifunction [[rbf]].

All of them accept scaling factor `scale`.
Only polyharmonic is defined with integer exponent `k`.
See [[rbfs-list]] for all names.

[[rbf-obj]] returns SMILE library object for defined function.
raw docstring

fastmath.stats

Statistics functions.

  • Descriptive statistics for sequence.
  • Correlation / covariance of two sequences.
  • Outliers

All functions are backed by Apache Commons Math or SMILE libraries. All work with Clojure sequences.

Descriptive statistics

All in one function stats-map contains:

  • :Size - size of the samples, (count ...)
  • :Min - minimum value
  • :Max - maximum value
  • :Mean - mean/average
  • :Median - median, see also: median-3
  • :Mode - mode, see also: modes
  • :Q1 - first quartile, use: percentile, [[quartile]]
  • :Q3 - third quartile, use: percentile, [[quartile]]
  • :Total - sum of all samples
  • :SD - standard deviation of population, corrected sample standard deviation, use: population-stddev
  • :MAD - median-absolute-deviation
  • :SEM - standard error of mean
  • :LAV - lower adjacent value, use: adjacent-values
  • :UAV - upper adjacent value, use: adjacent-values
  • :IQR - interquartile range, (- q3 q1)
  • :LOF - lower outer fence, (- q1 (* 3.0 iqr))
  • :UOF - upper outer fence, (+ q3 (* 3.0 iqr))
  • :LIF - lower inner fence, (- q1 (* 1.5 iqr))
  • :UIF - upper inner fence, (+ q3 (* 1.5 iqr))
  • :Outliers - number of outliers, samples which are outside outer fences
  • :Kurtosis - kurtosis
  • :Skewness - skewness
  • :SecMoment - second central moment, use: second-moment

Note: percentile and [[quartile]] can have 10 different interpolation strategies. See docs

Correlation / Covariance / Divergence

Other

Normalize samples to have mean=0 and standard deviation = 1 with standardize.

histogram to count samples in evenly spaced ranges.

Statistics functions.

* Descriptive statistics for sequence.
* Correlation / covariance of two sequences.
* Outliers

All functions are backed by Apache Commons Math or SMILE libraries. All work with Clojure sequences.

### Descriptive statistics

All in one function [[stats-map]] contains:

* `:Size` - size of the samples, `(count ...)`
* `:Min` - [[minimum]] value
* `:Max` - [[maximum]] value
* `:Mean` - [[mean]]/average
* `:Median` - [[median]], see also: [[median-3]]
* `:Mode` - [[mode]], see also: [[modes]]
* `:Q1` - first quartile, use: [[percentile]], [[quartile]]
* `:Q3` - third quartile, use: [[percentile]], [[quartile]]
* `:Total` - [[sum]] of all samples
* `:SD` - standard deviation of population, corrected sample standard deviation, use: [[population-stddev]]
* `:MAD` - [[median-absolute-deviation]]
* `:SEM` - standard error of mean
* `:LAV` - lower adjacent value, use: [[adjacent-values]]
* `:UAV` - upper adjacent value, use: [[adjacent-values]]
* `:IQR` - interquartile range, `(- q3 q1)`
* `:LOF` - lower outer fence, `(- q1 (* 3.0 iqr))`
* `:UOF` - upper outer fence, `(+ q3 (* 3.0 iqr))`
* `:LIF` - lower inner fence, `(- q1 (* 1.5 iqr))`
* `:UIF` - upper inner fence, `(+ q3 (* 1.5 iqr))`
* `:Outliers` - number of [[outliers]], samples which are outside outer fences
* `:Kurtosis` - [[kurtosis]]
* `:Skewness` - [[skewness]]
* `:SecMoment` - second central moment, use: [[second-moment]]

Note: [[percentile]] and [[quartile]] can have 10 different interpolation strategies. See [docs](http://commons.apache.org/proper/commons-math/javadocs/api-3.6.1/org/apache/commons/math3/stat/descriptive/rank/Percentile.html)

### Correlation / Covariance / Divergence

* [[covariance]]
* [[correlation]]
* [[pearson-correlation]]
* [[spearman-correlation]]
* [[kendall-correlation]]
* [[kullback-leibler-divergence]]
* [[jensen-shannon-divergence]]

### Other

Normalize samples to have mean=0 and standard deviation = 1 with [[standardize]].

[[histogram]] to count samples in evenly spaced ranges.
raw docstring

fastmath.transform

Transforms.

See transformer and TransformProto for details.

Wavelet

Based on JWave library.

Be aware that some of the wavelet types doesn't work properly. :battle-23, :cdf-53, :cdf-97.

Cos/Sin/Hadamard

Orthogonal or standard fast sine/cosine/hadamard 1d transforms.

Fourier

DFT.

Transforms.

See [[transformer]] and [[TransformProto]] for details.

#### Wavelet

Based on [JWave](https://github.com/cscheiblich/JWave/) library.

Be aware that some of the wavelet types doesn't work properly. `:battle-23`, `:cdf-53`, `:cdf-97`.

#### Cos/Sin/Hadamard

Orthogonal or standard fast sine/cosine/hadamard 1d transforms.

#### Fourier

DFT.
raw docstring

fastmath.vector

Mathematical vector operations.

Types

  • Fixed size (custom types):
    • Vec2 - 2d vector, creator vec2
    • Vec3 - 3d vector, creator vec3
    • Vec4 - 4d vector, creator vec4
    • ArrayVec - fixed size vector as double array, n-dimensional, creator [[arrayvec]]
  • Variable size:
    • Clojure's PersistentVector, creator [].

VectorProto defines most of the functions.

Vectors implements also:

  • Sequable
  • Sequencial
  • IFn
  • Counted
  • equals and toString from Object

That means that vectors can be destructured, treated as sequence or called as a function. See vec2 for examples.

Mathematical vector operations.

### Types

* Fixed size (custom types):
    * Vec2 - 2d vector, creator [[vec2]]
    * Vec3 - 3d vector, creator [[vec3]]
    * Vec4 - 4d vector, creator [[vec4]]
    * ArrayVec - fixed size vector as double array, n-dimensional, creator [[arrayvec]]
* Variable size:
    * Clojure's PersistentVector, creator `[]`.

[[VectorProto]] defines most of the functions.

Vectors implements also:

* `Sequable`
* `Sequencial`
* `IFn`
* `Counted`
* `equals` and `toString` from `Object`

That means that vectors can be destructured, treated as sequence or called as a function. See [[vec2]] for examples.
raw docstring

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

× close