From 716ac773a6d0918a42bfd4336e94ef16f8ac5514 Mon Sep 17 00:00:00 2001 From: GenerateMe Date: Fri, 29 Sep 2023 14:13:37 +0200 Subject: [PATCH] linear optimization --- CHANGELOG.md | 1 + README.md | 2 +- docs/fastmath.clustering.html | 78 ++-- docs/fastmath.complex.html | 118 ++--- docs/fastmath.core.html | 593 +++++++++++++------------ docs/fastmath.curves.html | 2 +- docs/fastmath.distance.html | 2 +- docs/fastmath.easings.html | 2 +- docs/fastmath.efloat.html | 6 +- docs/fastmath.fields.html | 130 +++--- docs/fastmath.gp.html | 82 ++-- docs/fastmath.grid.html | 2 +- docs/fastmath.interpolation.html | 63 +-- docs/fastmath.kernel.html | 46 +- docs/fastmath.matrix.html | 201 +++++---- docs/fastmath.optimization.html | 140 +++--- docs/fastmath.optimization.lbfgsb.html | 4 +- docs/fastmath.protocols.html | 19 +- docs/fastmath.protocols.matrix.html | 2 +- docs/fastmath.quaternion.html | 43 ++ docs/fastmath.random.html | 221 ++++----- docs/fastmath.signal.html | 12 +- docs/fastmath.solver.html | 5 +- docs/fastmath.stats.bootstrap.html | 24 +- docs/fastmath.stats.html | 170 +++---- docs/fastmath.transform.html | 4 +- docs/fastmath.vector.html | 294 ++++++------ docs/index.html | 18 +- src/fastmath/optimization.clj | 123 ++++- test/fastmath/optimization_test.clj | 28 ++ 30 files changed, 1320 insertions(+), 1115 deletions(-) create mode 100644 docs/fastmath.quaternion.html create mode 100644 test/fastmath/optimization_test.clj diff --git a/CHANGELOG.md b/CHANGELOG.md index 0694002a..dc4e64ed 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file. This change * `fastmath.quaternion` namespace * Cholesky decomposition for fixed size matrices * `negative-zero?` tests for `-0.0` value +* `linear-optimizer` - linear optimization ### Changed diff --git a/README.md b/README.md index a47831f5..8451d868 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ Various clustering algorithms including K-Means++, DBSCAN, CLARANS, DENCLUE, MEC ### Optimization -L-BFGS-B, Gradient, Nelder-Mead, Simplex, Powell, BOBYQA, CMAES, BayesianOptimizer +L-BFGS-B, Gradient, Nelder-Mead, Simplex, Powell, BOBYQA, CMAES, BayesianOptimizer, Linear optimizer ### Grids diff --git a/docs/fastmath.clustering.html b/docs/fastmath.clustering.html index 6dc179ea..dd7268e2 100644 --- a/docs/fastmath.clustering.html +++ b/docs/fastmath.clustering.html @@ -1,6 +1,6 @@ -fastmath.clustering documentation

fastmath.clustering

Clustering.

+fastmath.clustering documentation

fastmath.clustering

Clustering.

Various clustering algrorithms backed by SMILE library.

Only partition clustering is implemented.

Input data

@@ -58,9 +58,9 @@

Regrouping

:data :clustering :obj :predict) ;;=> {:clusters 2, -;;=> :info {:distortion 11522.0}, -;;=> :representatives ((1.0) (124.0)), -;;=> :sizes (106 894 0), +;;=> :info {:distortion 11442.0}, +;;=> :representatives ((1.0) (125.0)), +;;=> :sizes (109 891 0), ;;=> :type :clarans}

clustering-methods-list

List of clustering methods.

Examples

List of methods

clustering-methods-list
@@ -92,7 +92,7 @@ 

Regrouping

;;=> {:clusters 8, ;;=> :info {}, ;;=> :representatives nil, -;;=> :sizes (131 1147 1169 1125 1092 122 93 121 0), +;;=> :sizes (1119 1128 1129 1129 147 108 120 120 0), ;;=> :type :dbscan}

denclue

(denclue data sigma m)(denclue data sigma m tolerance)(denclue data sigma m tolerance min-pts)

DENsity CLUstering algorithm.

Input:

    @@ -136,18 +136,18 @@

    Regrouping

    (r/randval (r/grand) (r/grand 5 1.0))))) (deterministic-annealing 4 0.5) (regroup))) -;;=> ({:key 1, -;;=> :representative (0.08901912095860125 5.05141457324412), -;;=> :size 231} -;;=> {:key 3, -;;=> :representative (4.949899452159327 4.998411798416555), -;;=> :size 252} +;;=> ({:key 3, +;;=> :representative (4.981128559374225 4.917380239304928), +;;=> :size 242} +;;=> {:key 1, +;;=> :representative (0.0240693616013261 4.906708467338807), +;;=> :size 246} ;;=> {:key 2, -;;=> :representative (5.169817768215978 -0.04166862180388523), -;;=> :size 256} +;;=> :representative (4.927300741141155 0.06848813585858737), +;;=> :size 263} ;;=> {:key 0, -;;=> :representative (-0.07634736991709429 -0.19863728536737843), -;;=> :size 261})

g-means

(g-means data clusters)(g-means data clusters max-iter)(g-means data clusters max-iter tolerance)

G-Means

+;;=> :representative (0.12708107663316356 -0.14485027403046535), +;;=> :size 249})

g-means

(g-means data clusters)(g-means data clusters max-iter)(g-means data clusters max-iter tolerance)

G-Means

Input:

  • data - sequence of samples
  • @@ -160,7 +160,7 @@

    Regrouping

    ((juxt :clusters :sizes :representatives)
      (g-means (repeatedly 100 (fn* [] (r/randval (r/drand) (r/drand 5 6))))
               4))
    -;;=> [2 (51 49 0) ((0.4772938178957185) (5.477688669526616))]

k-means

(k-means data clusters)(k-means data clusters max-iter)(k-means data clusters max-iter tolerance)

K-Means++ algorithm.

+;;=> [2 (46 54 0) ((5.530726228077052) (0.4718967556076599))]

k-means

(k-means data clusters)(k-means data clusters max-iter)(k-means data clusters max-iter tolerance)

K-Means++ algorithm.

Input:

  • data - sequence of samples
  • @@ -177,11 +177,11 @@

    Regrouping

    ;;=> :data [1 2 3 -1 -1 2 -1 11 111], ;;=> :info {:distortion 2.0000000000000004}, ;;=> :obj -;;=> #object[smile.clustering.KMeans 0x618519cf "Cluster distortion: 2.00000\nCluster size of 9 data points:\nCluster 1 3 (33.3%)\nCluster 2 1 (11.1%)\nCluster 3 1 (11.1%)\nCluster 4 4 (44.4%)\n"], -;;=> :predict #, +;;=> #object[smile.clustering.KMeans 0x3d678abb "Cluster distortion: 2.00000\nCluster size of 9 data points:\nCluster 1 3 (33.3%)\nCluster 2 1 (11.1%)\nCluster 3 1 (11.1%)\nCluster 4 4 (44.4%)\n"], +;;=> :predict #, ;;=> :representatives ((-1.0) (111.0) (11.0) (2.0)), ;;=> :sizes (3 1 1 4 0), -;;=> :type :k-means}

Clusters group into separate maps.

+;;=> :type :k-means}

Clusters group into separate maps.

(regroup (k-means [1 2 3 -1 -1 2 -1 11 111] 4))
 ;;=> ({:data (1 2 3 2), :key 3, :representative (2.0), :size 4}
 ;;=>  {:data (-1 -1 -1), :key 0, :representative (-1.0), :size 3}
@@ -219,10 +219,10 @@ 

Regrouping

20) :data :clustering :obj :predict) -;;=> {:clusters 4, -;;=> :info {:entropy 0.0}, +;;=> {:clusters 5, +;;=> :info {:entropy 123.76475896122787}, ;;=> :representatives nil, -;;=> :sizes (263 2287 2204 246 0), +;;=> :sizes (1067 255 2242 253 1183 0), ;;=> :type :mec}

outlier-id

const

;;=> 2147483647

Id of the cluster which contain outliers.

predict

(predict cluster in)

Predict cluster for given vector

regroup

(regroup {:keys [clustering data representatives sizes]})

Transform clustering result into list of clusters as separate maps.

@@ -238,25 +238,25 @@

Regrouping

Examples

Result of clustering with regrouping

(k-means [1 2 3 -1 -1 2 -1 11 111] 7)
 ;;=> #fastmath.clustering.ClusteringResult
-;;=>  {:clustering (4 0 5 3 3 0 3 2 1),
+;;=>  {:clustering (5 3 4 1 1 3 1 0 2),
 ;;=>   :clusters 7,
 ;;=>   :data [1 2 3 -1 -1 2 -1 11 111],
 ;;=>   :info {:distortion 0.0},
 ;;=>   :obj
-;;=>   #object[smile.clustering.KMeans 0x543ca0a1 "Cluster distortion: 0.00000\nCluster size of 9 data points:\nCluster    1      2 (22.2%)\nCluster    2      1 (11.1%)\nCluster    3      1 (11.1%)\nCluster    4      3 (33.3%)\nCluster    5      1 (11.1%)\nCluster    6      1 (11.1%)\nCluster    7      0 ( 0.0%)\n"],
-;;=>   :predict #,
-;;=>   :representatives ((2.0) (111.0) (11.0) (-1.0) (1.0) (3.0) (##NaN)),
-;;=>   :sizes (2 1 1 3 1 1 0 0),
+;;=>   #object[smile.clustering.KMeans 0x197da505 "Cluster distortion: 0.00000\nCluster size of 9 data points:\nCluster    1      1 (11.1%)\nCluster    2      3 (33.3%)\nCluster    3      1 (11.1%)\nCluster    4      2 (22.2%)\nCluster    5      1 (11.1%)\nCluster    6      1 (11.1%)\nCluster    7      0 ( 0.0%)\n"],
+;;=>   :predict #,
+;;=>   :representatives ((11.0) (-1.0) (111.0) (2.0) (3.0) (1.0) (##NaN)),
+;;=>   :sizes (1 3 1 2 1 1 0 0),
 ;;=>   :type :k-means}
 (regroup (k-means [1 2 3 -1 -1 2 -1 11 111] 7))
 ;;=> ({:data (1), :key 5, :representative (1.0), :size 1}
-;;=>  {:data (2 2), :key 3, :representative (2.0), :size 2}
+;;=>  {:data (2 2), :key 0, :representative (2.0), :size 2}
 ;;=>  {:data (3), :key 4, :representative (3.0), :size 1}
-;;=>  {:data (-1 -1 -1), :key 0, :representative (-1.0), :size 3}
+;;=>  {:data (-1 -1 -1), :key 3, :representative (-1.0), :size 3}
 ;;=>  {:data (11), :key 2, :representative (11.0), :size 1}
 ;;=>  {:data (111), :key 1, :representative (111.0), :size 1})
 (count (regroup (k-means [1 2 3 -1 -1 2 -1 11 111] 7)))
-;;=> 6

spectral

(spectral data clusters sigma)(spectral data clusters sigma max-iters tolerance)(spectral data clusters samples sigma)(spectral data clusters samples sigma max-iters tolerance)

Spectral clustering

+;;=> 6

spectral

(spectral data clusters sigma)(spectral data clusters sigma max-iters tolerance)(spectral data clusters samples sigma)(spectral data clusters samples sigma max-iters tolerance)

Spectral clustering

Input:

  • data - sequence of samples
  • @@ -279,9 +279,9 @@

    Regrouping

    :data :clustering :obj :predict) ;;=> {:clusters 4, -;;=> :info {:distortion 32.57089991186055}, +;;=> :info {:distortion 35.370075541146754}, ;;=> :representatives nil, -;;=> :sizes (133 264 81 22 0), +;;=> :sizes (132 268 96 4 0), ;;=> :type :spectral}

2d vectors

(dissoc (lloyd
          (repeatedly
@@ -294,12 +294,12 @@ 

Regrouping

:data :clustering :obj :predict) ;;=> {:clusters 4, -;;=> :info {:distortion 319781.50713524147}, -;;=> :representatives ((121.62222222222222 124.56888888888889) -;;=> (-0.3235294117647059 47.1764705882353) -;;=> (138.4607843137255 0.23529411764705882) -;;=> (115.3021582733813 -0.26618705035971224)), -;;=> :sizes (225 34 102 139 0), +;;=> :info {:distortion 150979.2782140331}, +;;=> :representatives ((124.51690821256038 123.1304347826087) +;;=> (-1.7142857142857142 130.17857142857142) +;;=> (-0.5806451612903226 0.0) +;;=> (123.24358974358974 0.13675213675213677)), +;;=> :sizes (207 28 31 234 0), ;;=> :type :lloyd}

x-means

(x-means data clusters)(x-means data clusters max-iter)(x-means data clusters max-iter tolerance)

X-Means

Input:

    @@ -314,4 +314,4 @@

    Regrouping

    (x-means (repeatedly 10000 (fn* [] (r/randval (r/grand) (r/grand 5 1.0)))) 4)) -;;=> [2 (4924 5076 0) ((5.005016732578154) (-0.01610911384093022))]
\ No newline at end of file +;;=> [2 (4997 5003 0) ((5.030492889086659) (-0.009684743016128554))]
\ No newline at end of file diff --git a/docs/fastmath.complex.html b/docs/fastmath.complex.html index 8512c2bc..ebd3bd3f 100644 --- a/docs/fastmath.complex.html +++ b/docs/fastmath.complex.html @@ -1,133 +1,141 @@ -fastmath.complex documentation

fastmath.complex

Complex numbers functions.

+fastmath.complex documentation

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.

-

Complex plane (identity) looks as follows:

-

identity

-

abs

Absolute value

+

Implementation checks for ##Inf, ##NaN and some of the function distinguish +0.0 and -0.0

+

abs

(abs z)

Absolute value, magnitude

Examples

Abs

(abs (complex 1 -3))
-;;=> 3.1622776601683795

acos

(acos z)

acos

+;;=> 3.1622776601683795

acos

(acos z)

acos

Examples

acos(z)

(acos (complex 2 -1))
-;;=> [0.5073563032171449 1.4693517443681863]

Plot of acos

-

acosech

(acosech z)

acosech

-

acosh

(acosh z)

acosh

-

acoth

(acoth z)

sech

-

acsch

(acsch z)

sech

-

add

Sum of two complex numbers.

+;;=> [0.5073563032171444 1.4693517443681854]

Plot of acos

+

acosh

(acosh z)

acosh

+

acot

(acot z)

acot

+

acoth

(acoth z)

acsc

(acsc z)

acsc

+

acsch

(acsch z)

add

(add z1 z2)

Sum of two complex numbers

Examples

Sum

(add I ONE)
-;;=> [1.0 1.0]

arg

Argument (angle) of complex number.

+;;=> [1.0 1.0]

arg

(arg z)

Argument (angle) of the complex number

Examples

Argument

(m/degrees (arg I-))
-;;=> -90.0

asech

(asech z)

sech

-

asin

(asin z)

asin

+;;=> -90.0

asec

(asec z)

asec

+

asech

(asech z)

asin

(asin z)

asin

Examples

asin(z)

(asin (complex 2 -1))
-;;=> [1.0634400235777521 -1.4693517443681852]

Plot of asin

-

asinh

(asinh z)

asinh

-

atan

(atan z)

atan

+;;=> [1.0634400235777521 -1.4693517443681854]

Plot of asin

+

asinh

(asinh z)

asinh

+

atan

(atan z)

atan

Examples

atan(z)

(atan (complex 2 -1))
-;;=> [1.1780972450961724 -0.1732867951399863]

Plot of atan

-

atanh

(atanh z)

atanh

-

complex

(complex a b)(complex a)(complex)

Create complex number. Represented as Vec2.

+;;=> [1.1780972450961724 -0.17328679513998632]

Plot of atan

+

atanh

(atanh z)

atanh

+

complex

(complex a b)(complex a)(complex)

Create complex number. Represented as Vec2.

Examples

New complex number.

(complex 2 -1)
-;;=> [2.0 -1.0]

conjugate

(conjugate z)

Complex conjugate. \(\bar{z}\)

+;;=> [2.0 -1.0]

conjugate

(conjugate z)

Complex conjugate. \(\bar{z}\)

Examples

Conjugate

(conjugate I)
-;;=> [0.0 -1.0]

cos

(cos z)

cos

+;;=> [0.0 -1.0]

cos

(cos z)

cos

Examples

cos(z)

(cos (complex 2 -1))
 ;;=> [-0.6421481247155197 1.0686074213827785]

Plot of cos

-

cosh

(cosh z)

cosh

+

cosh

(cosh z)

cosh

Examples

cosh(z)

(cosh (complex 2 -1))
 ;;=> [2.0327230070196656 -3.0518977991517997]

Plot of cosh

-

coth

(coth z)

coth

-

csc

(csc z)

cosecant

+

cot

(cot z)

csc

+

coth

(coth z)

coth

+

csc

(csc z)

csc

Examples

csc(z)

(csc (complex 2 -1))
-;;=> [0.6354937992539001 -0.22150093085050934]

Plot of csc

-

csch

(csch z)

cosech

-

div

(div z1 z2)

Divide two complex numbers.

+;;=> [0.6354937992538998 -0.22150093085050923]

Plot of csc

+

csch

(csch z)

csch

+

csgn

(csgn re im)(csgn z)

Complex sgn.

+

Returns 0 for 0+0i or calls m/sgn on real part otherwise.

+

delta-eq

(delta-eq q1 q2)(delta-eq q1 q2 accuracy)

Compare complex numbers with given accuracy (10e-6 by default)

+

div

(div z1 z2)

Divide two complex numbers.

Examples

Divide

(div (complex 1 2) (complex 3 4))
-;;=> [0.44 0.08]

exp

(exp z)

exp

+;;=> [0.44 0.08]

exp

(exp z)

exp

Examples

exp(z)

(exp (complex 2 -1))
 ;;=> [3.992324048441272 -6.217676312367968]

\(e^{i\pi}+1\)

(add (exp (complex 0 m/PI)) ONE)
 ;;=> [0.0 1.224646799076922E-16]

Plot of exp

-

flip

(flip z)

Exchange imaginary and real parts

-

im

(im z)

Imaginary part

-

log

(log z)

log

+

flip

(flip z)

Exchange imaginary and real parts

+

im

(im z)

Imaginary part

+

imaginary?

(imaginary? z)

Is z is a pure imaginary number?

+

inf?

(inf? z)

Is infinite?

+

log

(log z)

log, principal value

Examples

log(z)

(log (complex 2 -1))
-;;=> [0.8047189562170503 -0.4636476090008061]

log(e)

+;;=> [0.8047189562170501 -0.4636476090008061]

log(e)

(log (complex m/E 0))
 ;;=> [1.0 0.0]

Plot of log

-

mult

(mult z1 z2)

Multiply two complex numbers.

+

logb

(logb z b)

log with base b

+

mult

(mult z1 z2)

Multiply two complex numbers.

Examples

Multiply

(mult (complex 1 2) (complex 3 4))
-;;=> [-5.0 10.0]

mult-I

(mult-I z)

mult-I-

(mult-I- z)

neg

(neg z)

Negate complex number. \(-z\)

+;;=> [-5.0 10.0]

mult-I

(mult-I z)

mult-I-

(mult-I- z)

nan?

(nan? z)

Is NaN?

+

neg

(neg z)

Negate complex number. \(-z\)

Examples

Negate.

(neg (complex 1 2))
-;;=> [-1.0 -2.0]

pow

(pow z1 z2)

Power. \(z_1^{z_2}\)

+;;=> [-1.0 -2.0]

norm

(norm z)

Norm (Guass) of the complex number, absolute value squared

+

pow

(pow z1 z2)

Power. \(z_1^{z_2}\)

Examples

\(\sqrt{2}\)

(pow TWO (complex 0.5 0.0))
 ;;=> [1.4142135623730951 0.0]

Complex power

(pow (complex 1 2) (complex 3 4))
-;;=> [0.12900959407446697 0.03392409290517014]

re

(re z)

Real part

-

reciprocal

(reciprocal z)

\(\frac{1}{z}\)

+;;=> [0.12900959407446694 0.03392409290517002]

re

(re z)

Real part

+

real?

(real? z)

Is z is a real number?

+

reciprocal

(reciprocal z)

\(\frac{1}{z}\)

Examples

Reciprocal of real

(reciprocal TWO)
-;;=> [0.5 0.0]

Reciprocal of complex

+;;=> [0.5 -0.0]

Reciprocal of complex

(reciprocal (complex 0 2))
 ;;=> [0.0 -0.5]

Plot of reciprocal

-

scale

Scale number

-

sec

(sec z)

secant

+

scale

(scale z v)

Multiply by real number

+

sec

(sec z)

sec

Examples

sec(z)

(sec (complex 2 -1))
-;;=> [-0.41314934426693994 -0.6875274386554792]

Plot of sec

-

sech

(sech z)

sech

-

sin

(sin z)

sin

+;;=> [-0.4131493442669398 -0.687527438655479]

Plot of sec

+

sech

(sech z)

sech

+

sin

(sin z)

sin

Examples

sin(z)

(sin (complex 2 -1))
 ;;=> [1.403119250622041 0.4890562590412935]

Plot of sin

-

sinh

(sinh z)

sinh

+

sinh

(sinh z)

sinh

Examples

sinh(z)

(sinh (complex 2 -1))
 ;;=> [1.9596010414216063 -3.1657785132161678]

Plot of sinh

-

sq

(sq z)

Square complex number. \(z^2\)

+

sq

(sq z)

Square complex number. \(z^2\)

Examples

Square.

(sq (complex 1 2))
 ;;=> [-3.0 4.0]

\(i^2\)

(sq I)
 ;;=> [-1.0 0.0]

Plot of sq

-

sqrt

(sqrt z)

Sqrt of complex number. \(\sqrt{z}\)

+

sqrt

(sqrt z)

Sqrt of complex number. \(\sqrt{z}\)

Examples

Square root of real.

(sqrt (complex 2 0))
 ;;=> [1.4142135623730951 0.0]

Square root of complex.

(sqrt (complex 2 2))
 ;;=> [1.5537739740300376 0.6435942529055827]

Plot of sqrt

-

sqrt1z

(sqrt1z z)

\(\sqrt{1-z^2}\)

+

sqrt1z

(sqrt1z z)

\(\sqrt{1-z^2}\)

Examples

Example 1

(sqrt1z (complex 2 3))
 ;;=> [3.115799084103365 -1.9256697360916721]

Plot of sqrt1z

-

sub

Subtraction of two complex numbers.

+

sub

(sub z1 z2)

Difference of two complex numbers

Examples

Subtract

(sub ONE I-)
-;;=> [1.0 1.0]

tan

(tan z)

tan

+;;=> [1.0 1.0]

tan

(tan z)

tan

Examples

tan(z)

(tan (complex 2 -1))
-;;=> [-0.2434582011857252 -1.1667362572409201]

Plot of tan

-

tanh

(tanh z)

tanh

+;;=> [-0.24345820118572514 -1.16673625724092]

Plot of tan

+

tanh

(tanh z)

tanh

Examples

tanh(z)

(tanh (complex 2 -1))
-;;=> [1.0147936161466335 -0.0338128260798967]

Plot of tanh

-
\ No newline at end of file +;;=> [1.0147936161466335 -0.033812826079896684]

Plot of tanh

+

zero?

(zero? z)

Is zero?

+
\ No newline at end of file diff --git a/docs/fastmath.core.html b/docs/fastmath.core.html index f39e8285..f9084ba6 100644 --- a/docs/fastmath.core.html +++ b/docs/fastmath.core.html @@ -1,6 +1,6 @@ -fastmath.core documentation

fastmath.core

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

+fastmath.core documentation

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-and-not bit-set bit-clear bit-test bit-flip bit-not bit-shift-left bit-shift-right unsigned-bit-shift-right inc dec zero? neg? pos? min max even? odd? abs

@@ -17,17 +17,17 @@

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.

-

Categories

    Other vars: * + - / < << <= == > >= >> >>> Ci I0 Si abs acos acosh acot acoth acovercos acoversin acrd acsc acsch aexcsc aexsec ahacovercos ahacoversin ahavercos ahaversin approx approx-eq approx= asec asech asin asinh atan atan2 atanh avercos aversin bessel-j between-? between? bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-test bit-xor bits->double bool-and bool-not bool-or bool-xor cb cbrt ceil cexpexp cloglog cnorm co-intervals combinations constrain copy-sign cos cos-interpolation cosh cot coth covercos coversin crd csc csch cut dec degrees delta-eq delta= difference-of-products digamma dist double-array->seq double-bits double-double-array->seq double-high-bits double-low-bits eq erf erfc evalpoly even? excsc exp expm1 exsec factorial factorial20 fast* fast+ fast- fast-identity fast-max fast-min floor fma fpow frac gamma gcd group-by-intervals hacovercos hacoversin havercos haversin haversine haversine-dist high-2-exp high-exp hypot hypot-sqrt iabs inc inf? inv-erf inv-erfc inv-gamma-1pm1 invalid-double? itrunc jinc lcm lerp ln log log-I0 log-beta log-combinations log-factorial log-gamma log-gamma-1p log10 log1mexp log1p log1pexp log1pmx log1psq log2 log2mexp logaddexp logb logcosh logexpm1 logistic logit logmxp1 logsubexp logsumexp low-2-exp low-exp make-norm makepoly max mevalpoly min minkowski mlerp mnorm mod muladd nan? neg-inf? neg? negmuladd next-double norm not-neg? not-pos? not== odd? one? order pos-inf? pos? pow pow2 pow3 prev-double qceil qcos qdist qexp qfloor qlog qpow qround qsin qsqrt quad-interpolation quot radians rank rank1 regularized-beta regularized-gamma-p regularized-gamma-q rem remainder rint round round-even round-up-pow2 rqsqrt safe-sqrt sample sec sech seq->double-array seq->double-double-array sfrac sgn sigmoid signum sin sinc sinh slice-range smooth-interpolation smoothstep sq sqrt sum-of-products tan tanh trigamma trunc unsigned-bit-shift-right unuse-primitive-operators use-primitive-operators valid-double? vercos versin wrap xexpx xexpy xlog1py xlogx xlogy zero?

    Constants

    *

    macro

    (* x)(* x y)(* x y & rest)

    A primitive math version of *

    +

    Categories

      Other vars: * + - / < << <= == > >= >> >>> Ci I0 Si abs acos acosh acot acoth acovercos acoversin acrd acsc acsch aexcsc aexsec ahacovercos ahacoversin ahavercos ahaversin approx approx-eq approx= asec asech asin asinh atan atan2 atanh avercos aversin bessel-j between-? between? bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-test bit-xor bits->double bool-and bool-not bool-or bool-xor cb cbrt ceil cexpexp cloglog cnorm co-intervals combinations constrain copy-sign cos cos-interpolation cosh cot coth covercos coversin crd csc csch cut dec degrees delta-eq delta= difference-of-products digamma dist double-array->seq double-bits double-double-array->seq double-exponent double-high-bits double-low-bits double-significand eq erf erfc evalpoly even? excsc exp expm1 exsec factorial factorial20 fast* fast+ fast- fast-identity fast-max fast-min floor fma fpow frac gamma gcd group-by-intervals hacovercos hacoversin havercos haversin haversine haversine-dist high-2-exp high-exp hypot hypot-sqrt iabs inc inf? inv-erf inv-erfc inv-gamma-1pm1 invalid-double? itrunc jinc lcm lerp ln log log-I0 log-beta log-combinations log-factorial log-gamma log-gamma-1p log10 log1mexp log1p log1pexp log1pmx log1psq log2 log2int log2mexp logaddexp logb logcosh logexpm1 logistic logit logmxp1 logsubexp logsumexp low-2-exp low-exp make-norm makepoly max mevalpoly min minkowski mlerp mnorm mod muladd nan? neg-inf? neg? negative-zero? negmuladd next-double norm not-neg? not-pos? not== odd? one? order pos-inf? pos? pow pow2 pow3 prev-double qceil qcos qdist qexp qfloor qlog qpow qround qsin qsqrt quad-interpolation quot radians rank rank1 regularized-beta regularized-gamma-p regularized-gamma-q rem remainder rint round round-even round-up-pow2 rqsqrt safe-sqrt sample sec sech seq->double-array seq->double-double-array sfrac sgn sigmoid signum sin sinc sinh slice-range smooth-interpolation smoothstep sq sqrt sum-of-products tan tanh trigamma trunc ulp unsigned-bit-shift-right unuse-primitive-operators use-primitive-operators valid-double? vercos versin wrap xexpx xexpy xlog1py xlogx xlogy zero?

      Constants

      *

      macro

      (* x)(* x y)(* x y & rest)

      A primitive math version of *

      +

      macro

      (+ x)(+ x y)(+ x y & rest)

      A primitive math version of +

      -

      macro

      (- x)(- x y)(- x y & rest)

      A primitive math version of -

      -E

      const

      ;;=> -2.718281828459045

      Value of \(-e\)

      -

      -HALF_PI

      const

      ;;=> -1.5707963267948966

      Value of \(-\frac{\pi}{2}\)

      -

      -PI

      const

      ;;=> -3.141592653589793

      Value of \(-\pi\)

      -

      -QUARTER_PI

      const

      ;;=> -0.7853981633974483

      Value of \(-\frac{\pi}{4}\)

      -

      -TAU

      const

      ;;=> -6.283185307179586

      Alias for TWO_PI-

      -

      -THIRD_PI

      const

      ;;=> 1.0471975511965976

      Value of \(-\frac{\pi}{3}\)

      -

      -TWO_PI

      const

      ;;=> -6.283185307179586

      Value of \(-2 {\pi}\)

      -

      /

      macro

      (/ x)(/ x y)(/ x y & rest)

      A primitive math version of /

      +

      -HALF_PI

      const

      ;;=> -1.5707963267948966

      Value of \(-\frac{\pi}{2}\)

      +

      -PI

      const

      ;;=> -3.141592653589793

      Value of \(-\pi\)

      +

      -QUARTER_PI

      const

      ;;=> -0.7853981633974483

      Value of \(-\frac{\pi}{4}\)

      +

      -TAU

      const

      ;;=> -6.283185307179586

      Alias for TWO_PI-

      +

      -THIRD_PI

      const

      ;;=> 1.0471975511965976

      Value of \(-\frac{\pi}{3}\)

      +

      -TWO_PI

      const

      ;;=> -6.283185307179586

      Value of \(-2 {\pi}\)

      +

      /

      macro

      (/ x)(/ x y)(/ x y & rest)

      A primitive math version of /

      <

      macro

      (< x)(< x y)(< x y & rest)

      A primitive math version of <

      <<

      macro

      (<< x y)

      fastmath.java.PrimitiveMath/shiftLeft function wrapped in macro.

      <=

      macro

      (<= x)(<= x y)(<= x y & rest)

      A primitive math version of <=

      @@ -40,73 +40,73 @@

      Other functions

      Examples

      Usage

      (fastmath.core/abs 1.0)
       ;;=> 1.0

      Plot of abs

      -

      acos

      macro

      (acos x)

      net.jafama.FastMath/acos function wrapped in macro.

      +

      acos

      macro

      (acos x)

      net.jafama.FastMath/acos function wrapped in macro.

      Examples

      Usage

      (fastmath.core/acos 1.0)
       ;;=> 0.0

      Plot of acos

      -

      acosh

      macro

      (acosh x)

      net.jafama.FastMath/acosh function wrapped in macro.

      +

      acosh

      macro

      (acosh x)

      net.jafama.FastMath/acosh function wrapped in macro.

      Examples

      Usage

      (fastmath.core/acosh 1.0)
       ;;=> 0.0

      Plot of acosh

      -

      acot

      (acot v)

      Arccotangent

      +

      acot

      (acot v)

      Arccotangent

      Examples

      Usage

      (fastmath.core/acot 1.0)
       ;;=> 0.7853981633974483

      Plot of acot

      -

      acoth

      (acoth v)

      Area hyperbolic cotangent

      +

      acoth

      (acoth v)

      Area hyperbolic cotangent

      Examples

      Usage

      (fastmath.core/acoth 1.0)
       ;;=> Infinity

      Plot of acoth

      -

      acovercos

      (acovercos v)

      Arc covercosine

      -

      acoversin

      (acoversin v)

      Arc coversine

      -

      acrd

      (acrd v)

      Inverse chord

      -

      acsc

      (acsc v)

      Arcosecant

      +

      acovercos

      (acovercos v)

      Arc covercosine

      +

      acoversin

      (acoversin v)

      Arc coversine

      +

      acrd

      (acrd v)

      Inverse chord

      +

      acsc

      (acsc v)

      Arcosecant

      Examples

      Usage

      (fastmath.core/acsc 1.0)
       ;;=> 1.5707963267948966

      Plot of acsc

      -

      acsch

      (acsch v)

      Area hyperbolic cosecant

      +

      acsch

      (acsch v)

      Area hyperbolic cosecant

      Examples

      Usage

      (fastmath.core/acsch 1.0)
       ;;=> 0.8813735870195429

      Plot of acsch

      -

      aexcsc

      (aexcsc v)

      Arc excosecant

      -

      aexsec

      (aexsec v)

      Arc exsecant

      -

      ahacovercos

      (ahacovercos v)

      Arc hacovercosine

      -

      ahacoversin

      (ahacoversin v)

      Arc hacoversine

      -

      ahavercos

      (ahavercos v)

      Arc havecosine

      -

      ahaversin

      (ahaversin v)

      Arc haversine

      -

      approx

      (approx v)(approx v digits)

      Round v to specified (default: 2) decimal places. Be aware of double number accuracy.

      +

      aexcsc

      (aexcsc v)

      Arc excosecant

      +

      aexsec

      (aexsec v)

      Arc exsecant

      +

      ahacovercos

      (ahacovercos v)

      Arc hacovercosine

      +

      ahacoversin

      (ahacoversin v)

      Arc hacoversine

      +

      ahavercos

      (ahavercos v)

      Arc havecosine

      +

      ahaversin

      (ahaversin v)

      Arc haversine

      +

      approx

      (approx v)(approx v digits)

      Round v to specified (default: 2) decimal places. Be aware of double number accuracy.

      Examples

      Default rounding (2 digits).

      (approx 1.232323)
       ;;=> 1.23

      Rounding up to 4 digits.

      (approx 1.232323 4)
      -;;=> 1.2323

      approx-eq

      (approx-eq a b)(approx-eq a b digits)

      Checks equality approximately. See approx.

      +;;=> 1.2323

      approx-eq

      (approx-eq a b)(approx-eq a b digits)

      Checks equality approximately. See approx.

      Examples

      Default rounding (2 digits).

      (approx-eq 1.232323 1.231999)
       ;;=> true

      Rounding up to 4 digits.

      (approx-eq 1.232323 1.23231999 4)
       ;;=> true

      Keep an eye on rounding

      (approx-eq 1.2349 1.235)
      -;;=> false

      approx=

      Alias for approx-eq

      -

      asec

      (asec v)

      Arcsecant

      +;;=> false

      approx=

      Alias for approx-eq

      +

      asec

      (asec v)

      Arcsecant

      Examples

      Usage

      (fastmath.core/asec 1.0)
       ;;=> 0.0

      Plot of asec

      -

      asech

      (asech v)

      Area hyperbolic secant

      +

      asech

      (asech v)

      Area hyperbolic secant

      Examples

      Usage

      (fastmath.core/asech 1.0)
       ;;=> 0.0

      Plot of asech

      -

      asin

      macro

      (asin x)

      net.jafama.FastMath/asin function wrapped in macro.

      +

      asin

      macro

      (asin x)

      net.jafama.FastMath/asin function wrapped in macro.

      Examples

      Usage

      (fastmath.core/asin 1.0)
       ;;=> 1.5707963267948966

      Plot of asin

      -

      asinh

      macro

      (asinh x)

      net.jafama.FastMath/asinh function wrapped in macro.

      +

      asinh

      macro

      (asinh x)

      net.jafama.FastMath/asinh function wrapped in macro.

      Examples

      Usage

      (fastmath.core/asinh 1.0)
       ;;=> 0.8813735870195429

      Plot of asinh

      -

      atan

      macro

      (atan x)

      net.jafama.FastMath/atan function wrapped in macro.

      +

      atan

      macro

      (atan x)

      net.jafama.FastMath/atan function wrapped in macro.

      Examples

      Usage

      (fastmath.core/atan 1.0)
       ;;=> 0.7853981633974483

      Plot of atan

      -

      atan2

      macro

      (atan2 x y)

      net.jafama.FastMath/atan2 function wrapped in macro.

      +

      atan2

      macro

      (atan2 x y)

      net.jafama.FastMath/atan2 function wrapped in macro.

      Examples

      atan2 values

      (degrees (atan2 1 1))
       ;;=> 45.0
      @@ -114,13 +114,13 @@ 

      Other functions

      ;;=> 0.0 (degrees (atan2 0 -1)) ;;=> 180.0

      Plot of atan2

      -

      atanh

      macro

      (atanh x)

      net.jafama.FastMath/atanh function wrapped in macro.

      +

      atanh

      macro

      (atanh x)

      net.jafama.FastMath/atanh function wrapped in macro.

      Examples

      Usage

      (fastmath.core/atanh 1.0)
       ;;=> Infinity

      Plot of atanh

      -

      avercos

      (avercos v)

      Arc vecosine

      -

      aversin

      (aversin v)

      Arc versine

      -

      bessel-j

      macro

      (bessel-j x y)

      Bessel J function value for given order and argument.

      +

      avercos

      (avercos v)

      Arc vecosine

      +

      aversin

      (aversin v)

      Arc versine

      +

      bessel-j

      macro

      (bessel-j x y)

      Bessel J function value for given order and argument.

      Examples

      bessel-j values

      (bessel-j 1 1)
       ;;=> 0.44005058574493355
      @@ -128,8 +128,8 @@ 

      Other functions

      ;;=> 0.7651976865579666 (bessel-j 0 10) ;;=> -0.24593576445134827

      Plot of bessel-j

      -

      between-?

      (between-? [x y] v)(between-? x y v)

      Check if given number is within the range (x,y].

      -

      between?

      (between? [x y] v)(between? x y v)

      Check if given number is within the range x,y.

      +

      between-?

      (between-? [x y] v)(between-? x y v)

      Check if given number is within the range (x,y].

      +

      between?

      (between? [x y] v)(between? x y v)

      Check if given number is within the range x,y.

      Examples

      Examples

      (between? [1 4] 2)
       ;;=> true
      @@ -148,7 +148,7 @@ 

      Other functions

      (between? 1 4 1) ;;=> true -;; Test: ok.

      bit-and

      macro

      (bit-and x)(bit-and x y)(bit-and x y & rest)

      A primitive math version of bit-and

      +;; Test: ok.

      bit-and

      macro

      (bit-and x)(bit-and x y)(bit-and x y & rest)

      A primitive math version of bit-and

      bit-and-not

      macro

      (bit-and-not x)(bit-and-not x y)(bit-and-not x y & rest)

      A primitive math version of bit-and-not

      bit-clear

      macro

      (bit-clear x y)

      fastmath.java.PrimitiveMath/bitClear function wrapped in macro.

      bit-flip

      macro

      (bit-flip x y)

      fastmath.java.PrimitiveMath/bitFlip function wrapped in macro.

      @@ -160,20 +160,20 @@

      Other functions

      bit-test

      macro

      (bit-test x y)

      fastmath.java.PrimitiveMath/bitTest function wrapped in macro.

      bit-xor

      macro

      (bit-xor x)(bit-xor x y)(bit-xor x y & rest)

      A primitive math version of bit-xor

      bits->double

      (bits->double v)

      Convert 64 bits to double

      -

      bool-and

      macro

      deprecated

      (bool-and x)(bool-and x y)(bool-and x y & rest)

      A primitive math version of bool-and

      +

      bool-and

      macro

      deprecated

      (bool-and x)(bool-and x y)(bool-and x y & rest)

      A primitive math version of bool-and

      bool-not

      macro

      (bool-not x)

      fastmath.java.PrimitiveMath/not function wrapped in macro.

      bool-or

      macro

      deprecated

      (bool-or x)(bool-or x y)(bool-or x y & rest)

      A primitive math version of bool-or

      bool-xor

      macro

      deprecated

      (bool-xor x)(bool-xor x y)(bool-xor x y & rest)

      A primitive math version of bool-xor

      CATALAN_G

      const

      ;;=> 0.915965594177219

      Catalan G

      -

      cb

      (cb x)

      \(x^3\)

      +

      cb

      (cb x)

      \(x^3\)

      Examples

      Usage

      (fastmath.core/cb 1.0)
       ;;=> 1.0

      Plot of cb

      -

      cbrt

      macro

      (cbrt x)

      \(\sqrt3{x}\)

      +

      cbrt

      macro

      (cbrt x)

      \(\sqrt3{x}\)

      Examples

      Usage

      (fastmath.core/cbrt 1.0)
       ;;=> 1.0

      Plot of cbrt

      -

      ceil

      (ceil x)(ceil x scale)

      \(\lceil x \rceil\). See: qceil.

      +

      ceil

      (ceil x)(ceil x scale)

      \(\lceil x \rceil\). See: qceil.

      Rounding is done to a multiply of scale value (when provided).

      Examples

      Scaled ceil

      (ceil 234.312 10)
      @@ -184,120 +184,122 @@ 

      Other functions

      ;; Test: ok.

      Usage

      (fastmath.core/ceil 1.0)
       ;;=> 1.0

      Plot of ceil

      -

      cexpexp

      (cexpexp x)

      1-exp(-exp(x))

      -

      Ci

      (Ci x)

      Negative of integral of cos(t)/t from x to inf

      -

      cloglog

      (cloglog x)

      log(-log(1-x))

      -

      cnorm

      (cnorm v start1 stop1 start2 stop2)(cnorm v start stop)

      Constrained version of norm. Result of norm is applied to constrain to [0,1] or [start2,stop2] ranges.

      +

      cexpexp

      (cexpexp x)

      1-exp(-exp(x))

      +

      Ci

      (Ci x)

      Negative of integral of cos(t)/t from x to inf

      +

      cloglog

      (cloglog x)

      log(-log(1-x))

      +

      cnorm

      (cnorm v start1 stop1 start2 stop2)(cnorm v start stop)

      Constrained version of norm. Result of norm is applied to constrain to [0,1] or [start2,stop2] ranges.

      Examples

      Constrain result of norm.

      (cnorm 1.5 0 1 100 200)
       ;;=> 200.0
       (cnorm 555 200 500)
      -;;=> 1.0

      co-intervals

      (co-intervals data)(co-intervals data number)(co-intervals data number overlap)

      Divide sequence to overlaping intervals containing similar number of values. Same as R’s co.intervals()

      +;;=> 1.0

      co-intervals

      (co-intervals data)(co-intervals data number)(co-intervals data number overlap)

      Divide sequence to overlaping intervals containing similar number of values. Same as R’s co.intervals()

      Examples

      Usage

      (co-intervals [1 2 3 1 2 3 4 5 6 1 2 3 4 5 6 7 1 1 1 1 -1])
       ;;=> ([-1.5 1.5] [0.5 2.5] [0.5 3.5] [1.5 4.5] [2.5 5.5] [3.5 7.5])

      Higher overlap

      (co-intervals [1 2 3 1 2 3 4 5 6 1 2 3 4 5 6 7 1 1 1 1 -1] 5 0.95)
      -;;=> ([-1.5 5.5] [0.5 5.5] [0.5 6.5] [0.5 7.5])

      combinations

      (combinations n k)

      Binomial coefficient (n choose k)

      -

      constrain

      macro

      (constrain value mn mx)

      Clamp value to the range [mn,mx].

      +;;=> ([-1.5 5.5] [0.5 5.5] [0.5 6.5] [0.5 7.5])

      combinations

      (combinations n k)

      Binomial coefficient (n choose k)

      +

      constrain

      macro

      (constrain value mn mx)

      Clamp value to the range [mn,mx].

      Examples

      Examples

      (constrain 0.5 1 2)
       ;;=> 1.0
       (constrain 1.5 1 2)
       ;;=> 1.5
       (constrain 2.5 1 2)
      -;;=> 2.0

      copy-sign

      macro

      (copy-sign x y)

      Returns a value with a magnitude of first argument and sign of second.

      -

      cos

      macro

      (cos x)

      net.jafama.FastMath/cos function wrapped in macro.

      +;;=> 2.0

      copy-sign

      macro

      (copy-sign x y)

      Returns a value with a magnitude of first argument and sign of second.

      +

      cos

      macro

      (cos x)

      net.jafama.FastMath/cos function wrapped in macro.

      Examples

      Usage

      (fastmath.core/cos 1.0)
       ;;=> 0.5403023058681398

      Plot of cos

      -

      cos-interpolation

      (cos-interpolation start stop t)

      oF interpolateCosine interpolation. See also lerp/mlerp, quad-interpolation or smooth-interpolation.

      +

      cos-interpolation

      (cos-interpolation start stop t)

      oF interpolateCosine interpolation. See also lerp/mlerp, quad-interpolation or smooth-interpolation.

      Examples

      Example

      (cos-interpolation 0.0 1.0 0.123)
       ;;=> 0.03686712449046664

      Plot of cos-interpolation

      -

      cosh

      macro

      (cosh x)

      net.jafama.FastMath/cosh function wrapped in macro.

      +

      cosh

      macro

      (cosh x)

      net.jafama.FastMath/cosh function wrapped in macro.

      Examples

      Usage

      (fastmath.core/cosh 1.0)
       ;;=> 1.543080634815244

      Plot of cosh

      -

      cot

      (cot v)

      Cotangent

      +

      cot

      (cot v)

      Cotangent

      Examples

      Usage

      (fastmath.core/cot 1.0)
      -;;=> 0.6420926159343308

      Plot of cot

      -

      coth

      (coth v)

      Hyperbolic cotangent

      +;;=> 0.6420926159343309

      Plot of cot

      +

      coth

      (coth v)

      Hyperbolic cotangent

      Examples

      Usage

      (fastmath.core/coth 1.0)
       ;;=> 1.3130352854993315

      Plot of coth

      -

      covercos

      (covercos v)

      Covercosine

      -

      coversin

      (coversin v)

      Coversine

      -

      crd

      (crd v)

      Chord

      -

      csc

      (csc v)

      Cosecant

      +

      covercos

      (covercos v)

      Covercosine

      +

      coversin

      (coversin v)

      Coversine

      +

      crd

      (crd v)

      Chord

      +

      csc

      (csc v)

      Cosecant

      Examples

      Usage

      (fastmath.core/csc 1.0)
       ;;=> 1.1883951057781215

      Plot of csc

      -

      csch

      (csch v)

      Hyperbilic cosecant

      +

      csch

      (csch v)

      Hyperbilic cosecant

      Examples

      Usage

      (fastmath.core/csch 1.0)
       ;;=> 0.8509181282393214

      Plot of csch

      -

      cut

      (cut data breaks)(cut x1 x2 breaks)

      Cut range or sequence into intervals

      -

      dec

      macro

      (dec x)

      fastmath.java.PrimitiveMath/dec function wrapped in macro.

      +

      cut

      (cut data breaks)(cut x1 x2 breaks)

      Cut range or sequence into intervals

      +

      dec

      macro

      (dec x)

      fastmath.java.PrimitiveMath/dec function wrapped in macro.

      deg-in-rad

      const

      ;;=> 0.017453292519943295

      \(\frac{\pi}{180}\)

      -

      degrees

      (degrees rad)

      Convert radians into degrees.

      +

      degrees

      (degrees rad)

      Convert radians into degrees.

      Examples

      Let’s convert \(\pi\) radians to degrees.

      (degrees PI)
      -;;=> 180.0

      delta-eq

      (delta-eq a b)(delta-eq a b accuracy)

      Checks equality for given accuracy (default 1.0e-6).

      -

      delta=

      Alias for delta-eq

      -

      difference-of-products

      (difference-of-products a b c d)

      Kahan’s algorithm for (ab)-(cd) to avoid catastrophic cancellation.

      -

      digamma

      macro

      (digamma x)

      Logarithmic derivative of \(\Gamma\).

      +;;=> 180.0

      delta-eq

      (delta-eq a b)(delta-eq a b accuracy)

      Checks equality for given accuracy (default 1.0e-6).

      +

      delta=

      Alias for delta-eq

      +

      difference-of-products

      (difference-of-products a b c d)

      Kahan’s algorithm for (ab)-(cd) to avoid catastrophic cancellation.

      +

      digamma

      macro

      (digamma x)

      Logarithmic derivative of \(\Gamma\).

      Examples

      Usage

      (fastmath.core/digamma 1.0)
       ;;=> -0.5772156677920679

      Plot of digamma

      -

      dist

      (dist [x1 y1] [x2 y2])(dist x1 y1 x2 y2)

      Euclidean distance between points (x1,y1) and (x2,y2). See fastmath.vector namespace to see other metrics which work on vectors.

      +

      dist

      (dist [x1 y1] [x2 y2])(dist x1 y1 x2 y2)

      Euclidean distance between points (x1,y1) and (x2,y2). See fastmath.vector namespace to see other metrics which work on vectors.

      Examples

      Distance between two points.

      (dist 1 3 -2 10)
      -;;=> 7.615773105863909

      double-array->seq

      Convert double array into sequence.

      +;;=> 7.615773105863909

      double-array->seq

      Convert double array into sequence.

      Alias for seq.

      Examples

      Convert

      (double-array->seq (seq->double-array [4 3 2]))
      -;;=> (4.0 3.0 2.0)

      double-array-type

      const

      ;;=> class [D

      double-bits

      (double-bits v)

      Returns double as 64-bits (long)

      -

      double-double-array->seq

      (double-double-array->seq res)

      Convert double array of double arrays into sequence of sequences.

      +;;=> (4.0 3.0 2.0)

      double-array-type

      const

      ;;=> class [D

      double-bits

      (double-bits v)

      Returns double as 64-bits (long)

      +

      double-double-array->seq

      (double-double-array->seq res)

      Convert double array of double arrays into sequence of sequences.

      Examples

      Convert

      (double-double-array->seq (seq->double-double-array
                                  [[4 3 2] (double-array [1 2 3])]))
      -;;=> ((4.0 3.0 2.0) (1.0 2.0 3.0))

      double-double-array-type

      const

      ;;=> class [[D

      double-high-bits

      (double-high-bits v)

      Returns high word from double as bits

      -

      double-low-bits

      (double-low-bits v)

      Returns low word from double as bits

      -

      double-one-minus-epsilon

      const

      ;;=> 0.9999999999999999

      Value of 0x1.fffffffffffffp-1d = 0.(9)

      -

      E

      const

      ;;=> 2.718281828459045

      Value of \(e\)

      -

      EPSILON

      const

      ;;=> 1.0E-10

      Very small number \(\varepsilon\)

      -

      eq

      (eq _)(eq a b)(eq a b c)(eq a b c d)

      Primitive math equality function for doubles. See ==.

      -

      erf

      macro

      (erf x)(erf x y)

      Error function. For two arguments return difference between (erf x) and (erf y).

      +;;=> ((4.0 3.0 2.0) (1.0 2.0 3.0))

      double-double-array-type

      const

      ;;=> class [[D

      double-exponent

      (double-exponent v)

      Extract exponent information from double

      +

      double-high-bits

      (double-high-bits v)

      Returns high word from double as bits

      +

      double-low-bits

      (double-low-bits v)

      Returns low word from double as bits

      +

      double-one-minus-epsilon

      const

      ;;=> 0.9999999999999999

      Value of 0x1.fffffffffffffp-1d = 0.(9)

      +

      double-significand

      (double-significand v)

      Extract significand from double

      +

      E

      const

      ;;=> 2.718281828459045

      Value of \(e\)

      +

      EPSILON

      const

      ;;=> 1.0E-10

      Very small number \(\varepsilon\)

      +

      eq

      (eq _)(eq a b)(eq a b c)(eq a b c d)

      Primitive math equality function for doubles. See ==.

      +

      erf

      macro

      (erf x)(erf x y)

      Error function. For two arguments return difference between (erf x) and (erf y).

      Examples

      Usage

      (fastmath.core/erf 1.0)
       ;;=> 0.8427007929497151

      Plot of erf

      Plort of 2d erf

      -

      erfc

      macro

      (erfc x)

      Complementary error function.

      +

      erfc

      macro

      (erfc x)

      Complementary error function.

      Examples

      Usage

      (fastmath.core/erfc 1.0)
       ;;=> 0.15729920705028488

      Plot of erfc

      -

      evalpoly

      (evalpoly x & coeffs)

      Evaluate polynomial

      -

      even?

      macro

      (even? x)

      fastmath.java.PrimitiveMath/isEven function wrapped in macro.

      +

      evalpoly

      (evalpoly x & coeffs)

      Evaluate polynomial

      +

      even?

      macro

      (even? x)

      fastmath.java.PrimitiveMath/isEven function wrapped in macro.

      excsc

      (excsc v)

      Excosecant

      -

      exp

      macro

      (exp x)

      net.jafama.FastMath/exp function wrapped in macro.

      +

      exp

      macro

      (exp x)

      net.jafama.FastMath/exp function wrapped in macro.

      Examples

      Usage

      (fastmath.core/exp 1.0)
       ;;=> 2.7182818284590455

      Plot of exp

      -

      expm1

      macro

      (expm1 x)

      net.jafama.FastMath/expm1 function wrapped in macro.

      +

      expm1

      macro

      (expm1 x)

      net.jafama.FastMath/expm1 function wrapped in macro.

      Examples

      Usage

      (fastmath.core/expm1 1.0)
       ;;=> 1.7182818284590455

      Plot of expm1

      -

      exsec

      (exsec v)

      Exsecant

      -

      factorial

      (factorial n)

      Factorial

      -

      factorial20

      (factorial20 n)

      Factorial table up to 20!

      -

      fast*

      (fast* a b)

      Primitive * for two doubles as function.

      -

      fast+

      (fast+ a b)

      Primitive + for two doubles as function.

      -

      fast-

      (fast- a b)

      Primitive - for two doubles as function.

      -

      fast-identity

      (fast-identity a)

      Identity on double.

      -

      fast-max

      (fast-max a b)

      Primitive max for two doubles as function.

      -

      fast-min

      (fast-min a b)

      Primitive min for two doubles as function

      -

      floor

      (floor x)(floor x scale)

      \(\lfloor x \rfloor\). See: qfloor.

      +

      exsec

      (exsec v)

      Exsecant

      +

      factorial

      (factorial n)

      Factorial

      +

      factorial20

      (factorial20 n)

      Factorial table up to 20!

      +

      fast*

      (fast* a b)

      Primitive * for two doubles as function.

      +

      fast+

      (fast+ a b)

      Primitive + for two doubles as function.

      +

      fast-

      (fast- a b)

      Primitive - for two doubles as function.

      +

      fast-identity

      (fast-identity a)

      Identity on double.

      +

      fast-max

      (fast-max a b)

      Primitive max for two doubles as function.

      +

      fast-min

      (fast-min a b)

      Primitive min for two doubles as function

      +

      floor

      (floor x)(floor x scale)

      \(\lfloor x \rfloor\). See: qfloor.

      Rounding is done to a multiply of scale value (when provided).

      Examples

      Scaled floor

      (floor 234.312 10)
      @@ -308,9 +310,9 @@ 

      Other functions

      ;; Test: ok.

      Usage

      (fastmath.core/floor 1.0)
       ;;=> 1.0

      Plot of floor

      -

      fma

      macro

      (fma x y z)

      [x y z] -> (+ z (* x y)) or Math/fma for java 9+

      -

      FOUR_INV_PI

      const

      ;;=> 1.2732395447351628

      Value of \(\frac{4}{\pi}\)

      -

      fpow

      macro

      (fpow x y)

      Fast version of pow where exponent is integer.

      +

      fma

      macro

      (fma x y z)

      [x y z] -> (+ z (* x y)) or Math/fma for java 9+

      +

      FOUR_INV_PI

      const

      ;;=> 1.2732395447351628

      Value of \(\frac{4}{\pi}\)

      +

      fpow

      macro

      (fpow x y)

      Fast version of pow where exponent is integer.

      Examples

      Example

      (fpow 1.23 4)
       ;;=> 2.28886641
      @@ -321,7 +323,7 @@ 

      Other functions

      (fpow 1.23 5) ;;=> 2.8153056842999997 (fpow 1.23 -2) -;;=> 0.6609822195782934

      frac

      (frac v)

      Fractional part, always returns values from 0.0 to 1.0 (exclusive). See sfrac for signed version.

      +;;=> 0.6609822195782934

      frac

      (frac v)

      Fractional part, always returns values from 0.0 to 1.0 (exclusive). See sfrac for signed version.

      Examples

      Examples

      (frac 0.555)
       ;;=> 0.555
      @@ -329,19 +331,19 @@ 

      Other functions

      ;;=> 0.555

      Usage

      (fastmath.core/frac 1.0)
       ;;=> 0.0

      Plot of frac

      -

      GAMMA

      const

      ;;=> 0.5772156649015329

      Euler-Mascheroni constant

      -

      gamma

      macro

      (gamma x)

      Gamma function \(\Gamma(x)\)

      +

      GAMMA

      const

      ;;=> 0.5772156649015329

      Euler-Mascheroni constant

      +

      gamma

      macro

      (gamma x)

      Gamma function \(\Gamma(x)\)

      Examples

      Usage

      (fastmath.core/gamma 1.0)
       ;;=> 1.0

      Plot of gamma

      -

      gcd

      (gcd a b)

      Fast binary greatest common divisor (Stein’s algorithm)

      +

      gcd

      (gcd a b)

      Fast binary greatest common divisor (Stein’s algorithm)

      Examples

      Usage

      (gcd 340 440)
       ;;=> 20
       (gcd (* 123 5544331) (* 123 123))
       ;;=> 123
       (gcd -234 -432)
      -;;=> 18

      group-by-intervals

      (group-by-intervals coll)(group-by-intervals intervals coll)

      Group sequence of values into given intervals.

      +;;=> 18

      group-by-intervals

      (group-by-intervals coll)(group-by-intervals intervals coll)

      Group sequence of values into given intervals.

      If intervals are missing, use co-intervals to find some.

      Examples

      Examples

      (group-by-intervals [1 2 3 4 1 2 3 4 5 1 -2])
      @@ -351,12 +353,12 @@ 

      Other functions

      ;;=> [2.5 4.5] (3 4 3 4), ;;=> [3.5 5.5] (4 4 5)} (group-by-intervals [[1 2] [3 4]] [1 2 3 4 1 2 3 4 5 1 -2]) -;;=> {[1 2] (2 2), [3 4] (4 4)}

      hacovercos

      (hacovercos v)

      Hacovercosine

      -

      hacoversin

      (hacoversin v)

      Hacoversine

      -

      HALF_PI

      const

      ;;=> 1.5707963267948966

      Value of \(\frac{\pi}{2}\)

      -

      havercos

      (havercos v)

      Havercosine

      -

      haversin

      (haversin v)(haversin [lat1 lon1] [lat2 lon2])(haversin lat1 lon1 lat2 lon2)

      Haversine formula for value or lattitude and longitude pairs.

      -

      haversine

      Haversine (haversin alias)

      +;;=> {[1 2] (2 2), [3 4] (4 4)}

      hacovercos

      (hacovercos v)

      Hacovercosine

      +

      hacoversin

      (hacoversin v)

      Hacoversine

      +

      HALF_PI

      const

      ;;=> 1.5707963267948966

      Value of \(\frac{\pi}{2}\)

      +

      havercos

      (havercos v)

      Havercosine

      +

      haversin

      (haversin v)(haversin [lat1 lon1] [lat2 lon2])(haversin lat1 lon1 lat2 lon2)

      Haversine formula for value or lattitude and longitude pairs.

      +

      haversine

      Haversine (haversin alias)

      Examples

      Usage

      (haversine 10)
       ;;=> 0.9195357645382263
      @@ -366,12 +368,12 @@ 

      Other functions

      ;;=> 0.17694529423473296

      Usage

      (fastmath.core/haversine 1.0)
       ;;=> 0.22984884706593012

      Plot of haversine

      -

      haversine-dist

      (haversine-dist [lat1 lon1] [lat2 lon2])(haversine-dist lat1 lon1 lat2 lon2)

      Haversine distance d for r=1

      +

      haversine-dist

      (haversine-dist [lat1 lon1] [lat2 lon2])(haversine-dist lat1 lon1 lat2 lon2)

      Haversine distance d for r=1

      Examples

      Usage

      (haversine-dist [10 20] [30 10])
       ;;=> 0.8683203900985386
       (haversine-dist 10 20 30 10)
      -;;=> 0.8683203900985386

      high-2-exp

      (high-2-exp v)

      Find lowest exponent (power of 2) which is greater or equal x. See low-2-exp.

      +;;=> 0.8683203900985386

      high-2-exp

      (high-2-exp v)

      Find lowest exponent (power of 2) which is greater or equal x. See low-2-exp.

      Examples

      Result 5 means, that \(2^5=32\) is greater than 23.11. Lower exponent (4) gives lower value (16).

      (high-2-exp 23.11)
       ;;=> 5

      For x less than 1.0 gives negative exponent.

      @@ -379,21 +381,21 @@

      Other functions

      ;;=> -3

      Usage

      (fastmath.core/high-2-exp 1.0)
       ;;=> 0

      Plot of high-2-exp

      -

      high-exp

      (high-exp b x)

      Find lowest exponent for base b which is higher or equalx. See also low-exp.

      +

      high-exp

      (high-exp b x)

      Find lowest exponent for base b which is higher or equalx. See also low-exp.

      Examples

      Result 2 means, that \(9^2=81\) is greater than 23.11. Lower exponent 1 gives lower value 9.

      (high-exp 9 23.11)
       ;;=> 2

      For x less than 1.0 gives negative exponent.

      (high-exp 10 0.011)
      -;;=> -1

      hypot

      (hypot x y)(hypot x y z)

      Hypot. See also hypot-sqrt.

      +;;=> -1

      hypot

      (hypot x y)(hypot x y z)

      Hypot. See also hypot-sqrt.

      Examples

      Plot of hypot

      -

      hypot-sqrt

      (hypot-sqrt x y)(hypot-sqrt x y z)

      Hypot, sqrt version: \(\sqrt{x^2+y^2}\) or \(\sqrt{x^2+y^2+z^2}\). Should be faster than hypot.

      +

      hypot-sqrt

      (hypot-sqrt x y)(hypot-sqrt x y z)

      Hypot, sqrt version: \(\sqrt{x^2+y^2}\) or \(\sqrt{x^2+y^2+z^2}\). Should be faster than hypot.

      Examples

      Plot of hypot-sqrt

      -

      I0

      (I0 x)

      Modified Bessel function of the first kind, order 0.

      -

      iabs

      (iabs x)

      \(|x|\) - long version. See abs.

      +

      I0

      (I0 x)

      Modified Bessel function of the first kind, order 0.

      +

      iabs

      (iabs x)

      \(|x|\) - long version. See abs.

      Examples

      Usage

      (fastmath.core/iabs 1.0)
       ;;=> 1

      Plot of iabs

      -

      inc

      macro

      (inc x)

      fastmath.java.PrimitiveMath/inc function wrapped in macro.

      +

      inc

      macro

      (inc x)

      fastmath.java.PrimitiveMath/inc function wrapped in macro.

      inf?

      (inf? v)

      Check if number is infinite

      Examples

      Usage

      (inf? ##Inf)
      @@ -407,25 +409,26 @@ 

      Other functions

      (inf? ##NaN) ;;=> false -;; Test: ok.

      inv-erf

      macro

      (inv-erf x)

      Inverse erf.

      +;; Test: ok.

      inv-erf

      macro

      (inv-erf x)

      Inverse erf.

      Examples

      Usage

      (fastmath.core/inv-erf 1.0)
       ;;=> Infinity

      Plot of inv-erf

      -

      inv-erfc

      macro

      (inv-erfc x)

      Inverse erfc.

      +

      inv-erfc

      macro

      (inv-erfc x)

      Inverse erfc.

      Examples

      Usage

      (fastmath.core/inv-erfc 1.0)
       ;;=> 0.0

      Plot of inv-erfc

      -

      inv-gamma-1pm1

      macro

      (inv-gamma-1pm1 x)

      \(\frac{1}{\Gamma(1+x)}-1\).

      +

      inv-gamma-1pm1

      macro

      (inv-gamma-1pm1 x)

      \(\frac{1}{\Gamma(1+x)}-1\).

      Examples

      Usage

      (fastmath.core/inv-gamma-1pm1 1.0)
       ;;=> -0.0

      Plot of inv-gamma-1pm1

      -

      INV_LN2

      const

      ;;=> 1.4426950408889634

      \(\frac{1}{\ln{2}}\)

      -

      INV_LOG_HALF

      const

      ;;=> -1.4426950408889634

      \(\frac{1}{\ln{0.5}}\)

      -

      INV_PI

      const

      ;;=> 0.3183098861837907

      Value of \(\frac{1}{\pi}\)

      -

      INV_SQRT2PI

      const

      ;;=> 0.3989422804014327

      \(\frac{1}{\sqrt\pi}\)

      -

      INV_SQRT_2

      const

      ;;=> 0.7071067811865475

      \(\frac{1}{\sqrt{2}}\)

      -

      INV_TWO_PI

      const

      ;;=> 0.15915494309189535

      Value of \(\frac{1}{2 \pi}\)

      -

      invalid-double?

      (invalid-double? v)

      Check if number is invalid

      +

      INV_FOUR_PI

      const

      ;;=> 0.07957747154594767

      Value of \(\frac{1}{4 \pi}\)

      +

      INV_LN2

      const

      ;;=> 1.4426950408889634

      \(\frac{1}{\ln{2}}\)

      +

      INV_LOG_HALF

      const

      ;;=> -1.4426950408889634

      \(\frac{1}{\ln{0.5}}\)

      +

      INV_PI

      const

      ;;=> 0.3183098861837907

      Value of \(\frac{1}{\pi}\)

      +

      INV_SQRT2PI

      const

      ;;=> 0.3989422804014327

      \(\frac{1}{\sqrt\pi}\)

      +

      INV_SQRT_2

      const

      ;;=> 0.7071067811865475

      \(\frac{1}{\sqrt{2}}\)

      +

      INV_TWO_PI

      const

      ;;=> 0.15915494309189535

      Value of \(\frac{1}{2 \pi}\)

      +

      invalid-double?

      (invalid-double? v)

      Check if number is invalid

      Examples

      Usage

      (invalid-double? ##Inf)
       ;;=> true
      @@ -438,7 +441,7 @@ 

      Other functions

      (invalid-double? ##NaN) ;;=> true -;; Test: ok.

      itrunc

      (itrunc v)

      Truncate fractional part, keep sign. Returns long.

      +;; Test: ok.

      itrunc

      (itrunc v)

      Truncate fractional part, keep sign. Returns long.

      Examples

      Examples

      (itrunc 1.234)
       ;;=> 1
      @@ -446,9 +449,9 @@ 

      Other functions

      ;;=> -1

      Usage

      (fastmath.core/itrunc 1.0)
       ;;=> 1

      Plot of itrunc

      -

      jinc

      (jinc x)

      Besselj1 devided by x

      -

      jvm-version

      const

      ;;=> 19

      LANCZOS_G

      const

      ;;=> 4.7421875

      Lanchos approximation g constant

      -

      lcm

      (lcm a b)

      Fast binary least common multiplier.

      +

      jinc

      (jinc x)

      Besselj1 devided by x

      +

      jvm-version

      const

      ;;=> 21

      LANCZOS_G

      const

      ;;=> 4.7421875

      Lanchos approximation g constant

      +

      lcm

      (lcm a b)

      Fast binary least common multiplier.

      Examples

      Usage

      (lcm 340 440)
       ;;=> 7480
      @@ -457,7 +460,7 @@ 

      Other functions

      (lcm 331 (* 123 123)) ;;=> 5007699 (lcm -234 -432) -;;=> 5616

      lerp

      (lerp start stop t)

      Linear interpolation between start and stop for amount t. See also mlerp, cos-interpolation, quad-interpolation or smooth-interpolation.

      +;;=> 5616

      lerp

      (lerp start stop t)

      Linear interpolation between start and stop for amount t. See also mlerp, cos-interpolation, quad-interpolation or smooth-interpolation.

      Examples

      Examples

      (lerp 0.0 1.0 0.123)
       ;;=> 0.123
      @@ -467,70 +470,71 @@ 

      Other functions

      ;;=> 150.0

      Interpolate outside given range.

      (lerp -1.0 1.0 1.5)
       ;;=> 2.0

      Plot of lerp

      -

      ln

      macro

      (ln x)

      net.jafama.FastMath/log function wrapped in macro.

      +

      ln

      macro

      (ln x)

      net.jafama.FastMath/log function wrapped in macro.

      Examples

      Usage

      (fastmath.core/ln 1.0)
       ;;=> 0.0

      Plot of ln

      -

      LN10

      const

      ;;=> 2.302585092994046

      \(\ln{10}\)

      -

      LN2

      const

      ;;=> 0.6931471805599453

      \(\ln{2}\)

      -

      LN2_2

      const

      ;;=> 0.34657359027997264

      \(\frac{\ln{2}}{2}\)

      -

      log

      macro

      (log x)

      net.jafama.FastMath/log function wrapped in macro.

      +

      LN10

      const

      ;;=> 2.302585092994046

      \(\ln{10}\)

      +

      LN2

      const

      ;;=> 0.6931471805599453

      \(\ln{2}\)

      +

      LN2_2

      const

      ;;=> 0.34657359027997264

      \(\frac{\ln{2}}{2}\)

      +

      log

      macro

      (log x)

      net.jafama.FastMath/log function wrapped in macro.

      Examples

      Usage

      (fastmath.core/log 1.0)
       ;;=> 0.0

      Plot of log

      -

      log-beta

      macro

      (log-beta x y)

      Logarithm of Beta function.

      +

      log-beta

      macro

      (log-beta x y)

      Logarithm of Beta function.

      Examples

      Plot of log-beta

      -

      log-combinations

      (log-combinations n k)

      Log of binomial coefficient (n choose k)

      -

      log-factorial

      (log-factorial x)

      Log factorial, alias to log-gamma

      -

      log-gamma

      macro

      (log-gamma x)

      Log of Gamma function \(\ln\Gamma(x)\)

      +

      log-combinations

      (log-combinations n k)

      Log of binomial coefficient (n choose k)

      +

      log-factorial

      (log-factorial x)

      Log factorial, alias to log-gamma

      +

      log-gamma

      macro

      (log-gamma x)

      Log of Gamma function \(\ln\Gamma(x)\)

      Examples

      Usage

      (fastmath.core/log-gamma 1.0)
       ;;=> -0.0

      Plot of log-gamma

      -

      log-gamma-1p

      macro

      (log-gamma-1p x)

      Log of Gamma function \(\ln\Gamma(1+x)\)

      +

      log-gamma-1p

      macro

      (log-gamma-1p x)

      Log of Gamma function \(\ln\Gamma(1+x)\)

      Examples

      Usage

      (fastmath.core/log-gamma-1p 1.0)
       ;;=> 0.0

      Plot of log-gamma-1p

      -

      log-I0

      (log-I0 x)

      Log of I0.

      -

      log10

      macro

      (log10 x)

      \(\ln_{10}{x}\)

      +

      log-I0

      (log-I0 x)

      Log of I0.

      +

      log10

      macro

      (log10 x)

      \(\ln_{10}{x}\)

      Examples

      Usage

      (fastmath.core/log10 1.0)
       ;;=> 0.0

      Plot of log10

      -

      LOG10E

      const

      ;;=> 0.4342944819032518

      \(\log_{10}{e}\)

      -

      log1mexp

      (log1mexp x)

      log(1-exp(x))

      -

      log1p

      macro

      (log1p x)

      net.jafama.FastMath/log1p function wrapped in macro.

      +

      LOG10E

      const

      ;;=> 0.4342944819032518

      \(\log_{10}{e}\)

      +

      log1mexp

      (log1mexp x)

      log(1-exp(x))

      +

      log1p

      macro

      (log1p x)

      net.jafama.FastMath/log1p function wrapped in macro.

      Examples

      Usage

      (fastmath.core/log1p 1.0)
       ;;=> 0.6931471805599453

      Plot of log1p

      -

      log1pexp

      (log1pexp x)

      log(1+exp(x))

      +

      log1pexp

      (log1pexp x)

      log(1+exp(x))

      Examples

      Usage

      (fastmath.core/log1pexp 1.0)
       ;;=> 1.3132616875182228

      Plot of log1pexp

      -

      log1pmx

      (log1pmx x)

      log(1+x)-x

      -

      log1psq

      (log1psq x)

      log(1+x^2))

      -

      log2

      (log2 x)

      Logarithm with base 2.

      +

      log1pmx

      (log1pmx x)

      log(1+x)-x

      +

      log1psq

      (log1psq x)

      log(1+x^2))

      +

      log2

      (log2 x)

      Logarithm with base 2.

      \(\ln_2{x}\)

      Examples

      Usage

      (fastmath.core/log2 1.0)
       ;;=> 0.0

      Plot of log2

      -

      LOG2E

      const

      ;;=> 1.4426950408889634

      \(\log_{2}{e}\)

      -

      log2mexp

      (log2mexp x)

      log(2-exp(x))

      -

      LOG_HALF

      const

      ;;=> -0.6931471805599453

      \(\ln{0.5}\)

      -

      LOG_PI

      const

      ;;=> 1.1447298858494002

      \(\ln{\pi}\)

      -

      LOG_TWO_PI

      const

      ;;=> 1.8378770664093453

      \(\ln{2 \pi}\)

      -

      logaddexp

      (logaddexp x y)

      log(exp(x)+exp(y))

      -

      logb

      (logb b x)

      Logarithm with base b.

      +

      LOG2E

      const

      ;;=> 1.4426950408889634

      \(\log_{2}{e}\)

      +

      log2int

      (log2int v)

      Fast and integer version of log2, returns long

      +

      log2mexp

      (log2mexp x)

      log(2-exp(x))

      +

      LOG_HALF

      const

      ;;=> -0.6931471805599453

      \(\ln{0.5}\)

      +

      LOG_PI

      const

      ;;=> 1.1447298858494002

      \(\ln{\pi}\)

      +

      LOG_TWO_PI

      const

      ;;=> 1.8378770664093453

      \(\ln{2 \pi}\)

      +

      logaddexp

      (logaddexp x y)

      log(exp(x)+exp(y))

      +

      logb

      (logb b x)

      Logarithm with base b.

      \(\ln_b{x}\)

      -

      logcosh

      (logcosh x)

      log(cosh(x))

      -

      logexpm1

      (logexpm1 x)

      log(exp(x)-1))

      -

      logistic

      Alias for sigmoid

      -

      logit

      (logit x)

      Logit function

      +

      logcosh

      (logcosh x)

      log(cosh(x))

      +

      logexpm1

      (logexpm1 x)

      log(exp(x)-1))

      +

      logistic

      Alias for sigmoid

      +

      logit

      (logit x)

      Logit function

      Examples

      Usage

      (fastmath.core/logit 1.0)
       ;;=> Infinity

      Plot of logit

      -

      logmxp1

      (logmxp1 x)

      log(x)-x+1

      -

      logsubexp

      (logsubexp x y)

      log(abs(exp(x)-exp(y)))

      -

      logsumexp

      (logsumexp xs)

      log(exp(x1)+…+exp(xn))

      -

      low-2-exp

      (low-2-exp x)

      Find greatest exponent (power of 2) which is lower or equal x. See high-2-exp.

      +

      logmxp1

      (logmxp1 x)

      log(x)-x+1

      +

      logsubexp

      (logsubexp x y)

      log(abs(exp(x)-exp(y)))

      +

      logsumexp

      (logsumexp xs)

      log(exp(x1)+…+exp(xn))

      +

      low-2-exp

      (low-2-exp x)

      Find greatest exponent (power of 2) which is lower or equal x. See high-2-exp.

      Examples

      Result 4 means, that \(2^4=16\) is lower than 23.11. Next exponent (5) gives greater value (32).

      (low-2-exp 23.11)
       ;;=> 4

      For x less than 1.0 gives negative exponent.

      @@ -538,44 +542,44 @@

      Other functions

      ;;=> -4

      Usage

      (fastmath.core/low-2-exp 1.0)
       ;;=> 0

      Plot of low-2-exp

      -

      low-exp

      (low-exp b x)

      Find greatest exponent for base b which is lower or equal x. See also high-exp.

      +

      low-exp

      (low-exp b x)

      Find greatest exponent for base b which is lower or equal x. See also high-exp.

      Examples

      Result 1 means, that \(9^1=9\) is lower than 23.11. Next exponent 2 gives greater value 82.

      (low-exp 9 23.11)
       ;;=> 1

      For x less than 1.0 gives negative exponent.

      (low-exp 10 0.011)
      -;;=> -2

      M_1_PI

      const

      ;;=> 0.3183098861837907

      \(\frac{1}{\pi}\)

      -

      M_2_PI

      const

      ;;=> 0.6366197723675814

      \(\frac{2}{\pi}\)

      -

      M_2_SQRTPI

      const

      ;;=> 1.1283791670955126

      \(\frac{2}{\sqrt\pi}\)

      -

      M_3PI_4

      const

      ;;=> 2.356194490192345

      \(\frac{3\pi}{4}\)

      -

      M_E

      const

      ;;=> 2.718281828459045

      \(e\)

      -

      M_INVLN2

      const

      ;;=> 1.4426950408889634

      \(\frac{1}{\ln{2}}\)

      -

      M_IVLN10

      const

      ;;=> 0.43429448190325176

      \(\frac{1}{\ln{10}}\)

      -

      M_LN10

      const

      ;;=> 2.302585092994046

      \(\ln{10}\)

      -

      M_LN2

      const

      ;;=> 0.6931471805599453

      \(\ln{2}\)

      -

      M_LOG10E

      const

      ;;=> 0.4342944819032518

      \(\log_{10}{e}\)

      -

      M_LOG2_E

      const

      ;;=> 0.6931471805599453

      \(\ln{2}\)

      -

      M_LOG2E

      const

      ;;=> 1.4426950408889634

      \(\log_{2}{e}\)

      -

      M_PI

      const

      ;;=> 3.141592653589793

      \(\pi\)

      -

      M_PI_2

      const

      ;;=> 1.5707963267948966

      \(\frac{\pi}{2}\)

      -

      M_PI_4

      const

      ;;=> 0.7853981633974483

      \(\frac{\pi}{4}\)

      -

      M_SQRT1_2

      const

      ;;=> 0.7071067811865475

      \(\frac{1}{\sqrt{2}}\)

      -

      M_SQRT2

      const

      ;;=> 1.4142135623730951

      \(\sqrt{2}\)

      -

      M_SQRT3

      const

      ;;=> 1.7320508075688772

      \(\sqrt{3}\)

      -

      M_SQRT_PI

      const

      ;;=> 1.7724538509055159

      \(\sqrt\pi\)

      -

      M_TWOPI

      const

      ;;=> 6.283185307179586

      \(2\pi\)

      -

      MACHINE-EPSILON

      const

      ;;=> 1.1102230246251565E-16

      Smallest machine number. Value is calculated during evaluation and may differ on different processors.

      -

      make-norm

      (make-norm start stop)(make-norm start stop dstart dstop)

      Make norm function for given range. Resulting function accepts double value (with optional target [dstart,dstop] range) and returns double.

      +;;=> -2

      M_1_PI

      const

      ;;=> 0.3183098861837907

      \(\frac{1}{\pi}\)

      +

      M_2_PI

      const

      ;;=> 0.6366197723675814

      \(\frac{2}{\pi}\)

      +

      M_2_SQRTPI

      const

      ;;=> 1.1283791670955126

      \(\frac{2}{\sqrt\pi}\)

      +

      M_3PI_4

      const

      ;;=> 2.356194490192345

      \(\frac{3\pi}{4}\)

      +

      M_E

      const

      ;;=> 2.718281828459045

      \(e\)

      +

      M_INVLN2

      const

      ;;=> 1.4426950408889634

      \(\frac{1}{\ln{2}}\)

      +

      M_IVLN10

      const

      ;;=> 0.43429448190325176

      \(\frac{1}{\ln{10}}\)

      +

      M_LN10

      const

      ;;=> 2.302585092994046

      \(\ln{10}\)

      +

      M_LN2

      const

      ;;=> 0.6931471805599453

      \(\ln{2}\)

      +

      M_LOG10E

      const

      ;;=> 0.4342944819032518

      \(\log_{10}{e}\)

      +

      M_LOG2_E

      const

      ;;=> 0.6931471805599453

      \(\ln{2}\)

      +

      M_LOG2E

      const

      ;;=> 1.4426950408889634

      \(\log_{2}{e}\)

      +

      M_PI

      const

      ;;=> 3.141592653589793

      \(\pi\)

      +

      M_PI_2

      const

      ;;=> 1.5707963267948966

      \(\frac{\pi}{2}\)

      +

      M_PI_4

      const

      ;;=> 0.7853981633974483

      \(\frac{\pi}{4}\)

      +

      M_SQRT1_2

      const

      ;;=> 0.7071067811865475

      \(\frac{1}{\sqrt{2}}\)

      +

      M_SQRT2

      const

      ;;=> 1.4142135623730951

      \(\sqrt{2}\)

      +

      M_SQRT3

      const

      ;;=> 1.7320508075688772

      \(\sqrt{3}\)

      +

      M_SQRT_PI

      const

      ;;=> 1.7724538509055159

      \(\sqrt\pi\)

      +

      M_TWOPI

      const

      ;;=> 6.283185307179586

      \(2\pi\)

      +

      MACHINE-EPSILON

      const

      ;;=> 1.1102230246251565E-16

      Smallest machine number. Value is calculated during evaluation and may differ on different processors.

      +

      make-norm

      (make-norm start stop)(make-norm start stop dstart dstop)

      Make norm function for given range. Resulting function accepts double value (with optional target [dstart,dstop] range) and returns double.

      Examples

      Make cos() normalizer from -1.0,1.0 to 0.0, 1.0.

      (let [norm-cos (make-norm -1.0 1.0 0.0 1.0)] (norm-cos (cos 2.0)))
       ;;=> 0.29192658172642894

      Make normalizer from 0,255 to any range.

      (let [norm-0-255 (make-norm 0 255)]
         [(norm-0-255 123 -10 -20) (norm-0-255 123 20 10)])
      -;;=> [-14.823529411764707 15.176470588235293]

      makepoly

      (makepoly coeffs)

      Create polynomial function for given coefficients

      -

      max

      macro

      (max x)(max x y)(max x y & rest)

      A primitive math version of max

      +;;=> [-14.823529411764707 15.176470588235293]

      makepoly

      (makepoly coeffs)

      Create polynomial function for given coefficients

      +

      max

      macro

      (max x)(max x y)(max x y & rest)

      A primitive math version of max

      mevalpoly

      macro

      (mevalpoly x & coeffs)

      Evaluate polynomial macro version in the form coeffs0+coeffs1*x+coeffs2*x^2+….

      -

      min

      macro

      (min x)(min x y)(min x y & rest)

      A primitive math version of min

      +

      min

      macro

      (min x)(min x y)(min x y & rest)

      A primitive math version of min

      minkowski

      (minkowski x)

      Minkowski’s question mark function ?(x)

      -

      mlerp

      macro

      (mlerp start stop t)

      lerp as macro. For inline code. See also lerp, cos-interpolation, quad-interpolation or smooth-interpolation.

      +

      mlerp

      macro

      (mlerp start stop t)

      lerp as macro. For inline code. See also lerp, cos-interpolation, quad-interpolation or smooth-interpolation.

      Examples

      Examples

      (mlerp 0.0 1.0 0.123)
       ;;=> 0.123
      @@ -584,7 +588,7 @@ 

      Other functions

      (mlerp 100 200 0.5) ;;=> 150.0

      Interpolate outside given range.

      (mlerp -1.0 1.0 1.5)
      -;;=> 2.0

      mnorm

      macro

      (mnorm v start stop)(mnorm v start1 stop1 start2 stop2)

      Macro version of norm.

      +;;=> 2.0

      mnorm

      macro

      (mnorm v start stop)(mnorm v start1 stop1 start2 stop2)

      Macro version of norm.

      Examples

      Normalize from 1,-1 to 0,1

      (mnorm 0.234 -1.0 1.0)
       ;;=> 0.617

      Normalize from -1,1 to 0,1

      @@ -593,7 +597,7 @@

      Other functions

      (mnorm (cos HALF_PI) -1.0 1.0 0.0 255.0)
       ;;=> 127.5

      Normalize cos() to 255,0

      (mnorm (cos HALF_PI) -1.0 1.0 255.0 0.0)
      -;;=> 127.5

      mod

      macro

      (mod x y)

      fastmath.java.PrimitiveMath/modulus function wrapped in macro.

      +;;=> 127.5

      mod

      macro

      (mod x y)

      fastmath.java.PrimitiveMath/modulus function wrapped in macro.

      Examples

      Modulus (compared to clojure.core version).

      (mod 3.123 0.333)
       ;;=> 0.12600000000000006
      @@ -611,7 +615,7 @@ 

      Other functions

      ;;=> -0.1259999999999999 (clojure.core/mod 3.123 -0.333) ;;=> -0.20700000000000013

      muladd

      macro

      (muladd x y z)

      [x y z] -> (+ z (* x y)) or Math/fma for java 9+

      -

      nan?

      (nan? v)

      Check if number is NaN

      +

      nan?

      (nan? v)

      Check if number is NaN

      Examples

      Usage

      (nan? ##Inf)
       ;;=> false
      @@ -624,7 +628,7 @@ 

      Other functions

      (nan? ##NaN) ;;=> true -;; Test: ok.

      neg-inf?

      (neg-inf? v)

      Check if number is negatively infinite

      +;; Test: ok.

      neg-inf?

      (neg-inf? v)

      Check if number is negatively infinite

      Examples

      Usage

      (neg-inf? ##Inf)
       ;;=> false
      @@ -637,14 +641,15 @@ 

      Other functions

      (neg-inf? ##NaN) ;;=> false -;; Test: ok.

      neg?

      macro

      (neg? x)

      fastmath.java.PrimitiveMath/isNeg function wrapped in macro.

      -

      negmuladd

      macro

      (negmuladd x y z)

      [x y z] -> (+ z (* -1.0 x y)

      -

      next-double

      (next-double v)(next-double v delta)

      Next double value. Optional value delta sets step amount.

      +;; Test: ok.

      neg?

      macro

      (neg? x)

      fastmath.java.PrimitiveMath/isNeg function wrapped in macro.

      +

      negative-zero?

      (negative-zero? x)

      Check if zero is negative, ie. -0.0

      +

      negmuladd

      macro

      (negmuladd x y z)

      [x y z] -> (+ z (* -1.0 x y)

      +

      next-double

      (next-double v)(next-double v delta)

      Next double value. Optional value delta sets step amount.

      Examples

      Next double.

      (next-double 1234.56789)
       ;;=> 1234.5678900000003

      Next double with delta.

      (next-double 1234.56789 1000)
      -;;=> 1234.5678900002274

      norm

      (norm v start stop)(norm v start1 stop1 start2 stop2)

      Normalize v from the range [start,stop] to the range [0,1] or map v from the range [start1,stop1] to the range [start2,stop2]. See also make-norm.

      +;;=> 1234.5678900002274

      norm

      (norm v start stop)(norm v start1 stop1 start2 stop2)

      Normalize v from the range [start,stop] to the range [0,1] or map v from the range [start1,stop1] to the range [start2,stop2]. See also make-norm.

      Examples

      Normalize from 1,-1 to 0,1

      (norm 0.234 -1.0 1.0)
       ;;=> 0.617

      Normalize from -1,1 to 0,1

      @@ -653,7 +658,7 @@

      Other functions

      (norm (cos HALF_PI) -1.0 1.0 0.0 255.0)
       ;;=> 127.5

      Normalize cos() to 255,0

      (norm (cos HALF_PI) -1.0 1.0 255.0 0.0)
      -;;=> 127.5

      not-neg?

      macro

      (not-neg? x)

      fastmath.java.PrimitiveMath/isNNeg function wrapped in macro.

      +;;=> 127.5

      not-neg?

      macro

      (not-neg? x)

      fastmath.java.PrimitiveMath/isNNeg function wrapped in macro.

      not-pos?

      macro

      (not-pos? x)

      fastmath.java.PrimitiveMath/isNPos function wrapped in macro.

      not==

      macro

      (not== x)(not== x y)(not== x y & rest)

      A primitive math version of not==

      odd?

      macro

      (odd? x)

      fastmath.java.PrimitiveMath/isOdd function wrapped in macro.

      @@ -668,9 +673,9 @@

      Other functions

      (order [1 1 3 2 1 1 2 3 4 3] true)
       ;;=> (8 2 7 9 3 6 0 1 4 5)
       
      -;; Test: ok.

      PHI

      const

      ;;=> 1.618033988749895

      Golden ratio \(\phi\)

      -

      PI

      const

      ;;=> 3.141592653589793

      Value of \(\pi\)

      -

      pos-inf?

      (pos-inf? v)

      Check if number is positively infinite

      +;; Test: ok.

      PHI

      const

      ;;=> 1.618033988749895

      Golden ratio \(\phi\)

      +

      PI

      const

      ;;=> 3.141592653589793

      Value of \(\pi\)

      +

      pos-inf?

      (pos-inf? v)

      Check if number is positively infinite

      Examples

      Usage

      (pos-inf? ##Inf)
       ;;=> true
      @@ -683,23 +688,23 @@ 

      Other functions

      (pos-inf? ##NaN) ;;=> false -;; Test: ok.

      pos?

      macro

      (pos? x)

      fastmath.java.PrimitiveMath/isPos function wrapped in macro.

      +;; Test: ok.

      pos?

      macro

      (pos? x)

      fastmath.java.PrimitiveMath/isPos function wrapped in macro.

      pow

      macro

      (pow x y)

      net.jafama.FastMath/pow function wrapped in macro.

      -

      pow2

      (pow2 x)

      Same as sq. \(x^2\)

      +

      pow2

      (pow2 x)

      Same as sq. \(x^2\)

      Examples

      Usage

      (fastmath.core/pow2 1.0)
       ;;=> 1.0

      Plot of pow2

      -

      pow3

      (pow3 x)

      \(x^3\)

      +

      pow3

      (pow3 x)

      \(x^3\)

      Examples

      Usage

      (fastmath.core/pow3 1.0)
       ;;=> 1.0

      Plot of pow3

      -

      prev-double

      (prev-double v)(prev-double v delta)

      Next double value. Optional value delta sets step amount.

      +

      prev-double

      (prev-double v)(prev-double v delta)

      Next double value. Optional value delta sets step amount.

      Examples

      Prev double.

      (prev-double 1234.56789)
       ;;=> 1234.5678899999998

      Prev double with delta.

      (prev-double 1234.56789 1000)
      -;;=> 1234.5678899997727

      qceil

      macro

      (qceil x)

      Fast version of ceil. Returns long. See: ceil.

      -

      qcos

      macro

      (qcos x)

      Fast and less accurate cos.

      +;;=> 1234.5678899997727

      qceil

      macro

      (qceil x)

      Fast version of ceil. Returns long. See: ceil.

      +

      qcos

      macro

      (qcos x)

      Fast and less accurate cos.

      Examples

      Compare cos and qcos.

      (cos 1.123)
       ;;=> 0.43298018843109504
      @@ -707,12 +712,12 @@ 

      Other functions

      ;;=> 0.433093818853152

      Usage

      (fastmath.core/qcos 1.0)
       ;;=> 0.540171472729893

      Plot of qcos

      -

      qdist

      (qdist [x1 y1] [x2 y2])(qdist x1 y1 x2 y2)

      Quick version of Euclidean distance between points. qsqrt is used instead of sqrt.

      +

      qdist

      (qdist [x1 y1] [x2 y2])(qdist x1 y1 x2 y2)

      Quick version of Euclidean distance between points. qsqrt is used instead of sqrt.

      Examples

      Distance between two points (quick version).

      (qdist 1 3 -2 10)
       ;;=> 7.481406462931432

      Distance between two points (accurate version).

      (dist 1 3 -2 10)
      -;;=> 7.615773105863909

      qexp

      macro

      (qexp x)

      Quick and less accurate version of exp.

      +;;=> 7.615773105863909

      qexp

      macro

      (qexp x)

      Quick and less accurate version of exp.

      Examples

      Compare exp and qexp.

      (exp 1.123)
       ;;=> 3.07406257154899
      @@ -720,8 +725,8 @@ 

      Other functions

      ;;=> 3.1542205810546875

      Usage

      (fastmath.core/qexp 1.0)
       ;;=> 2.799318313598633

      Plot of qexp

      -

      qfloor

      macro

      (qfloor x)

      Fast version of floor. Returns long. See: floor.

      -

      qlog

      macro

      (qlog x)

      Fast and less accurate version of log.

      +

      qfloor

      macro

      (qfloor x)

      Fast version of floor. Returns long. See: floor.

      +

      qlog

      macro

      (qlog x)

      Fast and less accurate version of log.

      Examples

      Compare log and qlog.

      (log 23.123)
       ;;=> 3.1408277931718307
      @@ -729,13 +734,13 @@ 

      Other functions

      ;;=> 3.1407453502111626

      Usage

      (fastmath.core/qlog 1.0)
       ;;=> 0.0

      Plot of qlog

      -

      qpow

      macro

      (qpow x y)

      Fast and less accurate version of pow.

      +

      qpow

      macro

      (qpow x y)

      Fast and less accurate version of pow.

      Examples

      Compare pow and qpow.

      (pow 1.23 43.3)
       ;;=> 7814.322402338249
       (qpow 1.23 43.3)
      -;;=> 7808.951363383271

      qround

      macro

      (qround x)

      Fast version of round. Returns long. See: rint, round.

      -

      qsin

      macro

      (qsin x)

      Fast and less accurate sin.

      +;;=> 7808.951363383271

      qround

      macro

      (qround x)

      Fast version of round. Returns long. See: rint, round.

      +

      qsin

      macro

      (qsin x)

      Fast and less accurate sin.

      Examples

      Compare sin and qsin.

      (sin 1.123)
       ;;=> 0.901403437105813
      @@ -743,7 +748,7 @@ 

      Other functions

      ;;=> 0.901348847046022

      Usage

      (fastmath.core/qsin 1.0)
       ;;=> 0.8415549774368984

      Plot of qsin

      -

      qsqrt

      macro

      (qsqrt x)

      Approximated sqrt using binary operations with error 1.0E-2.

      +

      qsqrt

      macro

      (qsqrt x)

      Approximated sqrt using binary operations with error 1.0E-2.

      Examples

      Compare sqrt and qsqrt.

      (sqrt 23.123)
       ;;=> 4.808638060823459
      @@ -751,12 +756,12 @@ 

      Other functions

      ;;=> 4.746781462931431

      Usage

      (fastmath.core/qsqrt 1.0)
       ;;=> 0.982050807866429

      Plot of qsqrt

      -

      quad-interpolation

      (quad-interpolation start stop t)

      Quad interpolation. See also lerp/mlerp, cos-interpolation or smooth-interpolation.

      +

      quad-interpolation

      (quad-interpolation start stop t)

      Quad interpolation. See also lerp/mlerp, cos-interpolation or smooth-interpolation.

      Examples

      Example

      (quad-interpolation 0.0 1.0 0.123)
       ;;=> 0.030258

      Plot of quad-interpolation

      -

      QUARTER_PI

      const

      ;;=> 0.7853981633974483

      Value of \(\frac{\pi}{4}\)

      -

      quot

      macro

      (quot x y)

      fastmath.java.PrimitiveMath/quotient function wrapped in macro.

      +

      QUARTER_PI

      const

      ;;=> 0.7853981633974483

      Value of \(\frac{\pi}{4}\)

      +

      quot

      macro

      (quot x y)

      fastmath.java.PrimitiveMath/quotient function wrapped in macro.

      Examples

      Quotient (compared to clojure.core version).

      (quot 3.123 0.333)
       ;;=> 9.0
      @@ -774,10 +779,10 @@ 

      Other functions

      ;;=> 9.0 (clojure.core/quot 3.123 -0.333) ;;=> -9.0

      rad-in-deg

      const

      ;;=> 57.29577951308232

      \(\frac{180}{\pi}\)

      -

      radians

      (radians deg)

      Convert degrees into radians.

      +

      radians

      (radians deg)

      Convert degrees into radians.

      Examples

      Let’s convert 180 degrees to radians.

      (radians 180)
      -;;=> 3.141592653589793

      rank

      (rank vs)(rank vs ties)(rank vs ties desc?)

      Sample ranks. See R docs.

      +;;=> 3.141592653589793

      rank

      (rank vs)(rank vs ties)(rank vs ties desc?)

      Sample ranks. See R docs.

      Rank uses 0 based indexing.

      Possible tie strategies: :average, :first, :last, :random, :min, :max, :dense.

      :dense is the same as in data.table::frank from R

      @@ -799,16 +804,16 @@

      Other functions

      ;; Test: ok.

      Random ties

      (rank [3 1 4 1 5 9 2 6 5 3 5] :random)
      -;;=> [3 1 5 0 8 10 2 9 6 4 7]
      +;;=> [4 1 5 0 6 10 2 9 7 3 8]
       (rank [3 1 4 1 5 9 2 6 5 3 5] :random)
      -;;=> [3 1 5 0 7 10 2 9 8 4 6]
      +;;=> [4 1 5 0 7 10 2 9 6 3 8]
       (rank [3 1 4 1 5 9 2 6 5 3 5] :random)
      -;;=> [4 0 5 1 6 10 2 9 8 3 7]
      +;;=> [3 1 5 0 6 10 2 9 7 4 8]
       (rank [3 1 4 1 5 9 2 6 5 3 5] :random)
      -;;=> [4 0 5 1 6 10 2 9 7 3 8]

      regularized-beta

      macro

      (regularized-beta x y z)

      Regularized Beta.

      -

      regularized-gamma-p

      macro

      (regularized-gamma-p x y)

      Regularized gamma P

      -

      regularized-gamma-q

      macro

      (regularized-gamma-q x y)

      Regularized gamma Q

      -

      rem

      macro

      (rem x y)

      fastmath.java.PrimitiveMath/remainder function wrapped in macro.

      +;;=> [3 0 5 1 6 10 2 9 8 4 7]

      regularized-beta

      macro

      (regularized-beta x y z)

      Regularized Beta.

      +

      regularized-gamma-p

      macro

      (regularized-gamma-p x y)

      Regularized gamma P

      +

      regularized-gamma-q

      macro

      (regularized-gamma-q x y)

      Regularized gamma Q

      +

      rem

      macro

      (rem x y)

      fastmath.java.PrimitiveMath/remainder function wrapped in macro.

      Examples

      Remainder (compared to clojure.core version).

      (rem 3.123 0.333)
       ;;=> 0.12600000000000006
      @@ -832,20 +837,21 @@ 

      Other functions

      (rem 3.123 0.2) ;;=> 0.12300000000000005 (mod 3.123 0.2) -;;=> 0.12300000000000005

      rint

      (rint x)

      Round to double. See round, qround.

      +;;=> 0.12300000000000005

      rint

      (rint x)(rint x scale)

      Round to double. See round, qround.

      +

      Rounding is done to a multiply of scale value (when provided).

      Examples

      Round to double.

      (rint PI)
       ;;=> 3.0

      Usage

      (fastmath.core/rint 1.0)
       ;;=> 1.0

      Plot of rint

      -

      round

      (round x)

      Round to long. See: rint, qround.

      +

      round

      (round x)

      Round to long. See: rint, qround.

      Examples

      Round to long.

      (round PI)
       ;;=> 3

      Usage

      (fastmath.core/round 1.0)
       ;;=> 1

      Plot of round

      -

      round-even

      (round-even x)

      Round evenly (like in round in R), IEEE / IEC rounding

      -

      round-up-pow2

      (round-up-pow2 v)

      Round long to the next power of 2

      +

      round-even

      (round-even x)

      Round evenly (like in round in R), IEEE / IEC rounding

      +

      round-up-pow2

      (round-up-pow2 v)

      Round long to the next power of 2

      Examples

      Examples

      (round-up-pow2 1023)
       ;;=> 1024
      @@ -855,16 +861,16 @@ 

      Other functions

      ;;=> 2048

      Usage

      (fastmath.core/round-up-pow2 1.0)
       ;;=> 1

      Plot of round-up-pow2

      -

      rqsqrt

      macro

      (rqsqrt x)

      Inversed version of qsqrt. Quick and less accurate.

      +

      rqsqrt

      macro

      (rqsqrt x)

      Inversed version of qsqrt. Quick and less accurate.

      Examples

      Usage

      (fastmath.core/rqsqrt 1.0)
       ;;=> 0.9662250423950712

      Plot of rqsqrt

      -

      safe-sqrt

      (safe-sqrt value)

      Safe sqrt, for value <= 0 result is 0.

      +

      safe-sqrt

      (safe-sqrt value)

      Safe sqrt, for value <= 0 result is 0.

      \( \left\{ \begin{array}{lr} 0 & : x \leq 0\\ \sqrt{x} & : x > 0 \end{array} \right. \)

      Examples

      Usage

      (fastmath.core/safe-sqrt 1.0)
       ;;=> 1.0

      Plot of safe-sqrt

      -

      sample

      (sample f number-of-values)(sample f number-of-values domain?)(sample f domain-min domain-max number-of-values)(sample f domain-min domain-max number-of-values domain?)

      Sample function f and return sequence of values.

      +

      sample

      (sample f number-of-values)(sample f number-of-values domain?)(sample f domain-min domain-max number-of-values)(sample f domain-min domain-max number-of-values domain?)

      Sample function f and return sequence of values.

      range-min defaults to 0.0, range-max to 1.0.

      Range is inclusive.

      When optional domain? is set to true (default: false) function returns pairs [x,(f x)].

      @@ -885,32 +891,32 @@

      Other functions

      (sample sq 1 5 5) ;;=> (1.0 4.0 9.0 16.0 25.0) (sample sq 1 5 5 true) -;;=> ([1.0 1.0] [2.0 4.0] [3.0 9.0] [4.0 16.0] [5.0 25.0])

      sec

      (sec v)

      Secant

      +;;=> ([1.0 1.0] [2.0 4.0] [3.0 9.0] [4.0 16.0] [5.0 25.0])

      sec

      (sec v)

      Secant

      Examples

      Usage

      (fastmath.core/sec 1.0)
       ;;=> 1.8508157176809255

      Plot of sec

      -

      sech

      (sech v)

      Hyperbolic secant

      +

      sech

      (sech v)

      Hyperbolic secant

      Examples

      Usage

      (fastmath.core/sech 1.0)
       ;;=> 0.6480542736638853

      Plot of sech

      -

      seq->double-array

      (seq->double-array vs)

      Convert sequence to double array. Returns input if vs is double array already.

      +

      seq->double-array

      (seq->double-array vs)

      Convert sequence to double array. Returns input if vs is double array already.

      Examples

      Convert

      (seq->double-array [1 2 3])
      -;;=> [D@3d219ef1
      +;;=> [D@70fc098e
       (seq (seq->double-array [1 2 3]))
       ;;=> (1.0 2.0 3.0)
       (double-array->seq (seq->double-array [1 2 3]))
       ;;=> (1.0 2.0 3.0)

      Also works on number (treated as one element list).

      (seq (seq->double-array 1))
      -;;=> (1.0)

      seq->double-double-array

      (seq->double-double-array vss)

      Convert sequence to double-array of double-arrays.

      +;;=> (1.0)

      seq->double-double-array

      (seq->double-double-array vss)

      Convert sequence to double-array of double-arrays.

      If sequence is double-array of double-arrays returns vss

      Examples

      Convert

      (seq->double-double-array [[1 2] [3 4]])
      -;;=> [[D@7d01a6fa
      +;;=> [[D@76f969bf
       (double-double-array->seq (seq->double-double-array [[1 2] [3 4]]))
       ;;=> ((1.0 2.0) (3.0 4.0))

      Also works on seq of numbers

      (seq (second (seq->double-double-array [1 2 3])))
      -;;=> (2.0)

      sfrac

      (sfrac v)

      Fractional part, always returns values from -1.0 to 1.0 (exclusive). See frac for unsigned version.

      +;;=> (2.0)

      sfrac

      (sfrac v)

      Fractional part, always returns values from -1.0 to 1.0 (exclusive). See frac for unsigned version.

      Examples

      Examples

      (sfrac 0.555)
       ;;=> 0.555
      @@ -918,82 +924,82 @@ 

      Other functions

      ;;=> -0.555

      Usage

      (fastmath.core/sfrac 1.0)
       ;;=> 0.0

      Plot of sfrac

      -

      sgn

      (sgn value)

      Return -1 when value is negative, 1 otherwise. See also signum.

      +

      sgn

      (sgn value)

      Return -1 when value is negative, 1 otherwise. See also signum.

      \( \left\{ \begin{array}{lr} 1.0 & : x \geq 0\\ -1.0 & : x < 0\\ \end{array} \right. \)

      Examples

      Usage

      (fastmath.core/sgn 1.0)
       ;;=> 1.0

      Plot of sgn

      -

      Si

      (Si x)

      Integral of sin(t)/t from 0 to x

      -

      sigmoid

      (sigmoid x)

      Sigmoid function

      +

      Si

      (Si x)

      Integral of sin(t)/t from 0 to x

      +

      sigmoid

      (sigmoid x)

      Sigmoid function

      Examples

      Usage

      (fastmath.core/sigmoid 1.0)
       ;;=> 0.7310585786300049

      Plot of sigmoid

      -

      signum

      (signum value)

      Return 1 if value is > 0, 0 if it is 0, -1 otherwise. See also sgn.

      +

      signum

      (signum value)

      Return 1 if value is > 0, 0 if it is 0, -1 otherwise. See also sgn.

      \( \left\{ \begin{array}{lr} 1.0 & : x > 0\\ -1.0 & : x < 0\\ 0.0 & : x = 0 \end{array} \right. \)

      Examples

      Usage

      (fastmath.core/signum 1.0)
       ;;=> 1.0

      Plot of signum

      -

      SILVER

      const

      ;;=> 2.414213562373095

      Silver ratio \(\delta_S\)

      -

      sin

      macro

      (sin x)

      net.jafama.FastMath/sin function wrapped in macro.

      +

      SILVER

      const

      ;;=> 2.414213562373095

      Silver ratio \(\delta_S\)

      +

      sin

      macro

      (sin x)

      net.jafama.FastMath/sin function wrapped in macro.

      Examples

      Usage

      (fastmath.core/sin 1.0)
       ;;=> 0.8414709848078964

      Plot of sin

      -

      sinc

      (sinc v)

      Sinc function.

      +

      sinc

      (sinc v)

      Sinc function.

      Examples

      Usage

      (fastmath.core/sinc 1.0)
       ;;=> 3.898171832295186E-17

      Plot of sinc

      -

      sinh

      macro

      (sinh x)

      net.jafama.FastMath/sinh function wrapped in macro.

      +

      sinh

      macro

      (sinh x)

      net.jafama.FastMath/sinh function wrapped in macro.

      Examples

      Usage

      (fastmath.core/sinh 1.0)
       ;;=> 1.1752011936438016

      Plot of sinh

      -

      SIXTH

      const

      ;;=> 0.16666666666666666

      Value of \(\frac{1}{6}\)

      -

      slice-range

      (slice-range start end cnt)(slice-range cnt)

      Slice range to get cnt number of points evenly distanced.

      -

      smooth-interpolation

      (smooth-interpolation start stop t)

      Smoothstep based interpolation. See also lerp/mlerp, quad-interpolation or cos-interpolation.

      +

      SIXTH

      const

      ;;=> 0.16666666666666666

      Value of \(\frac{1}{6}\)

      +

      slice-range

      (slice-range start end cnt)(slice-range cnt)

      Slice range to get cnt number of points evenly distanced.

      +

      smooth-interpolation

      (smooth-interpolation start stop t)

      Smoothstep based interpolation. See also lerp/mlerp, quad-interpolation or cos-interpolation.

      Examples

      Example

      (smooth-interpolation 0.0 1.0 0.123)
       ;;=> 0.041665266

      Plot of smooth-interpolation

      -

      smoothstep

      (smoothstep edge0 edge1 x)

      smoothstep

      (smoothstep edge0 edge1 x)

      Examples

      x from range.

      (smoothstep 100 200 120)
       ;;=> 0.10400000000000002

      corner case (< x edge0)

      (smoothstep 100 200 50)
       ;;=> 0.0

      corner case (> x edge1)

      (smoothstep 100 200 250)
      -;;=> 1.0

      sq

      (sq x)

      Same as pow2. \(x^2\)

      +;;=> 1.0

      sq

      (sq x)

      Same as pow2. \(x^2\)

      Examples

      Usage

      (fastmath.core/sq 1.0)
       ;;=> 1.0

      Plot of sq

      -

      sqrt

      macro

      (sqrt x)

      \(\sqrt{x}\)

      +

      sqrt

      macro

      (sqrt x)

      \(\sqrt{x}\)

      Examples

      Usage

      (fastmath.core/sqrt 1.0)
       ;;=> 1.0

      Plot of sqrt

      -

      SQRT2

      const

      ;;=> 1.4142135623730951

      \(\sqrt{2}\)

      -

      SQRT2_2

      const

      ;;=> 0.7071067811865476

      \(\frac{\sqrt{2}}{2}\)

      -

      SQRT2PI

      const

      ;;=> 2.5066282746310002

      \(\sqrt{2\pi}\)

      -

      SQRT3

      const

      ;;=> 1.7320508075688772

      \(\sqrt{3}\)

      -

      SQRT3_2

      const

      ;;=> 0.8660254037844386

      \(\frac{\sqrt{3}}{2}\)

      -

      SQRT3_3

      const

      ;;=> 0.5773502691896257

      \(\frac{\sqrt{3}}{3}\)

      -

      SQRT3_4

      const

      ;;=> 0.4330127018922193

      \(\frac{\sqrt{3}}{4}\)

      -

      SQRT5

      const

      ;;=> 2.23606797749979

      \(\sqrt{5}\)

      -

      SQRT_HALFPI

      const

      ;;=> 1.2533141373155001

      \(\sqrt{\frac{1}{2}\pi}\)

      -

      SQRTPI

      const

      ;;=> 1.7724538509055159

      \(\sqrt{\pi}\)

      -

      sum-of-products

      (sum-of-products a b c d)

      Kahan’s algorithm for (ab)+(cd) to avoid catastrophic cancellation.

      -

      tan

      macro

      (tan x)

      net.jafama.FastMath/tan function wrapped in macro.

      +

      SQRT2

      const

      ;;=> 1.4142135623730951

      \(\sqrt{2}\)

      +

      SQRT2_2

      const

      ;;=> 0.7071067811865476

      \(\frac{\sqrt{2}}{2}\)

      +

      SQRT2PI

      const

      ;;=> 2.5066282746310002

      \(\sqrt{2\pi}\)

      +

      SQRT3

      const

      ;;=> 1.7320508075688772

      \(\sqrt{3}\)

      +

      SQRT3_2

      const

      ;;=> 0.8660254037844386

      \(\frac{\sqrt{3}}{2}\)

      +

      SQRT3_3

      const

      ;;=> 0.5773502691896257

      \(\frac{\sqrt{3}}{3}\)

      +

      SQRT3_4

      const

      ;;=> 0.4330127018922193

      \(\frac{\sqrt{3}}{4}\)

      +

      SQRT5

      const

      ;;=> 2.23606797749979

      \(\sqrt{5}\)

      +

      SQRT_HALFPI

      const

      ;;=> 1.2533141373155001

      \(\sqrt{\frac{1}{2}\pi}\)

      +

      SQRTPI

      const

      ;;=> 1.7724538509055159

      \(\sqrt{\pi}\)

      +

      sum-of-products

      (sum-of-products a b c d)

      Kahan’s algorithm for (ab)+(cd) to avoid catastrophic cancellation.

      +

      tan

      macro

      (tan x)

      net.jafama.FastMath/tan function wrapped in macro.

      Examples

      Usage

      (fastmath.core/tan 1.0)
       ;;=> 1.5574077246549018

      Plot of tan

      -

      tanh

      macro

      (tanh x)

      net.jafama.FastMath/tanh function wrapped in macro.

      +

      tanh

      macro

      (tanh x)

      net.jafama.FastMath/tanh function wrapped in macro.

      Examples

      Usage

      (fastmath.core/tanh 1.0)
       ;;=> 0.7615941559557649

      Plot of tanh

      -

      TAU

      const

      ;;=> 6.283185307179586

      Alias for TWO_PI

      -

      THIRD

      const

      ;;=> 0.3333333333333333

      Value of \(\frac{1}{3}\)

      -

      THIRD_PI

      const

      ;;=> 1.0471975511965976

      Value of \(\frac{\pi}{3}\)

      -

      trigamma

      macro

      (trigamma x)

      Derivative of digamma.

      +

      TAU

      const

      ;;=> 6.283185307179586

      Alias for TWO_PI

      +

      THIRD

      const

      ;;=> 0.3333333333333333

      Value of \(\frac{1}{3}\)

      +

      THIRD_PI

      const

      ;;=> 1.0471975511965976

      Value of \(\frac{\pi}{3}\)

      +

      trigamma

      macro

      (trigamma x)

      Derivative of digamma.

      Examples

      Usage

      (fastmath.core/trigamma 1.0)
       ;;=> 1.6449340668481562

      Plot of trigamma

      -

      trunc

      (trunc v)

      Truncate fractional part, keep sign. Returns double.

      +

      trunc

      (trunc v)

      Truncate fractional part, keep sign. Returns double.

      Examples

      Examples

      (trunc 1.234)
       ;;=> 1.0
      @@ -1001,13 +1007,14 @@ 

      Other functions

      ;;=> -1.0

      Usage

      (fastmath.core/trunc 1.0)
       ;;=> 1.0

      Plot of trunc

      -

      TWO_INV_PI

      const

      ;;=> 0.6366197723675814

      Value of \(\frac{2}{\pi}\)

      -

      TWO_PI

      const

      ;;=> 6.283185307179586

      Value of \(2 {\pi}\)

      -

      TWO_THIRD

      const

      ;;=> 0.6666666666666666

      Value of \(\frac{2}{3}\)

      -

      unsigned-bit-shift-right

      macro

      (unsigned-bit-shift-right x y)

      fastmath.java.PrimitiveMath/unsignedShiftRight function wrapped in macro.

      +

      TWO_INV_PI

      const

      ;;=> 0.6366197723675814

      Value of \(\frac{2}{\pi}\)

      +

      TWO_PI

      const

      ;;=> 6.283185307179586

      Value of \(2 {\pi}\)

      +

      TWO_THIRD

      const

      ;;=> 0.6666666666666666

      Value of \(\frac{2}{3}\)

      +

      ulp

      (ulp v)

      Unit in the Last Place, distance between next value larger than v and v

      +

      unsigned-bit-shift-right

      macro

      (unsigned-bit-shift-right x y)

      fastmath.java.PrimitiveMath/unsignedShiftRight function wrapped in macro.

      unuse-primitive-operators

      (unuse-primitive-operators)

      Undoes the work of use-primitive-operators. This is idempotent.

      -

      use-primitive-operators

      (use-primitive-operators)(use-primitive-operators skip-set)

      Replaces Clojure’s arithmetic and number coercion functions with primitive equivalents. These are defined as macros, so they cannot be used as higher-order functions. This is an idempotent operation. Undo with unuse-primitive-operators.

      -

      valid-double?

      (valid-double? v)

      Check if number is invalid

      +

      use-primitive-operators

      (use-primitive-operators)(use-primitive-operators skip-set)

      Replaces Clojure’s arithmetic and number coercion functions with primitive equivalents. These are defined as macros, so they cannot be used as higher-order functions. This is an idempotent operation. Undo with unuse-primitive-operators.

      +

      valid-double?

      (valid-double? v)

      Check if number is invalid

      Examples

      Usage

      (valid-double? ##Inf)
       ;;=> false
      @@ -1020,9 +1027,9 @@ 

      Other functions

      (valid-double? ##NaN) ;;=> false -;; Test: ok.

      vercos

      (vercos v)

      Vercosine

      -

      versin

      (versin v)

      Versine

      -

      wrap

      (wrap [start stop] value)(wrap start stop value)

      Wrap overflowed value into the range, similar to ofWrap.

      +;; Test: ok.

      vercos

      (vercos v)

      Vercosine

      +

      versin

      (versin v)

      Versine

      +

      wrap

      (wrap [start stop] value)(wrap start stop value)

      Wrap overflowed value into the range, similar to ofWrap.

      Examples

      Example 1

      (wrap 0 -1 1)
       ;;=> -1.0

      Example 2 (value outside range)

      @@ -1030,10 +1037,10 @@

      Other functions

      ;;=> -1.0000000000000022

      Example 3 (reversed range)

      (wrap 0.7 0.5 1.0)
       ;;=> 0.6000000000000001

      Plot of wrap

      -

      xexpx

      (xexpx x)

      x * exp(x)

      -

      xexpy

      (xexpy x y)

      x * exp(x)

      -

      xlog1py

      (xlog1py x y)

      x * log(1+y)

      -

      xlogx

      (xlogx x)

      x * log(x)

      -

      xlogy

      (xlogy x y)

      x * log(y)

      -

      zero?

      macro

      (zero? x)

      fastmath.java.PrimitiveMath/isZero function wrapped in macro.

      +

      xexpx

      (xexpx x)

      x * exp(x)

      +

      xexpy

      (xexpy x y)

      x * exp(x)

      +

      xlog1py

      (xlog1py x y)

      x * log(1+y)

      +

      xlogx

      (xlogx x)

      x * log(x)

      +

      xlogy

      (xlogy x y)

      x * log(y)

      +

      zero?

      macro

      (zero? x)

      fastmath.java.PrimitiveMath/isZero function wrapped in macro.

      \ No newline at end of file diff --git a/docs/fastmath.curves.html b/docs/fastmath.curves.html index c092d465..021812d5 100644 --- a/docs/fastmath.curves.html +++ b/docs/fastmath.curves.html @@ -1,6 +1,6 @@ -fastmath.curves documentation

      fastmath.curves

      Collection of parametric curves

      +fastmath.curves documentation

      fastmath.curves

      Collection of parametric curves

      Categories

        Other vars: add curve curves-list mult parametrization

        add

        (add c1 c2)

        Add two curves (by adding resulting vectors).

        curve

        multimethod

        Return vector field for given name and parametrization.

        Default parametrization is random.

        diff --git a/docs/fastmath.distance.html b/docs/fastmath.distance.html index 0742e472..45b15047 100644 --- a/docs/fastmath.distance.html +++ b/docs/fastmath.distance.html @@ -1,6 +1,6 @@ -fastmath.distance documentation

        fastmath.distance

        Distance objects.

        +fastmath.distance documentation

        fastmath.distance

        Distance objects.

        Objects implement IFn, Smile and Apache Commons Math distance interfaces.

        angular

        Angular distance

        Examples

        Usage

        diff --git a/docs/fastmath.easings.html b/docs/fastmath.easings.html index b51be7ad..bbe602ca 100644 --- a/docs/fastmath.easings.html +++ b/docs/fastmath.easings.html @@ -1,6 +1,6 @@ -fastmath.easings documentation

        fastmath.easings

        Easing functions.

        +fastmath.easings documentation

        fastmath.easings

        back-in

        (back-in t)(back-in s t)

        BackIn easing.

        Parameter s (default: 1.70158) defines overshoot.

        diff --git a/docs/fastmath.efloat.html b/docs/fastmath.efloat.html index a9280ae4..b01412b9 100644 --- a/docs/fastmath.efloat.html +++ b/docs/fastmath.efloat.html @@ -1,6 +1,6 @@ -fastmath.efloat documentation

        fastmath.efloat

        (re)Implementation of EFloat/Interval from pbrt-v3/pbrt-v4.

        +fastmath.efloat documentation

        fastmath.efloat

        (re)Implementation of EFloat/Interval from pbrt-v3/pbrt-v4.

        A floating point number structure which keeps a track of error caused by operations.

        -

        ->double

        (->double ev)

        abs

        (abs ev)

        absolute-error

        (absolute-error ev)

        acos

        (acos ev)

        add

        (add ev1 ev2)

        addf

        (addf ev v)

        ceil

        (ceil ev)

        cos

        (cos ev)

        difference-of-products

        (difference-of-products a b c d)

        div

        (div ev1 ev2)

        divf

        (divf ev v)

        efloat

        (efloat v)(efloat v err)(efloat v low high)

        Create EFloat object from a single value or low and high values.

        -

        equals?

        (equals? ev v)

        floor

        (floor ev)

        fma

        (fma ev1 ev2 ev3)

        in-range?

        (in-range? ev v)

        lower-bound

        (lower-bound ev)

        max

        (max ev1 ev2)

        mid-point

        (mid-point ev)

        min

        (min ev1 ev2)

        mul

        (mul ev1 ev2)

        mulf

        (mulf ev v)

        neg

        (neg ev)

        quadratic

        (quadratic a b c)

        relative-error

        (relative-error ev)

        sin

        (sin ev)

        sq

        (sq ev)

        sqrt

        (sqrt ev)

        sub

        (sub ev1 ev2)

        subf

        (subf ev v)

        sum-of-products

        (sum-of-products a b c d)

        upper-bound

        (upper-bound ev)

        width

        (width ev)
        \ No newline at end of file +

        ->double

        (->double ev)

        abs

        (abs ev)

        absolute-error

        (absolute-error ev)

        acos

        (acos ev)

        add

        (add ev1 ev2)

        addf

        (addf ev v)

        ceil

        (ceil ev)

        cos

        (cos ev)

        difference-of-products

        (difference-of-products a b c d)

        div

        (div ev1 ev2)

        divf

        (divf ev v)

        efloat

        (efloat v)(efloat v err)(efloat v low high)

        Create EFloat object from a single value or low and high values.

        +

        equals?

        (equals? ev v)

        floor

        (floor ev)

        fma

        (fma ev1 ev2 ev3)

        in-range?

        (in-range? ev v)

        lower-bound

        (lower-bound ev)

        max

        (max ev1 ev2)

        mid-point

        (mid-point ev)

        min

        (min ev1 ev2)

        mul

        (mul ev1 ev2)

        mulf

        (mulf ev v)

        neg

        (neg ev)

        quadratic

        (quadratic a b c)

        relative-error

        (relative-error ev)

        sin

        (sin ev)

        sq

        (sq ev)

        sqrt

        (sqrt ev)

        sub

        (sub ev1 ev2)

        subf

        (subf ev v)

        sum-of-products

        (sum-of-products a b c d)

        upper-bound

        (upper-bound ev)

        width

        (width ev)
        \ No newline at end of file diff --git a/docs/fastmath.fields.html b/docs/fastmath.fields.html index 1ba96a5e..cf35572f 100644 --- a/docs/fastmath.fields.html +++ b/docs/fastmath.fields.html @@ -1,6 +1,6 @@ -fastmath.fields documentation

        fastmath.fields

        Vector field functions.

        +fastmath.fields documentation

        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

        @@ -33,7 +33,7 @@

        Combinations

      • randomize-configuration - change parametrization for given configuration.
      • *skip-random-fields*

        dynamic

        When random configuration for combine is used. Skip vector fields which are random.

        -

        angle-between

        Angle between input vector and result of the vector field.

        +

        angle-between

        Angle between input vector and result of the vector field.

        In case when two vector fields are given, cross product is taken from result of vector fields.

        Resulting value is from range [-PI,PI].

        Examples

        Usage

        @@ -41,7 +41,7 @@

        Combinations

        ;;=> 0.42920367320510344

        Usage (two fields)

        (let [f (angle-between (field :sinusoidal) (field :swirl))]
           (f (v/vec2 1 1)))
        -;;=> 0.42920367320510255

        combine

        (combine {:keys [type name amount config var step var1 var2]})(combine)

        Create composite vector field function based on configuration

        +;;=> 0.42920367320510255

        combine

        (combine {:keys [type name amount config var step var1 var2]})(combine)

        Create composite vector field function based on configuration

        Call without argument to get random vector field.

        Configuration is a tree structure where nodes are one of the following

        Examples

        Create random combination

        (let [f (combine)] (f (v/vec2 -0.5 0.5)))
        -;;=> [-1.6783534698442983 -0.06029950436770843]

        Create combination for given configuration

        +;;=> [-0.5217406307918071 -0.12663102804343862]

        Create combination for given configuration

        (let [conf {:type :operation,
                     :name :comp,
                     :var1 {:type :variation,
        @@ -89,55 +89,55 @@ 

        Combinations

        :amount 1.0} f (combine conf)] (f (v/vec2 -0.5 0.5))) -;;=> [0.18532823300678739 0.437177284257253]

        composition

        (composition f1 f2 amount)(composition f1 f2)

        Compose two vector fields.

        +;;=> [0.18532823300678739 0.437177284257253]

        composition

        (composition f1 f2 amount)(composition f1 f2)

        Compose two vector fields.

        Examples

        Usage

        (let [field-1 (field :sinusoidal)
               field-2 (field :swirl)
               field-comp (composition field-1 field-2)]
           (field-comp (v/vec2 0.5 0.3)))
        -;;=> [-0.11582232201566794 0.5408299143217236]

        cross

        2d cross product (det of the 2x2 matrix) of the input vector and result of the vector field.

        +;;=> [-0.11582232201566794 0.5408299143217236]

        cross

        2d cross product (det of the 2x2 matrix) of the input vector and result of the vector field.

        In case when two vector fields are given, cross product is taken from results of vector fields.

        Examples

        Usage

        (let [f (cross (field :swirl))] (f (v/vec2 1 1)))
         ;;=> 0.8322936730942845

        Usage (two fields)

        (let [f (cross (field :sinusoidal) (field :swirl))] (f (v/vec2 1 1)))
        -;;=> -0.7003509767480289

        curl

        (curl f)(curl f h)

        Curl (2d version) of the field.

        +;;=> -0.7003509767480289

        curl

        (curl f)(curl f h)

        Curl (2d version) of the field.

        See: https://youtu.be/rB83DpBJQsE?t=855

        Examples

        Usage

        (let [f (curl (field :swirl) 1.0E-8)] (f (v/vec2 0.0 0.0)))
        -;;=> -2.0

        derivative

        (derivative f amount h)(derivative f h)(derivative f)

        Calculate directional derivative of fn. Derivative is calculated along 1,1 vector with h as a step (default 1.0e-6).

        +;;=> -2.0

        derivative

        (derivative f amount h)(derivative f h)(derivative f)

        Calculate directional derivative of fn. Derivative is calculated along 1,1 vector with h as a step (default 1.0e-6).

        Examples

        Usage

        (let [f (derivative (field :sinusoidal) 1.0E-8)] (f (v/vec2 0.0 0.0)))
        -;;=> [1.0 1.0]

        divergence

        (divergence f)(divergence f h)

        Divergence of the field.

        +;;=> [1.0 1.0]

        divergence

        (divergence f)(divergence f h)

        Divergence of the field.

        See: https://youtu.be/rB83DpBJQsE?t=855

        Examples

        Usage

        (let [f (divergence (field :sinusoidal) 1.0E-8)] (f (v/vec2 0.0 0.0)))
        -;;=> 2.0

        dot

        Dot product of the input vector and result of the vector field.

        +;;=> 2.0

        dot

        Dot product of the input vector and result of the vector field.

        In case when two vector fields are given, cross product is taken from result of vector fields.

        Examples

        Usage

        (let [f (dot (field :swirl))] (f (v/vec2 1 1)))
         ;;=> 1.8185948536513636

        Usage (two fields)

        (let [f (dot (field :sinusoidal) (field :swirl))] (f (v/vec2 1 1)))
        -;;=> 1.5302948024685854

        field

        multimethod

        Return vector field for given name and options: amount (scaling factor) and parametrization.

        +;;=> 1.5302948024685854

        field

        multimethod

        Return vector field for given name and options: amount (scaling factor) and parametrization.

        Default scaling factor is 1.0, default parametrization is random.

        Resulting function operates on Vec2 type.

        Examples

        Get vector field by name

        (field :sinusoidal)
        -;;=> fastmath.fields.s$sinusoidal$fn__29997@158c442a
        +;;=> fastmath.fields.s$sinusoidal$fn__30073@274c6ddd
         ((field :sinusoidal) (v/vec2 m/HALF_PI m/HALF_PI))
         ;;=> [1.0 1.0]

        Get vector field by name and scale

        (field :sinusoidal 0.5)
        -;;=> fastmath.fields.s$sinusoidal$fn__29997@5e3efdb9
        +;;=> fastmath.fields.s$sinusoidal$fn__30073@6358c9ae
         ((field :sinusoidal 0.5) (v/vec2 m/HALF_PI m/HALF_PI))
         ;;=> [0.5 0.5]

        Apply parametrization

        (let [params (parametrization :cpow3)
               f (field :cpow3 1.0 params)]
           {:parametrization params, :value (f (v/vec2 -1.0 1.0))})
        -;;=> {:parametrization {:d 13.550332230506799,
        -;;=>                    :divisor -1.4008224545855428,
        -;;=>                    :r 0.9210964153948565,
        -;;=>                    :spread 1.5706529922073926},
        -;;=>  :value [1.0944626140632712 3.4694309860675565]}

        fields-list

        Examples

        List of all vector field names.

        +;;=> {:parametrization {:d -14.084455698606515, +;;=> :divisor -1.2957732414050445, +;;=> :r 0.8931076301162941, +;;=> :spread 2.8389757614011772}, +;;=> :value [-0.02294518426545013 0.4561549708802658]}

        fields-list

        Examples

        List of all vector field names.

        (sort fields-list)
         ;;=> (:acosech
         ;;=>  :acosh
        @@ -332,7 +332,7 @@ 

        Combinations

        ;;=> :woggle :x ;;=> :xheart :xtrb ;;=> :y :yinyang -;;=> :z :zsymmetry)

        fields-list-not-random

        Examples

        List of all vector fields which are not random.

        +;;=> :z :zsymmetry)

        fields-list-not-random

        Examples

        List of all vector fields which are not random.

        (sort fields-list-not-random)
         ;;=> (:acoth
         ;;=>  :anamorphcyl :arcsech2
        @@ -466,7 +466,7 @@ 

        Combinations

        ;;=> :wedge :wedgesph ;;=> :whorl :x ;;=> :xheart :y -;;=> :z :zsymmetry)

        fields-list-random

        Examples

        List of all vector fields which give random results.

        +;;=> :z :zsymmetry)

        fields-list-random

        Examples

        List of all vector fields which give random results.

        (sort fields-list-random)
         ;;=> (:acosech
         ;;=>  :acosh :apocarpet
        @@ -528,81 +528,73 @@ 

        Combinations

        ;;=> :truchethexfill :twintrian ;;=> :vogel :wallpaper ;;=> :wedgejulia :woggle -;;=> :xtrb :yinyang)

        fields-map

        grad-x

        (grad-x f amount h)(grad-x f h)(grad-x f)

        Calculate gradient along x axis.

        +;;=> :xtrb :yinyang)

        fields-map

        grad-x

        (grad-x f amount h)(grad-x f h)(grad-x f)

        Calculate gradient along x axis.

        Examples

        Usage

        (let [f (grad-x (field :sinusoidal) 1.0E-8)] (f (v/vec2 0.0 0.0)))
        -;;=> [1.0 0.0]

        grad-y

        (grad-y f amount h)(grad-y f h)(grad-y f)

        Calculate gradient along y axis.

        +;;=> [1.0 0.0]

        grad-y

        (grad-y f amount h)(grad-y f h)(grad-y f)

        Calculate gradient along y axis.

        Examples

        Usage

        (let [f (grad-y (field :sinusoidal) 1.0E-8)] (f (v/vec2 0.0 0.0)))
        -;;=> [0.0 1.0]

        heading

        (heading f)

        Angle of the vectors from field.

        +;;=> [0.0 1.0]

        heading

        (heading f)

        Angle of the vectors from field.

        Examples

        Usage

        (let [f (heading (field :sinusoidal))]
           (m/degrees (f (v/vec2 m/HALF_PI m/HALF_PI))))
        -;;=> 45.0

        jacobian

        (jacobian f)(jacobian f h)

        Det of Jacobian of the field

        +;;=> 45.0

        jacobian

        (jacobian f)(jacobian f h)

        Det of Jacobian of the field

        Examples

        Usage

        (let [f (jacobian (field :sinusoidal) 1.0E-8)] (f (v/vec2 0.0 0.0)))
        -;;=> 1.0

        magnitude

        (magnitude f)

        Magnitude of the vectors from field.

        +;;=> 1.0

        magnitude

        (magnitude f)

        Magnitude of the vectors from field.

        Examples

        Usage

        (let [f (magnitude (field :sinusoidal))]
           (f (v/vec2 m/HALF_PI m/HALF_PI)))
        -;;=> 1.4142135623730951

        multiplication

        (multiplication f1 f2 amount)(multiplication f1 f2)

        Multiply two vector fields (as a element-wise multiplication of results).

        +;;=> 1.4142135623730951

        multiplication

        (multiplication f1 f2 amount)(multiplication f1 f2)

        Multiply two vector fields (as a element-wise multiplication of results).

        Examples

        Usage

        (let [field-1 (field :sinusoidal)
               field-2 (field :swirl)
               field-multiplication (multiplication field-1 field-2)]
           (field-multiplication (v/vec2 0.5 0.3)))
        -;;=> [-0.05565308460418609 0.1688671791104423]

        parametrization

        multimethod

        Return random parametrization map for given field.

        +;;=> [-0.05565308460418609 0.1688671791104423]

        parametrization

        multimethod

        Return random parametrization map for given field.

        Optinally you can pass part of the parametrization. In this case function will add remaining keys with randomly generated values.

        If field doesn’t have parametrization, empty map will be returned.

        See field.

        Examples

        Get random parametrization for given field

        (parametrization :auger)
        -;;=> {:freq -2.7581161401981023,
        -;;=>  :scale 1.5185071494571902,
        -;;=>  :sym 1.6604261172323973,
        -;;=>  :weight -0.03224849866297275}

        Add lacking fields

        +;;=> {:freq 2.5825461333040565, +;;=> :scale -1.5130389003393934, +;;=> :sym 1.133320717504653, +;;=> :weight 0.11842671408241556}

        Add lacking fields

        (parametrization :auger {:scale 1.0, :freq 1.0})
         ;;=> {:freq 1.0,
         ;;=>  :scale 1.0,
        -;;=>  :sym -1.780967830401293,
        -;;=>  :weight -0.2100609105377551}

        Returns empty map when field doesn’t have parametrization

        +;;=> :sym 1.2115684744663069, +;;=> :weight 0.26201326923916457}

        Returns empty map when field doesn’t have parametrization

        (parametrization :sinusoidal)
         ;;=> {}

        random-configuration

        (random-configuration)(random-configuration depth)(random-configuration depth f)

        Create random configuration for combine function. Optionally with depth (0 = only root is created).

        See combine for structure.

        Bind *skip-random-fields* to true to exclude fields which are random.

        Examples

        Generate random configuration

        (random-configuration)
        -;;=> {:amount 1.0,
        -;;=>  :config {:rot 2.6181978084699455, :twist -5.154127002205628},
        -;;=>  :name :disc2,
        -;;=>  :type :variation}

        One node configuration

        +;;=> {:amount 1.0, :config {}, :name :squircular, :type :variation}

        One node configuration

        (random-configuration 0)
        -;;=> {:amount 1.0, :config {}, :name :sqrt-asinh, :type :variation}

        Configuration with depth 2

        +;;=> {:amount 1.0, :config {}, :name :diamond, :type :variation}

        Configuration with depth 2

        (random-configuration 2)
         ;;=> {:amount 1.0,
        -;;=>  :name :deriv,
        -;;=>  :step 0.2168858796955329,
        +;;=>  :name :comp,
         ;;=>  :type :operation,
        -;;=>  :var {:amount 1.0,
        -;;=>        :name :comp,
        -;;=>        :type :operation,
        -;;=>        :var1 {:amount 1.0,
        -;;=>               :config {:contrast 0.07274760605121522,
        -;;=>                        :phi1 354.2573549924269,
        -;;=>                        :phi2 17.20000230260112,
        -;;=>                        :pow 2.9714988331436114,
        -;;=>                        :radius 1.0567259159882174,
        -;;=>                        :thickness 0.7105285279534599},
        -;;=>               :name :glynnsim2,
        -;;=>               :type :variation},
        -;;=>        :var2 {:amount 1.0,
        -;;=>               :config {:x1 0.1664017937624582,
        -;;=>                        :x2 1.2050407496891395,
        -;;=>                        :y1 1.8475285003941921,
        -;;=>                        :y2 0.584446148926949},
        -;;=>               :name :cosh2bs,
        -;;=>               :type :variation}}}

        random-field

        (random-field)(random-field depth)

        Create randomized field (optional depth can be provided).

        -

        randomize-configuration

        (randomize-configuration f)

        Randomize values for given configuration. Keeps structure untouched.

        +;;=> :var1 {:amount 1.0, +;;=> :name :deriv, +;;=> :step 0.9667944074740565, +;;=> :type :operation, +;;=> :var {:amount 1.0, +;;=> :config {:a -0.8525853754431658, +;;=> :b 0.7772607155299691, +;;=> :c 0.7170063828409245, +;;=> :d -0.7067016229715266, +;;=> :e -0.9102525466961031, +;;=> :f 0.26099060732035717, +;;=> :mode true}, +;;=> :name :chunk, +;;=> :type :variation}}, +;;=> :var2 {:amount 1.0, :config {}, :name :invpolar, :type :variation}}

        random-field

        (random-field)(random-field depth)

        Create randomized field (optional depth can be provided).

        +

        randomize-configuration

        (randomize-configuration f)

        Randomize values for given configuration. Keeps structure untouched.

        Examples

        Usage

        (let [conf {:type :variation,
                     :name :blocky,
        @@ -610,17 +602,17 @@ 

        Combinations

        :config {:x -1.4, :y 0.9, :mp 2.6}}] [(randomize-configuration conf) (randomize-configuration conf)]) ;;=> [{:amount 1.0, -;;=> :config {:mp 1.7953356115794685, -;;=> :x -1.0069950566912558, -;;=> :y -0.913306464273377}, +;;=> :config {:mp 0.8986513423304683, +;;=> :x 1.1904936014304281, +;;=> :y -0.6462182660765559}, ;;=> :name :blocky, ;;=> :type :variation} ;;=> {:amount 1.0, -;;=> :config {:mp 1.4403319180575245, -;;=> :x -0.985190457995947, -;;=> :y 0.6687955091301594}, +;;=> :config {:mp 1.9154806023569149, +;;=> :x 0.9869828060465601, +;;=> :y -1.160872986608712}, ;;=> :name :blocky, -;;=> :type :variation}]

        scalar->vector-field

        (scalar->vector-field scalar f)(scalar->vector-field scalar f1 f2)

        Returns vector field build from scalar fields of the input vector and result of the vector field.

        +;;=> :type :variation}]

        scalar->vector-field

        (scalar->vector-field scalar f)(scalar->vector-field scalar f1 f2)

        Returns vector field build from scalar fields of the input vector and result of the vector field.

        Examples

        Usage

        (let [f (scalar->vector-field v/heading (field :sinusoidal))]
           (v/applyf (f (v/vec2 m/HALF_PI m/HALF_PI)) m/degrees))
        @@ -629,10 +621,10 @@ 

        Combinations

        (field :sinusoidal) (field :julia))] (v/applyf (f (v/vec2 m/HALF_PI m/HALF_PI)) m/degrees)) -;;=> [45.0 22.500000000000004]

        sum

        (sum f1 f2 amount)(sum f1 f2)

        Add two vector fields.

        +;;=> [45.0 -157.50000000000003]

        sum

        (sum f1 f2 amount)(sum f1 f2)

        Add two vector fields.

        Examples

        Usage

        (let [field-1 (field :sinusoidal)
               field-2 (field :swirl)
               field-sum (sum field-1 field-2)]
           (field-sum (v/vec2 0.5 0.3)))
        -;;=> [0.3633426850161062 0.866943667067757]
        \ No newline at end of file +;;=> [0.3633426850161062 0.866943667067757]
        \ No newline at end of file diff --git a/docs/fastmath.gp.html b/docs/fastmath.gp.html index 1affca87..c20339da 100644 --- a/docs/fastmath.gp.html +++ b/docs/fastmath.gp.html @@ -1,42 +1,42 @@ -fastmath.gp documentation

        fastmath.gp

        Gaussian Processes

        +fastmath.gp documentation

        fastmath.gp

        gaussian-process

        (gaussian-process xss ys)(gaussian-process xss ys {:keys [kscale kernel noise normalize? L?], :or {kscale 1.0, kernel (k/kernel :gaussian 1.0), normalize? false, noise 1.0E-8, L? true}})

        Examples

        Object creation

        (gaussian-process [1 2 3] [-1 2 1])
        -;;=> fastmath.gp.GaussianProcess@2e8a0ea8
        +;;=> fastmath.gp.GaussianProcess@7014908d
         (gaussian-process [1 2 3]
                           [-1 2 1]
                           {:normalize? true,
                            :kernel (k/kernel :gaussian 0.5),
                            :kscale 2.0,
                            :noise 0.1})
        -;;=> fastmath.gp.GaussianProcess@7c6f6097

        L

        (L ys w chol n)(L gp-object)

        posterior-samples

        (posterior-samples gp-object xvals)(posterior-samples gp-object xvals stddev?)

        Examples

        With gaussian kernel

        +;;=> fastmath.gp.GaussianProcess@7c5fba85

        L

        (L ys w chol n)(L gp-object)

        posterior-samples

        (posterior-samples gp-object xvals)(posterior-samples gp-object xvals stddev?)

        Examples

        With gaussian kernel

        (let [gp (gaussian-process [-5 1 2]
                                    [17 10 12]
                                    {:kernel (k/kernel :gaussian 0.5)})]
           (posterior-samples gp (range -5 2 0.9)))
        -;;=> (17.00000382183717
        -;;=>  3.469134911744126
        -;;=>  0.05639732263679262
        -;;=>  0.4407898012542572
        -;;=>  -1.1822643945486515
        -;;=>  1.7996161405577882
        -;;=>  4.432909454920831
        -;;=>  11.175489507479758)

        Plot of 10 posteriors (with gaussian kernel)

        +;;=> (16.999911271700068 +;;=> 1.4396261676852156 +;;=> -0.5662562350658056 +;;=> -0.26381866980281693 +;;=> -0.5616964300404151 +;;=> 0.32780559947465765 +;;=> 5.603781510038106 +;;=> 9.397793642342432)

        Plot of 10 posteriors (with gaussian kernel)

        With periodic kernel

        (let [gp (gaussian-process [-5 1 2]
                                    [17 10 12]
                                    {:kernel (k/kernel :periodic 0.2 6.5)})]
           (posterior-samples gp (range -5 2 0.9)))
        -;;=> (16.999957394562713
        -;;=>  0.39918841594982335
        -;;=>  0.6947387524410465
        -;;=>  0.8668027797681881
        -;;=>  -0.30261928761149637
        -;;=>  1.53149857822521
        -;;=>  -0.6431299741943961
        -;;=>  14.112061105415885)

        Plot of 10 posteriors (with periodic kernel)

        +;;=> (17.00003848656039 +;;=> 4.275540849613845 +;;=> 0.9307956232029831 +;;=> -1.8504644482052286 +;;=> 0.29385792463691496 +;;=> 0.47311529931052004 +;;=> 0.27135029649557507 +;;=> 13.501674596943719)

        Plot of 10 posteriors (with periodic kernel)

        predict

        (predict gp-object xval)(predict gp-object xval stddev?)

        Examples

        Usage

        (let [gp (gaussian-process [-5 1 2] [17 10 12])]
           [(gp 1.1) (predict gp 1.1)])
        @@ -67,30 +67,30 @@
         ;;=>  [6.277135459489308 0.739305317305734])

        prior-samples

        (prior-samples gp-object xvals)

        Examples

        Usage

        (let [gp (gaussian-process [0 1 -2 -2.001] [-2 3 0.5 -0.6])]
           (prior-samples gp (range 0 1 0.1)))
        -;;=> (0.6169941324989417
        -;;=>  0.7417796225662417
        -;;=>  0.8573053364748918
        -;;=>  0.9637098017534088
        -;;=>  1.0605747005533621
        -;;=>  1.1468076303547878
        -;;=>  1.2206802441175801
        -;;=>  1.280013808525612
        -;;=>  1.322481015514251
        -;;=>  1.345971476764109
        -;;=>  1.3489626436116557)

        Plot of 10 priors

        +;;=> (0.5513335229785846 +;;=> 0.5012297169060579 +;;=> 0.4385817858195753 +;;=> 0.36437646639668436 +;;=> 0.2804423584423929 +;;=> 0.18914414674256888 +;;=> 0.09304839529620974 +;;=> -0.005376263636502346 +;;=> -0.10397293800368286 +;;=> -0.20099438784565596 +;;=> -0.2950807811768326)

        Plot of 10 priors

        With added noise

        (let [gp
               (gaussian-process [0 1 -2 -2.001] [-2 3 0.5 -0.6] {:noise 0.1})]
           (prior-samples gp (range 0 1 0.1)))
        -;;=> (0.4666480150602599
        -;;=>  0.42741472858998836
        -;;=>  0.3627654448154403
        -;;=>  0.27308195820743597
        -;;=>  0.16030445319322284
        -;;=>  0.027659566848698178
        -;;=>  -0.12067661975798452
        -;;=>  -0.279941560519676
        -;;=>  -0.4451428187970916
        -;;=>  -0.611379745903101
        -;;=>  -0.7741132697704154)

        Plot of 10 priors (with noise)

        +;;=> (-0.08439228071890412 +;;=> -0.13608678909072633 +;;=> -0.19293817674278546 +;;=> -0.2559562744697197 +;;=> -0.32611484009258196 +;;=> -0.40411339705714877 +;;=> -0.49013874945984665 +;;=> -0.5836576095416394 +;;=> -0.6832733741851441 +;;=> -0.7866755749316164 +;;=> -0.8907035794074853)

        Plot of 10 priors (with noise)

        \ No newline at end of file diff --git a/docs/fastmath.grid.html b/docs/fastmath.grid.html index 8ff0dcf7..6e8bbb41 100644 --- a/docs/fastmath.grid.html +++ b/docs/fastmath.grid.html @@ -1,6 +1,6 @@ -fastmath.grid documentation

        fastmath.grid

        Grid calculation functions.

        +fastmath.grid documentation

        fastmath.grid

        Grid calculation functions.

        Convert 2d coordinates into various grid coordinates and back.

        Terms used:

        b-spline

        (b-spline xs ys)(b-spline degree-or-knots xs ys)

        B-spline for given points, default degree equals samples count - 1.

        more

        Examples

        Usage

        (interpolate b-spline ...)
         ;;=> 0.5600852765013091

        B-Spline plot

        B-Spline plot (degree=1)

        B-Spline plot (with knots)

        -

        b-spline-interp

        (b-spline-interp xs ys)(b-spline-interp degree xs ys)(b-spline-interp degree h xs ys)

        B-spline interpolation.

        +

        b-spline-interp

        (b-spline-interp xs ys)(b-spline-interp degree xs ys)(b-spline-interp degree h xs ys)

        B-spline interpolation.

        See:

        • 2 or 3 arity - exact interpolation using b-spline, default degree = 3 (more)
        • @@ -71,41 +72,41 @@

          2d

          ;;=> 0.6903406231405653

        B-Spline interpolation plot

        B-Spline interpolation plot (degree=5)

        B-Spline interpolation plot (degree=3, h=6)

        -

        bicubic

        (bicubic xs ys vs)

        Bicubic 2d.

        +

        bicubic

        (bicubic xs ys vs)

        Bicubic 2d.

        Grid based.

        Source: Apache Commons Math.

        Examples

        Usage

        (interpolate2d bicubic ...)
         ;;=> 0.07081337259133846

        Bicubic plot

        -

        bicubic-smile

        (bicubic-smile xs ys vs)

        Bicubic 2d.

        +

        bicubic-smile

        (bicubic-smile xs ys vs)

        Bicubic 2d.

        Grid based.

        Source: Smile.

        Examples

        Usage

        (interpolate2d bicubic-smile ...)
         ;;=> 0.07081337259133846

        Bicubic (Smile) plot

        -

        bilinear

        (bilinear xs ys vs)

        Bilinear 2d.

        +

        bilinear

        (bilinear xs ys vs)

        Bilinear 2d.

        Grid based.

        Source: Smile.

        Examples

        Usage

        (interpolate2d bilinear ...)
         ;;=> 0.062068616254939334

        Bilinear plot

        -

        cubic-2d

        (cubic-2d xs ys vs)

        Cubic spline 2d.

        +

        cubic-2d

        (cubic-2d xs ys vs)

        Cubic spline 2d.

        Grid based.

        Source: Smile.

        Examples

        Usage

        (interpolate2d cubic-2d ...)
         ;;=> 0.053984474655155074

        Cubic-2d plot

        -

        cubic-spline

        (cubic-spline xs ys)

        Cubic spline interpolation.

        +

        cubic-spline

        (cubic-spline xs ys)

        Cubic spline interpolation.

        Source: Smile.

        Examples

        Usage

        (interpolate cubic-spline ...)
         ;;=> 0.6809644344471792

        Cubic spline plot

        -

        divided-difference

        (divided-difference xs ys)

        Create Divided Difference Algorithm for interpolation.

        +

        divided-difference

        (divided-difference xs ys)

        Create Divided Difference Algorithm for interpolation.

        Source: Apache Commons Math.

        Examples

        Usage

        (interpolate divided-difference ...)
         ;;=> 0.6789478287835669

        Divided difference plot

        -

        interpolators-1d-list

        Map of 1d interpolation functions

        +

        interpolators-1d-list

        Map of 1d interpolation functions

        Examples

        List of names

        (keys interpolators-1d-list)
         ;;=> (:linear-smile :divided-difference :rbf
        @@ -116,27 +117,27 @@ 

        2d

        ;;=> :polynomial :shepard ;;=> :linear :microsphere ;;=> :monotone :step -;;=> :b-spline-interp :akima)

        interpolators-2d-list

        Map of 2d interpolation functions

        +;;=> :b-spline-interp :akima)

        interpolators-2d-list

        Map of 2d interpolation functions

        Examples

        List of names

        (keys interpolators-2d-list)
         ;;=> (:bicubic :piecewise-bicubic
         ;;=>           :microsphere-2d :bilinear
        -;;=>           :bicubic-smile :cubic-2d)

        kriging-spline

        (kriging-spline xs ys)

        Kriging interpolation.

        +;;=> :bicubic-smile :cubic-2d)

        kriging-spline

        (kriging-spline xs ys)

        Kriging interpolation.

        Source: Smile.

        Examples

        Usage

        (interpolate kriging-spline ...)
         ;;=> 0.6863915017789624

        Kriging spline plot

        -

        linear

        (linear xs ys)

        Create Divided Difference Algorithm for inqterpolation.

        +

        linear

        (linear xs ys)

        Create Divided Difference Algorithm for inqterpolation.

        Source: Apache Commons Math.

        Examples

        Usage

        (interpolate linear ...)
         ;;=> 0.6843915831251183

        Linear (Apache) plot

        -

        linear-smile

        (linear-smile xs ys)

        Linear interpolation from Smile library.

        +

        linear-smile

        (linear-smile xs ys)

        Linear interpolation from Smile library.

        Source: Smile.

        Examples

        Usage

        (interpolate linear-smile ...)
         ;;=> 0.6843915831251183

        Linear (Smile) plot

        -

        loess

        (loess xs ys)(loess bandwidth robustness-iters xs ys)(loess bandwidth robustness-iters accuracy xs ys)

        Local Regression Algorithm

        +

        loess

        (loess xs ys)(loess bandwidth robustness-iters xs ys)(loess bandwidth robustness-iters accuracy xs ys)

        Local Regression Algorithm

        • bandwidth: 0.2-1.0 (optimal: 0.25-0.5, default: 0.4)
        • robustness-iters: 0-4 (optimal: 0, default: 2)
        • @@ -152,7 +153,7 @@

          2d

        Usage (0.2, 1.0)

        (interpolate loess 0.2 1 ...)
         ;;=> 0.6809644344471794

        Loess (0.2, 1.0) plot

        -

        microsphere-2d-projection

        (microsphere-2d-projection elements max-dark-friction dark-threshold background exponent shared-sphere? no-interpolation-tolerance xs ys vs)

        Microsphere projection interpolator - 2d version

        +

        microsphere-2d-projection

        (microsphere-2d-projection elements max-dark-friction dark-threshold background exponent shared-sphere? no-interpolation-tolerance xs ys vs)

        Microsphere projection interpolator - 2d version

        Grid based.

        Source: Apache Commons Math.

        Examples

        Usage

        @@ -161,34 +162,34 @@

        2d

        1.0E-4 0.5 1.5 false 0.1 ...) -;;=> 0.12273607821725575

        Microsphere 2d plot

        -

        microsphere-projection

        (microsphere-projection elements max-dark-friction dark-threshold background exponent shared-sphere? no-interpolation-tolerance xs ys)

        Microsphere projection interpolator - 1d version

        +;;=> 0.02860557409286495

        Microsphere 2d plot

        +

        microsphere-projection

        (microsphere-projection elements max-dark-friction dark-threshold background exponent shared-sphere? no-interpolation-tolerance xs ys)

        Microsphere projection interpolator - 1d version

        Source: Apache Commons Math.

        Examples

        Usage

        (interpolate microsphere-projection 6 0.1 0.1 0.1 1.5 false 0.01 ...)
        -;;=> 0.5898304448413348

        Microsphere plot

        -

        monotone

        (monotone xs ys)

        Monotone interpolation

        +;;=> 0.6885033102791858

        Microsphere plot

        +

        monotone

        (monotone xs ys)

        Examples

        Usage

        (interpolate monotone ...)
         ;;=> 0.7094972531399422

        Monotone plot

        -

        neville

        (neville xs ys)

        Neville algorithm

        +

        neville

        (neville xs ys)

        Neville algorithm

        Source: Apache Commons Math.

        Examples

        Usage

        (interpolate neville ...)
         ;;=> 0.6789478287835672

        Neville plot

        -

        piecewise-bicubic

        (piecewise-bicubic xs ys vs)

        Piecewise bicubic 2d.

        +

        piecewise-bicubic

        (piecewise-bicubic xs ys vs)

        Piecewise bicubic 2d.

        Grid based.

        Source: Apache Commons Math.

        Examples

        Usage

        (interpolate2d piecewise-bicubic ...)
         ;;=> 0.06876424996210916

        Piecewise bicubic plot

        -

        polynomial

        (polynomial xs ys)

        Polynomial interpolation.

        +

        polynomial

        (polynomial xs ys)

        Polynomial interpolation.

        more

        Examples

        Usage

        (interpolate polynomial ...)
         ;;=> 0.6789478287861641

        Polynomial plot

        -

        rbf

        (rbf xs ys)(rbf rbf-fn normalize? xs ys)(rbf rbf-fn xs ys)

        RBF (Radial Basis Function) interpolation.

        +

        rbf

        (rbf xs ys)(rbf rbf-fn normalize? xs ys)(rbf rbf-fn xs ys)

        RBF (Radial Basis Function) interpolation.

        Default kernel: :gaussian

        Source: Smile

        Examples

        Usage

        @@ -206,7 +207,7 @@

        2d

        Usage (wendland-53 kernel)

        (interpolate rbf (k/rbf :wendland-53) ...)
         ;;=> 0.74837576670325

        Rbf (wendland-53 kernel) plot

        -

        shepard

        (shepard xs ys)(shepard p xs ys)

        Shepard interpolation.

        +

        shepard

        (shepard xs ys)(shepard p xs ys)

        Shepard interpolation.

        Source: Smile.

        Examples

        Usage

        (interpolate shepard ...)
        @@ -214,21 +215,21 @@ 

        2d

        Usage (0.9)

        (interpolate shepard 0.9 ...)
         ;;=> 0.5225345022349268

        Shepard (0.9) plot

        -

        spline

        (spline xs ys)

        Cubic spline interpolation

        +

        spline

        (spline xs ys)

        Cubic spline interpolation

        Source: Apache Commons Math.

        Examples

        Usage

        (interpolate spline ...)
         ;;=> 0.6809644344471794

        Spline plot

        -

        step

        (step xs ys)

        Step function.

        +

        step

        (step xs ys)

        Step function.

        Examples

        Usage

        (interpolate step ...)
         ;;=> 0.8165378262982225

        Step plot

        -

        step-after

        (step-after xs ys)

        Step function.

        +

        step-after

        (step-after xs ys)

        Step function.

        Examples

        Usage

        (interpolate step-after ...)
         ;;=> 0.8165378262982225

        Step (after) plot

        -

        step-before

        (step-before xs ys)

        Step function.

        +

        step-before

        (step-before xs ys)

        Step function.

        Examples

        Usage

        (interpolate step-before ...)
         ;;=> 0.5357270595553765

        Step (before) plot

        -
        \ No newline at end of file +
        \ No newline at end of file diff --git a/docs/fastmath.kernel.html b/docs/fastmath.kernel.html index b5a6586e..db4da88a 100644 --- a/docs/fastmath.kernel.html +++ b/docs/fastmath.kernel.html @@ -1,6 +1,6 @@ -fastmath.kernel documentation

        fastmath.kernel

        Various kernel functions.

        +fastmath.kernel documentation

        fastmath.kernel

        Various kernel functions.

        • RBF (double -> double functions)
        • vector kernels (vector x vector -> double function; may be positive definite, conditional positive definite, positive semi-definite, mercer)
        • @@ -13,25 +13,25 @@ ;;=> 0.02 (let [ak (approx (kernel :gaussian) 6)] (ak [1 2] [3 4])) ;;=> 0.018316

        Plot of :gaussian kernel pproximated to one decimal place.

        -

        cauchy-density-kernel

        (cauchy-density-kernel x)

        cosine-density-kernel

        (cosine-density-kernel x)

        cpd->pd

        (cpd->pd k)

        Convert conditionally positive definite kernel into positive definite.

        +

        cauchy-density-kernel

        (cauchy-density-kernel x)

        cosine-density-kernel

        (cosine-density-kernel x)

        cpd->pd

        (cpd->pd k)

        Convert conditionally positive definite kernel into positive definite.

        Formula is based on this SO answer. x0 is equal 0.

        Doesn’t work well.

        Examples

        Usage

        (let [k (kernel :circular) pd (cpd->pd k)] (pd [0.0 -0.1] [0.2 0.4]))
         ;;=> 0.013011305

        Plot of :periodic kernel converted with cpd->pd function.

        -

        epanechnikov-density-kernel

        (epanechnikov-density-kernel x)

        exp

        (exp k)(exp k t)

        Kernel wraper. exp of kernel k with optional scaling value t.

        +

        epanechnikov-density-kernel

        (epanechnikov-density-kernel x)

        exp

        (exp k)(exp k t)

        Kernel wraper. exp of kernel k with optional scaling value t.

        Examples

        Usage

        (let [k (exp (kernel :laplacian))] (k [1 2] [3 4]))
         ;;=> 1.060887420006057

        Exp with scale=0.5

        (let [k (exp (kernel :laplacian) 0.5)] (k [1 2] [3 4]))
         ;;=> 1.0299938931887205

        Plot of exp of :dirichlet kernel with scaling=5.0

        -

        fields

        (fields k f)(fields k f1 f2)

        Kernel wrapper. Apply vector field for each input before applying kernel function.

        +

        fields

        (fields k f)(fields k f1 f2)

        Kernel wrapper. Apply vector field for each input before applying kernel function.

        Examples

        Usage

        (let [k (kernel :laplacian)
               fld (fields/field :horseshoe)
               kf (fields k fld)]
           (kf (v/vec2 2 3) (v/vec2 1 2)))
        -;;=> 0.21437946979352915

        gaussian-density-kernel

        (gaussian-density-kernel x)

        kernel

        multimethod

        Crated vector kernel.

        +;;=> 0.21437946979352915

        gaussian-density-kernel

        (gaussian-density-kernel x)

        kernel

        multimethod

        Crated vector kernel.

        Kernels can be Mercer, positive definite, conditional positive definite, positive semi-definite or other.

        Optional parameters:

        For :gaussian, :exponential, :laplacian, :rational-quadratic, :multiquadratic, :inverse-multiquadratic, :circular, :spherical, :wave, :power, :log, :cauchy, :generalized-t-student, :hyperbolic-secant, :thin-plate, :mattern-12, :mattern-32, :mattern-52 and ::hyperbolic-secant you can provide scaling parameter and distance (see fastmath.distance, default is euclidean).

        @@ -95,10 +95,10 @@

        Plot of thin-plate

        Plot of variance-function

        Plot of wave

        -

        kernel->rbf

        (kernel->rbf k)(kernel->rbf k center)

        Convert vector kernel to RBF kernel. center is fixed y vector (default contains EPSILON values).

        +

        kernel->rbf

        (kernel->rbf k)(kernel->rbf k center)

        Convert vector kernel to RBF kernel. center is fixed y vector (default contains EPSILON values).

        Examples

        Usage

        (let [k (kernel :mattern-52) r (kernel->rbf k)] (r 0.234))
        -;;=> 0.9567485662415672

        kernel-density

        multimethod

        Create kernel density estimator.

        +;;=> 0.9567485662415672

        kernel-density

        multimethod

        Create kernel density estimator.

        Parameters:

        Examples

        Usage

        (let [k (kernel-density :epanechnikov (repeatedly 1000 rand))] (k 0.5))
        -;;=> 0.9183374186479187
        +;;=> 1.117963173775483
         (let [k (kernel-density :gaussian (repeatedly 1000 rand) 2)] (k 0.5))
        -;;=> 0.19727139631330753

        Plot of cauchy

        +;;=> 0.1974205108544589

        Plot of cauchy

        Plot of cosine

        Plot of default

        Plot of epanechnikov

        @@ -125,7 +125,7 @@

        Plot of triweight

        Plot of uniform

        Plot of wigner

        -

        kernel-density-ci

        (kernel-density-ci method data)(kernel-density-ci method data bandwidth)(kernel-density-ci method data bandwidth alpha)

        Create function which returns confidence intervals for given kde method.

        +

        kernel-density-ci

        (kernel-density-ci method data)(kernel-density-ci method data bandwidth)(kernel-density-ci method data bandwidth alpha)

        Create function which returns confidence intervals for given kde method.

        Check 6.1.5 http://sfb649.wiwi.hu-berlin.de/fedc_homepage/xplore/tutorials/xlghtmlnode33.html

        Parameters:

          @@ -138,10 +138,10 @@

        Examples

        Usage

        (let [k (kernel-density-ci :epanechnikov (repeatedly 1000 rand))]
           (k 0.5))
        -;;=> [0.9688370602070584 0.7995779565431819 1.138096163870935]
        +;;=> [1.0980476125749297 0.9158708086785848 1.2802244164712744]
         (let [k (kernel-density-ci :gaussian (repeatedly 1000 rand) 2)] (k 0.5))
        -;;=> [0.19739560420073257 0.18705372725971706 0.2077374811417481]

        Kernel density with confidence intervals

        -

        kernel-density-list

        Examples

        List of density kernels

        +;;=> [0.19738297405101762 0.18704142797234344 0.2077245201296918]

        Kernel density with confidence intervals

        +

        kernel-density-list

        Examples

        List of density kernels

        kernel-density-list
         ;;=> (:cauchy :cosine
         ;;=>          :default :epanechnikov
        @@ -150,7 +150,7 @@
         ;;=>          :sigmoid :silverman
         ;;=>          :smile :triangular
         ;;=>          :tricube :triweight
        -;;=>          :uniform :wigner)

        kernels-list

        Examples

        List of vector kernels

        +;;=> :uniform :wigner)

        kernels-list

        Examples

        List of vector kernels

        kernels-list
         ;;=> (:anova
         ;;=>  :bessel
        @@ -169,14 +169,14 @@
         ;;=>  :power :rational-quadratic
         ;;=>  :scalar-functions :spherical
         ;;=>  :spline :thin-plate
        -;;=>  :variance-function :wave)

        laplace-density-kernel

        (laplace-density-kernel x)

        logistic-density-kernel

        (logistic-density-kernel x)

        mult

        (mult k1)(mult k1 k2)(mult k1 k2 k3)(mult k1 k2 k3 & r)

        Kernel wrapper. Multiply two or more kernels.

        +;;=> :variance-function :wave)

        laplace-density-kernel

        (laplace-density-kernel x)

        logistic-density-kernel

        (logistic-density-kernel x)

        mult

        (mult k1)(mult k1 k2)(mult k1 k2 k3)(mult k1 k2 k3 & r)

        Kernel wrapper. Multiply two or more kernels.

        Examples

        Usage

        (let [k1 (kernel :laplacian)
               k2 (kernel :periodic)
               res (mult k1 k2)]
           (res [1 2 3 4] [-1 2 3 5]))
         ;;=> 0.042910348739392076

        Product of two kernels

        -

        quartic-density-kernel

        (quartic-density-kernel x)

        rbf

        multimethod

        RBF kernel creator. RBF is double->double function.

        +

        quartic-density-kernel

        (quartic-density-kernel x)

        rbf

        multimethod

        RBF kernel creator. RBF is double->double function.

        Parameters:

        All kernels accept scale parameter (as last parameter).

        Following kernels also accept beta: :multiquadratic, :inverse-multiquadratic, :truncated-power, :radial-powers and :thin-plate.

        @@ -228,10 +228,10 @@

        Plot of wu-31

        Plot of wu-32

        Plot of wu-33

        -

        rbf->kernel

        (rbf->kernel rbf-kernel)(rbf->kernel rbf-kernel distance)

        Treat RBF kernel as vector kernel using distance function (default euclidean.

        +

        rbf->kernel

        (rbf->kernel rbf-kernel)(rbf->kernel rbf-kernel distance)

        Treat RBF kernel as vector kernel using distance function (default euclidean.

        Examples

        Usage

        (let [r (rbf :mattern-c4) k (rbf->kernel r)] (k [1 2 3 4] [-1 2 3 5]))
        -;;=> 1.5719823264954609

        rbf-list

        Examples

        List of RBF kernels

        +;;=> 1.5719823264954609

        rbf-list

        Examples

        List of RBF kernels

        rbf-list
         ;;=> (:gaussian
         ;;=>  :gaussians-laguerre-11 :gaussians-laguerre-12
        @@ -253,21 +253,21 @@
         ;;=>  :wu-11 :wu-20
         ;;=>  :wu-21 :wu-22
         ;;=>  :wu-30 :wu-31
        -;;=>  :wu-32 :wu-33)

        scale

        (scale k scale)

        Kernel wrapper. Scale kernel result.

        +;;=> :wu-32 :wu-33)

        scale

        (scale k scale)

        Kernel wrapper. Scale kernel result.

        Examples

        Usage

        (let [k (kernel :laplacian)
               sk (scale k 2.0)]
           {:kernel (k [1 2 3 4] [-1 2 3 5]),
            :scaled-kernel (sk [1 2 3 4] [-1 2 3 5])})
        -;;=> {:kernel 0.10687792566038574, :scaled-kernel 0.2137558513207715}

        sigmoid-density-kernel

        (sigmoid-density-kernel x)

        silverman-density-kernel

        (silverman-density-kernel x)

        smile-mercer

        (smile-mercer k)

        Create Smile Mercer Kernel object

        +;;=> {:kernel 0.10687792566038574, :scaled-kernel 0.2137558513207715}

        sigmoid-density-kernel

        (sigmoid-density-kernel x)

        silverman-density-kernel

        (silverman-density-kernel x)

        smile-mercer

        (smile-mercer k)

        Create Smile Mercer Kernel object

        Used to pass to Smile constructors/functions.

        Examples

        Usage

        (smile-mercer (kernel :mattern-52))
        -;;=> fastmath.kernel$smile_mercer$reify__19944@6aba6d59

        smile-rbf

        (smile-rbf rbf-fn)

        Create RBF Smile object.

        +;;=> fastmath.kernel$smile_mercer$reify__19969@1c4f7000

        smile-rbf

        (smile-rbf rbf-fn)

        Create RBF Smile object.

        Used to pass to Smile constructors/functions.

        Examples

        Usage

        (smile-rbf (rbf :mattern-c2))
        -;;=> fastmath.kernel$smile_rbf$reify__19682@2550b98a

        triangular-density-kernel

        (triangular-density-kernel x)

        tricube-density-kernel

        (tricube-density-kernel x)

        triweight-density-kernel

        (triweight-density-kernel x)

        uniform-density-kernel

        (uniform-density-kernel x)

        wadd

        (wadd kernels)(wadd weights kernels)

        Kernel wrapper. Add kernels (weighted).

        +;;=> fastmath.kernel$smile_rbf$reify__19707@49cfb519

        triangular-density-kernel

        (triangular-density-kernel x)

        tricube-density-kernel

        (tricube-density-kernel x)

        triweight-density-kernel

        (triweight-density-kernel x)

        uniform-density-kernel

        (uniform-density-kernel x)

        wadd

        (wadd kernels)(wadd weights kernels)

        Kernel wrapper. Add kernels (weighted).

        Examples

        Usage

        (let [k1 (kernel :laplacian)
               k2 (kernel :periodic)
        @@ -279,4 +279,4 @@
               res (wadd [0.2 0.8] [k1 k2])]
           (res [1 2 3 4] [-1 2 3 5]))
         ;;=> 0.3425670639094149

        Weighted sum of two kernels

        -

        wigner-density-kernel

        (wigner-density-kernel x)
        \ No newline at end of file +

        wigner-density-kernel

        (wigner-density-kernel x)
        \ No newline at end of file diff --git a/docs/fastmath.matrix.html b/docs/fastmath.matrix.html index 26abe9a4..29085bac 100644 --- a/docs/fastmath.matrix.html +++ b/docs/fastmath.matrix.html @@ -1,119 +1,126 @@ -fastmath.matrix documentation

        fastmath.matrix

        acos

        (acos vector)

        Apply acos to matrix elements.

        -

        acosh

        (acosh vector)

        Apply acosh to matrix elements.

        -

        acot

        (acot vector)

        Apply acot to matrix elements.

        -

        acoth

        (acoth vector)

        Apply acoth to matrix elements.

        -

        acsc

        (acsc vector)

        Apply acsc to matrix elements.

        -

        add

        (add A)(add A B)

        Add matrices, C=A+B.

        -

        adds

        (adds A s)

        Add scalar to all matrix elements

        -

        asec

        (asec vector)

        Apply asec to matrix elements.

        -

        asech

        (asech vector)

        Apply asech to matrix elements.

        -

        asin

        (asin vector)

        Apply asin to matrix elements.

        -

        asinh

        (asinh vector)

        Apply asinh to matrix elements.

        -

        atan

        (atan vector)

        Apply atan to matrix elements.

        -

        atanh

        (atanh vector)

        Apply atanh to matrix elements.

        -

        cbrt

        (cbrt vector)

        Apply cbrt to matrix elements.

        -

        ceil

        (ceil vector)

        Apply ceil to matrix elements.

        -

        col

        (col A c)

        Return column as a vector

        -

        cols

        (cols A)

        Return matrix columns

        -

        cols->mat2x2

        (cols->mat2x2 [a00 a10] [a01 a11])

        Create 2x2 matrix from 2d vectors (columns).

        -

        cols->mat3x3

        (cols->mat3x3 [a00 a10 a20] [a01 a11 a21] [a02 a12 a22])

        Create 3x3 matrix from 3d vectors (columns).

        -

        cols->mat4x4

        (cols->mat4x4 [a00 a10 a20 a30] [a01 a11 a21 a31] [a02 a12 a22 a32] [a03 a13 a23 a33])

        Create 4x4 matrix from 4d vectors (columns).

        -

        cos

        (cos vector)

        Apply cos to matrix elements.

        -

        cosh

        (cosh vector)

        Apply cosh to matrix elements.

        -

        cot

        (cot vector)

        Apply cot to matrix elements.

        -

        coth

        (coth vector)

        Apply coth to matrix elements.

        -

        csc

        (csc vector)

        Apply csc to matrix elements.

        -

        csch

        (csch vector)

        Apply csch to matrix elements.

        -

        degrees

        (degrees vector)

        Apply degrees to matrix elements.

        -

        det

        (det A)

        Return determinant of the matrix.

        -

        diag

        (diag A)

        Return diagonal of the matrix as a vector.

        -

        diagonal

        (diagonal diag)

        Create diagonal matrix

        -

        emulm

        (emulm A B)

        Multiply two matrices element-wise, Hadamard product, C=AoB

        -

        exp

        (exp vector)

        Apply exp to matrix elements.

        -

        expm1

        (expm1 vector)

        Apply expm1 to matrix elements.

        -

        floor

        (floor vector)

        Apply floor to matrix elements.

        -

        fmap

        (fmap A f)

        Apply a function f to each matrix element.

        -

        frac

        (frac vector)

        Apply frac to matrix elements.

        -

        inverse

        (inverse m)

        Matrix inversion.

        +fastmath.matrix documentation

        fastmath.matrix

        acos

        (acos vector)

        Apply acos to matrix elements.

        +

        acosh

        (acosh vector)

        Apply acosh to matrix elements.

        +

        acot

        (acot vector)

        Apply acot to matrix elements.

        +

        acoth

        (acoth vector)

        Apply acoth to matrix elements.

        +

        acsc

        (acsc vector)

        Apply acsc to matrix elements.

        +

        acsch

        (acsch vector)

        Apply acsch to matrix elements.

        +

        add

        (add A)(add A B)

        Add matrices, C=A+B.

        +

        adds

        (adds A s)

        Add scalar to all matrix elements

        +

        asec

        (asec vector)

        Apply asec to matrix elements.

        +

        asech

        (asech vector)

        Apply asech to matrix elements.

        +

        asin

        (asin vector)

        Apply asin to matrix elements.

        +

        asinh

        (asinh vector)

        Apply asinh to matrix elements.

        +

        atan

        (atan vector)

        Apply atan to matrix elements.

        +

        atanh

        (atanh vector)

        Apply atanh to matrix elements.

        +

        cb

        (cb vector)

        Apply cb to matrix elements.

        +

        cbrt

        (cbrt vector)

        Apply cbrt to matrix elements.

        +

        ceil

        (ceil vector)

        Apply ceil to matrix elements.

        +

        cholesky

        (cholesky A)(cholesky A upper?)

        Calculate L (lower by default) triangular for where L * L^T = A.

        +

        Checks only for symmetry, can return NaNs when A is not positive-definite.

        +

        col

        (col A c)

        Return column as a vector

        +

        cols

        (cols A)

        Return matrix columns

        +

        cols->mat2x2

        (cols->mat2x2 [a00 a10] [a01 a11])

        Create 2x2 matrix from 2d vectors (columns).

        +

        cols->mat3x3

        (cols->mat3x3 [a00 a10 a20] [a01 a11 a21] [a02 a12 a22])

        Create 3x3 matrix from 3d vectors (columns).

        +

        cols->mat4x4

        (cols->mat4x4 [a00 a10 a20 a30] [a01 a11 a21 a31] [a02 a12 a22 a32] [a03 a13 a23 a33])

        Create 4x4 matrix from 4d vectors (columns).

        +

        cos

        (cos vector)

        Apply cos to matrix elements.

        +

        cosh

        (cosh vector)

        Apply cosh to matrix elements.

        +

        cot

        (cot vector)

        Apply cot to matrix elements.

        +

        coth

        (coth vector)

        Apply coth to matrix elements.

        +

        csc

        (csc vector)

        Apply csc to matrix elements.

        +

        csch

        (csch vector)

        Apply csch to matrix elements.

        +

        degrees

        (degrees vector)

        Apply degrees to matrix elements.

        +

        det

        (det A)

        Return determinant of the matrix.

        +

        diag

        (diag A)

        Return diagonal of the matrix as a vector.

        +

        diagonal

        (diagonal diag)

        Create diagonal matrix

        +

        emulm

        (emulm A B)

        Multiply two matrices element-wise, Hadamard product, C=AoB

        +

        exp

        (exp vector)

        Apply exp to matrix elements.

        +

        expm1

        (expm1 vector)

        Apply expm1 to matrix elements.

        +

        floor

        (floor vector)

        Apply floor to matrix elements.

        +

        fmap

        (fmap A f)

        Apply a function f to each matrix element.

        +

        frac

        (frac vector)

        Apply frac to matrix elements.

        +

        inverse

        (inverse m)

        Matrix inversion.

        Returns nil if inversion doesn’t exist.

        -

        jinc

        (jinc vector)

        Apply jinc to matrix elements.

        -

        ln

        (ln vector)

        Apply ln to matrix elements.

        -

        log

        (log vector)

        Apply log to matrix elements.

        -

        log10

        (log10 vector)

        Apply log10 to matrix elements.

        -

        log1mexp

        (log1mexp vector)

        Apply log1mexp to matrix elements.

        -

        log1p

        (log1p vector)

        Apply log1p to matrix elements.

        -

        log1pexp

        (log1pexp vector)

        Apply log1pexp to matrix elements.

        -

        log1pmx

        (log1pmx vector)

        Apply log1pmx to matrix elements.

        -

        log1psq

        (log1psq vector)

        Apply log1psq to matrix elements.

        -

        log2

        (log2 vector)

        Apply log2 to matrix elements.

        -

        logexpm1

        (logexpm1 vector)

        Apply logexpm1 to matrix elements.

        -

        logit

        (logit vector)

        Apply logit to matrix elements.

        -

        logmxp1

        (logmxp1 vector)

        Apply logmxp1 to matrix elements.

        -

        mat->array2d

        (mat->array2d A)

        Return doubles of doubles

        -

        mat->RealMatrix

        (mat->RealMatrix A)

        Return Apache Commons Math Array2DRowMatrix

        -

        mat2x2

        (mat2x2 v)(mat2x2 d1 d2)(mat2x2 a00 a01 a10 a11)

        Create 2x2 matrix.

        +

        jinc

        (jinc vector)

        Apply jinc to matrix elements.

        +

        ln

        (ln vector)

        Apply ln to matrix elements.

        +

        log

        (log vector)

        Apply log to matrix elements.

        +

        log10

        (log10 vector)

        Apply log10 to matrix elements.

        +

        log1mexp

        (log1mexp vector)

        Apply log1mexp to matrix elements.

        +

        log1p

        (log1p vector)

        Apply log1p to matrix elements.

        +

        log1pexp

        (log1pexp vector)

        Apply log1pexp to matrix elements.

        +

        log1pmx

        (log1pmx vector)

        Apply log1pmx to matrix elements.

        +

        log1psq

        (log1psq vector)

        Apply log1psq to matrix elements.

        +

        log2

        (log2 vector)

        Apply log2 to matrix elements.

        +

        logexpm1

        (logexpm1 vector)

        Apply logexpm1 to matrix elements.

        +

        logit

        (logit vector)

        Apply logit to matrix elements.

        +

        logmxp1

        (logmxp1 vector)

        Apply logmxp1 to matrix elements.

        +

        mat->array

        (mat->array A)

        Return doubles of doubles

        +

        mat->array2d

        (mat->array2d A)

        Return doubles of doubles

        +

        mat->float-array

        (mat->float-array A)

        Return doubles of doubles

        +

        mat->float-array2d

        (mat->float-array2d A)

        Return doubles of doubles

        +

        mat->RealMatrix

        (mat->RealMatrix A)

        Return Apache Commons Math Array2DRowMatrix

        +

        mat2x2

        (mat2x2 v)(mat2x2 d1 d2)(mat2x2 a00 a01 a10 a11)

        Create 2x2 matrix.

        Arity:

        • 1 - fills matrix with given value
        • 2 - creates diagonal matrix
        • 4 - creates row ordered matrix
        -

        mat3x3

        (mat3x3 v)(mat3x3 d1 d2 d3)(mat3x3 a00 a01 a02 a10 a11 a12 a20 a21 a22)

        Create 3x3 matrix.

        +

        mat3x3

        (mat3x3 v)(mat3x3 d1 d2 d3)(mat3x3 a00 a01 a02 a10 a11 a12 a20 a21 a22)

        Create 3x3 matrix.

        Arity:

        • 1 - fills matrix with given value
        • 3 - creates diagonal matrix
        • 9 - creates row ordered matrix
        -

        mat4x4

        (mat4x4 v)(mat4x4 d1 d2 d3 d4)(mat4x4 a00 a01 a02 a03 a10 a11 a12 a13 a20 a21 a22 a23 a30 a31 a32 a33)

        Create 4x4 matrix.

        +

        mat4x4

        (mat4x4 v)(mat4x4 d1 d2 d3 d4)(mat4x4 a00 a01 a02 a03 a10 a11 a12 a13 a20 a21 a22 a23 a30 a31 a32 a33)

        Create 4x4 matrix.

        Arity:

        • 1 - fills matrix with given value
        • 4 - creates diagonal matrix
        • 16 - creates row ordered matrix
        -

        mulm

        (mulm A B)(mulm A transposeA? B transposeB?)

        Multiply two matrices, C=AxB.

        +

        mulm

        (mulm A B)(mulm A transposeA? B transposeB?)

        Multiply two matrices, C=AxB.

        Optionally you can request transposition of matrices.

        -

        mulmt

        (mulmt A B)

        Multiply with transposed matrix, C=AxB^T

        -

        muls

        (muls A s)

        Multply matrix by a scalar, C=sA

        -

        mulv

        (mulv A v)

        Multply matrix by vector, x=Av

        -

        ncol

        (ncol A)

        Return number of rows

        -

        negate

        (negate A)

        Negate all matrix elements, C=-A

        -

        nrow

        (nrow A)

        Return number of rows

        -

        outer

        (outer v1 v2)

        Outer project for two vectors.

        -

        radians

        (radians vector)

        Apply radians to matrix elements.

        -

        rint

        (rint vector)

        Apply rint to matrix elements.

        -

        round

        (round vector)

        Apply round to matrix elements.

        -

        row

        (row A r)

        Return row as a vector

        -

        rows

        (rows A)

        Return matrix rows

        -

        rows->mat2x2

        (rows->mat2x2 [a00 a01] [a10 a11])

        Create 2x2 matrix from 2d vectors (rows).

        -

        rows->mat3x3

        (rows->mat3x3 [a00 a01 a02] [a10 a11 a12] [a20 a21 a22])

        Create 3x3 matrix from 3d vectors (rows).

        -

        rows->mat4x4

        (rows->mat4x4 [a00 a01 a02 a03] [a10 a11 a12 a13] [a20 a21 a22 a23] [a30 a31 a32 a33])

        Create 4x4 matrix from 4d vectors (rows).

        -

        safe-sqrt

        (safe-sqrt vector)

        Apply safe-sqrt to matrix elements.

        -

        sec

        (sec vector)

        Apply sec to matrix elements.

        -

        sech

        (sech vector)

        Apply sech to matrix elements.

        -

        sfrac

        (sfrac vector)

        Apply sfrac to matrix elements.

        -

        sgn

        (sgn vector)

        Apply sgn to matrix elements.

        -

        sigmoid

        (sigmoid vector)

        Apply sigmoid to matrix elements.

        -

        signum

        (signum vector)

        Apply signum to matrix elements.

        -

        sin

        (sin vector)

        Apply sin to matrix elements.

        -

        sinc

        (sinc vector)

        Apply sinc to matrix elements.

        -

        sinh

        (sinh vector)

        Apply sinh to matrix elements.

        -

        solve

        (solve A b)

        Solve linear equation Ax=b

        -

        sq

        (sq vector)

        Apply sq to matrix elements.

        -

        sqrt

        (sqrt vector)

        Apply sqrt to matrix elements.

        -

        sub

        (sub A)(sub A B)

        Subract matrices, C=A-B.

        -

        symmetric?

        (symmetric? A)

        Check if matrix is symmetric

        -

        tan

        (tan vector)

        Apply tan to matrix elements.

        -

        tanh

        (tanh vector)

        Apply tanh to matrix elements.

        -

        tmulm

        (tmulm A B)

        Transpose and multiply, C=A^TxB

        -

        tmulmt

        (tmulmt A B)

        Transpose both and multiply, C=A^TxB^T

        -

        trace

        (trace A)

        Return trace of the matrix (sum of diagonal elements)

        -

        transpose

        (transpose A)

        Transpose matrix, C=A^T

        -

        trunc

        (trunc vector)

        Apply trunc to matrix elements.

        -

        vtmul

        (vtmul A v)

        Multiply transposed vector by matrix, C=v^T A

        -

        xlogx

        (xlogx vector)

        Apply xlogx to matrix elements.

        -
        \ No newline at end of file +

        mulmt

        (mulmt A B)

        Multiply with transposed matrix, C=AxB^T

        +

        muls

        (muls A s)

        Multply matrix by a scalar, C=sA

        +

        mulv

        (mulv A v)

        Multply matrix by vector, x=Av

        +

        ncol

        (ncol A)

        Return number of rows

        +

        negate

        (negate A)

        Negate all matrix elements, C=-A

        +

        nrow

        (nrow A)

        Return number of rows

        +

        outer

        (outer v1 v2)

        Outer project for two vectors.

        +

        radians

        (radians vector)

        Apply radians to matrix elements.

        +

        rint

        (rint vector)

        Apply rint to matrix elements.

        +

        round

        (round vector)

        Apply round to matrix elements.

        +

        row

        (row A r)

        Return row as a vector

        +

        rows

        (rows A)

        Return matrix rows

        +

        rows->mat2x2

        (rows->mat2x2 [a00 a01] [a10 a11])

        Create 2x2 matrix from 2d vectors (rows).

        +

        rows->mat3x3

        (rows->mat3x3 [a00 a01 a02] [a10 a11 a12] [a20 a21 a22])

        Create 3x3 matrix from 3d vectors (rows).

        +

        rows->mat4x4

        (rows->mat4x4 [a00 a01 a02 a03] [a10 a11 a12 a13] [a20 a21 a22 a23] [a30 a31 a32 a33])

        Create 4x4 matrix from 4d vectors (rows).

        +

        safe-sqrt

        (safe-sqrt vector)

        Apply safe-sqrt to matrix elements.

        +

        sec

        (sec vector)

        Apply sec to matrix elements.

        +

        sech

        (sech vector)

        Apply sech to matrix elements.

        +

        sfrac

        (sfrac vector)

        Apply sfrac to matrix elements.

        +

        sgn

        (sgn vector)

        Apply sgn to matrix elements.

        +

        sigmoid

        (sigmoid vector)

        Apply sigmoid to matrix elements.

        +

        signum

        (signum vector)

        Apply signum to matrix elements.

        +

        sin

        (sin vector)

        Apply sin to matrix elements.

        +

        sinc

        (sinc vector)

        Apply sinc to matrix elements.

        +

        sinh

        (sinh vector)

        Apply sinh to matrix elements.

        +

        solve

        (solve A b)

        Solve linear equation Ax=b

        +

        sq

        (sq vector)

        Apply sq to matrix elements.

        +

        sqrt

        (sqrt vector)

        Apply sqrt to matrix elements.

        +

        sub

        (sub A)(sub A B)

        Subract matrices, C=A-B.

        +

        symmetric?

        (symmetric? A)

        Check if matrix is symmetric

        +

        tan

        (tan vector)

        Apply tan to matrix elements.

        +

        tanh

        (tanh vector)

        Apply tanh to matrix elements.

        +

        tmulm

        (tmulm A B)

        Transpose and multiply, C=A^TxB

        +

        tmulmt

        (tmulmt A B)

        Transpose both and multiply, C=A^TxB^T

        +

        trace

        (trace A)

        Return trace of the matrix (sum of diagonal elements)

        +

        transpose

        (transpose A)

        Transpose matrix, C=A^T

        +

        trunc

        (trunc vector)

        Apply trunc to matrix elements.

        +

        vtmul

        (vtmul A v)

        Multiply transposed vector by matrix, C=v^T A

        +

        xlogx

        (xlogx vector)

        Apply xlogx to matrix elements.

        +
        \ No newline at end of file diff --git a/docs/fastmath.optimization.html b/docs/fastmath.optimization.html index 50f737cf..47467c3f 100644 --- a/docs/fastmath.optimization.html +++ b/docs/fastmath.optimization.html @@ -1,6 +1,6 @@ -fastmath.optimization documentation

        fastmath.optimization

        Optimization.

        +fastmath.optimization documentation

        fastmath.optimization

        Optimization.

        Namespace provides various optimization methods.

        • Brent (1d functions)
        • @@ -10,7 +10,9 @@
        • Multidirectional simplex
        • CMAES
        • Gradient
        • +
        • L-BFGS-B
        • Bayesian Optimization (see below)
        • +
        • Linear optimization

        All optimizers require bounds.

        Optimizers

        @@ -53,7 +55,8 @@

        Specific paramet

        Bayesian Optimization

        Bayesian optimizer can be used for optimizing expensive to evaluate black box functions. Refer this article or this article

        -

        bayesian-optimization

        (bayesian-optimization f {:keys [warm-up init-points bounds utility-function-type utility-param kernel kscale jitter noise optimizer optimizer-params normalize?], :or {utility-function-type :ucb, init-points 3, jitter 0.25, noise 1.0E-8, utility-param (if (#{:ei :poi} utility-function-type) 0.001 2.576), warm-up (* (count bounds) 1000), normalize? true, kernel (k/kernel :mattern-52), kscale 1.0}})

        bayesian-optimization

        (bayesian-optimization f {:keys [warm-up init-points bounds utility-function-type utility-param kernel kscale jitter noise optimizer optimizer-params normalize?], :or {utility-function-type :ucb, init-points 3, jitter 0.25, noise 1.0E-8, utility-param (if (#{:ei :poi} utility-function-type) 0.001 2.576), warm-up (* (count bounds) 1000), normalize? true, kernel (k/kernel :mattern-52), kscale 1.0}})

        Bayesian optimizer

        Parameters are:

        • :warm-up - number of brute force iterations to find maximum of utility function
        • @@ -88,44 +91,67 @@

          Bayesian Opt {:bounds bounds, :init-points 5, :utility-function-type :poi}) 10)) ;;=> {:gp -;;=> #object[fastmath.gp.GaussianProcess 0x2c72cb63 "fastmath.gp.GaussianProcess@2c72cb63"], -;;=> :util-best (3.227802177805199 -2.5215316000712362), -;;=> :util-fn #, -;;=> :x (3.227802177805199 -2.5215316000712362), -;;=> :xs ((3.227802177805199 -2.5215316000712362) -;;=> (3.1969880293006945 -2.551635600292198) -;;=> (3.155543590855263 -2.576565723996086) -;;=> (3.1244183338484 -2.5841905038468362) -;;=> (3.1130573810943782 -2.583808025029185) -;;=> (3.0984862396773494 -2.595287075953053) -;;=> (3.0733960553410244 -2.6024720151371135) -;;=> (3.063184009721807 -2.60842917989942) -;;=> (3.0302504001334984 -2.6218246890829806) -;;=> (2.9918072743371567 -2.638563414429271) -;;=> (2.9472770477568027 -2.657641458916429) -;;=> [-2.2719197766030055 -4.11685501735947] -;;=> [-4.50063744330848 2.092209893523737] -;;=> [2.943715371396424 -2.659370952841656] -;;=> [0.23377811830742168 2.9856553624837234] -;;=> [-2.083589336560353 -1.5045868205292168]), -;;=> :y -16.3145229624578, -;;=> :ys (-16.3145229624578 -;;=> -18.427271314071184 -;;=> -20.905706429688372 -;;=> -22.462993118468145 -;;=> -22.932168917049705 -;;=> -23.988952259667855 -;;=> -25.37940412325127 -;;=> -26.073624834174797 -;;=> -28.142801650884138 -;;=> -30.69916455047249 -;;=> -33.77494194500137 -;;=> -158.0365255295933 -;;=> -179.5172422623248 -;;=> -34.035215163034444 -;;=> -67.97024697164709 -;;=> -113.148303721833)}

        Bayesian optimization points

        -

        maximize

        (maximize method f config)

        Maximize given function.

        +;;=> #object[fastmath.gp.GaussianProcess 0x34d2a92e "fastmath.gp.GaussianProcess@34d2a92e"], +;;=> :util-best (3.3141987214345434 -2.592010075663022), +;;=> :util-fn #, +;;=> :x (3.3141987214345434 -2.592010075663022), +;;=> :xs ((3.3141987214345434 -2.592010075663022) +;;=> (3.30992762512701 -2.596653048786531) +;;=> (3.278908684956144 -2.6269924745653417) +;;=> (3.2705125757874742 -2.637386077017003) +;;=> (3.2448338138896844 -2.671730136958611) +;;=> (3.1902248200344023 -2.7260638718526145) +;;=> (3.1587157021032857 -2.7452233603103924) +;;=> (3.0912019152796755 -2.771360671770304) +;;=> (3.0568616392253114 -2.7832848673444093) +;;=> (3.0254794263100253 -2.792257257375391) +;;=> (3.0181484109349483 -2.7937673519330035) +;;=> [-1.5162973865171314 -3.138013006830275] +;;=> [-4.559795626206481 2.080373576819847] +;;=> [3.014181669126163 -2.7942294999844366] +;;=> [0.4771670888630597 2.972154631606192] +;;=> [-1.972425173538717 -1.4158273234310959]), +;;=> :y -15.999529485423349, +;;=> :ys (-15.999529485423349 +;;=> -16.293018875754733 +;;=> -18.38232805807585 +;;=> -19.05939382833454 +;;=> -21.321613964051767 +;;=> -25.708403262220124 +;;=> -27.84863433722665 +;;=> -31.998516848853015 +;;=> -34.17055983454501 +;;=> -36.12689000130423 +;;=> -36.562489296028275 +;;=> -141.92959726860622 +;;=> -193.24651956856653 +;;=> -36.78102142190461 +;;=> -66.18256953291899 +;;=> -121.23291722716954)}

        Bayesian optimization points

        +

        linear-optimization

        (linear-optimization target constraints)(linear-optimization target constraints {:keys [goal epsilon max-ulps cut-off rule non-negative? max-iter stats?], :or {goal :minimize, epsilon 1.0E-6, max-ulps 10, cut-off 1.0E-10, rule :dantzig, non-negative? false, max-iter Integer/MAX_VALUE}})

        Solves a linear problem.

        +

        Target is defined as a vector of coefficients and constant as the last value: [a1 a2 a3 ... c] means f(x1,x2,x3) = a1*x1 + a2*x2 + a3*x3 + ... + c

        +

        Constraints are defined as a sequence of one of the following triplets:

        +
          +
        • [a1 a2 a3 ...] R n - which means a1*x1+a2*x2+a3*x3+... R n
        • +
        • [a1 a2 a3 ... ca] R [b1 b2 b3 ... cb] - which meansa1x1+a2x2+a3x3+…+ca R b1x1+b2x2+b3x3+…+cbwhereRis a relationship and can be one of<=,>=or=as symbol or keyword. Also:leq,:geqand:eq` are valid.
        • +
        +

        Function returns pair of optimal point and function value. If stat? option is set to true, returns also information about number of iterations.

        +

        Possible options:

        +
          +
        • :goal - :minimize (default) or :maximize
        • +
        • :rule - pivot selection rule, :dantzig (default) or :bland
        • +
        • :max-iter - maximum number of iterations, maximum integer by default
        • +
        • :non-negative? - allow non-negative variables only, default: false
        • +
        • :epsilon - convergence value, default: 1.0e-6:
        • +
        • :max-ulps - floating point comparisons, default: 10 ulp
        • +
        • :cut-off - pivot elements smaller than cut-off are treated as zero, default: 1.0e-10
        • +
        +
        (linear-optimization [-1 4 0] [[-3 1] :<= 6
        +                               [-1 -2] :>= -4
        +                               [0 1] :>= -3])
        +;; => [(9.999999999999995 -3.0) -21.999999999999993]
        +
        +

        maximize

        (maximize method f config)

        Maximize given function.

        Parameters: optimization method, function and configuration.

        Examples

        Usage

        (let [bounds [[-5.0 5.0]]
        @@ -137,7 +163,7 @@ 

        Bayesian Opt :bfgs (maximize :bfgs f {:bounds bounds})}) ;;=> {:bfgs [(-0.452310691333493) 7.224689671203529], ;;=> :brent [(-0.4523106823170646) 7.224689671203529], -;;=> :powell [(-0.4522927913307559) 7.224689666542709]}

        maximizer

        (maximizer method f config)

        Create optimizer which maximizer function.

        +;;=> :powell [(-0.4522927913307559) 7.224689666542709]}

        maximizer

        (maximizer method f config)

        Create optimizer which maximizes function.

        Returns function which performs optimization for optionally given initial point.

        Examples

        Usage

        (let [bounds [[-5.0 5.0]]
        @@ -149,10 +175,10 @@ 

        Bayesian Opt :run-1 (optimizer), :run-2 (optimizer [4.5]), :run-3 (optimizer [-4.5])}) -;;=> {:optimizer #, +;;=> {:optimizer #, ;;=> :run-1 [(0.0) 6.0], -;;=> :run-2 [(-3.8369253615253918) 2.4140475047943664], -;;=> :run-3 [(-0.9525047436884773) 6.138618012978813]}

        minimize

        (minimize method f config)

        Minimize given function.

        +;;=> :run-2 [(-0.5881313212519057) 6.978121213364068], +;;=> :run-3 [(-4.5) 2.1239369421519996]}

        minimize

        (minimize method f config)

        Minimize given function.

        Parameters: optimization method, function and configuration.

        Examples

        1d function

        (let [bounds [[-5.0 5.0]]
        @@ -177,7 +203,7 @@ 

        Bayesian Opt ;;=> 1.1846390625694734E-19], ;;=> :gradient [(2.999999970870807 2.00000006031274) 5.809729042963462E-14]}

        With stats

        (minimize :gradient
        -          (fn* [p1__32381#] (m/sin p1__32381#))
        +          (fn* [p1__32473#] (m/sin p1__32473#))
                   {:bounds [[-5 5]], :stats? true})
         ;;=> {:evaluations 22, :iterations 3, :result [(-1.5707963273466874) -1.0]}

        min/max of f using :powell optimizer

        min/max of f using :nelder-mead optimizer

        @@ -191,7 +217,7 @@

        Bayesian Opt

        min/max of f using :cmaes optimizer

        min/max of f using :gradient optimizer

        min/max of f using :bobyqa optimizer

        -

        minimizer

        (minimizer method f config)

        Create optimizer which minimizes function.

        +

        minimizer

        (minimizer method f config)

        Create optimizer which minimizes function.

        Returns function which performs optimization for optionally given initial point.

        Examples

        Usage

        (let [bounds [[-5.0 5.0]]
        @@ -203,10 +229,10 @@ 

        Bayesian Opt :run-1 (optimizer), :run-2 (optimizer [4.5]), :run-3 (optimizer [-4.5])}) -;;=> {:optimizer #, +;;=> {:optimizer #, ;;=> :run-1 [(-3.947569586073323) 2.2959519482739297], ;;=> :run-2 [(2.357114991599655) -0.2350104692683484], -;;=> :run-3 [(-4.570514545168775) 2.074718566761628]}

        scan-and-maximize

        Examples

        Usage

        +;;=> :run-3 [(-4.570514545168775) 2.074718566761628]}

        scan-and-maximize

        Examples

        Usage

        (let [bounds [[-5.0 5.0]]
               f (fn [x]
                   (+ (* 0.2 (m/sin (* 10.0 x)))
        @@ -214,9 +240,9 @@ 

        Bayesian Opt {:powell (scan-and-maximize :powell f {:bounds bounds}), :brent (scan-and-maximize :brent f {:bounds bounds}), :bfgs (scan-and-maximize :bfgs f {:bounds bounds})}) -;;=> {:bfgs [(-0.4523106924984993) 7.224689671203531], -;;=> :brent [(-0.4523106941608976) 7.224689671203531], -;;=> :powell [(-0.45231248621698766) 7.2246896711567805]}

        scan-and-minimize

        Examples

        1d function

        +;;=> {:bfgs [(-0.45231069249866795) 7.224689671203531], +;;=> :brent [(-0.4523106934099928) 7.22468967120353], +;;=> :powell [(-0.45231836815888715) 7.224689670346889]}

        scan-and-minimize

        Examples

        1d function

        (let [bounds [[-5.0 5.0]]
               f (fn [x]
                   (+ (* 0.2 (m/sin (* 10.0 x)))
        @@ -224,17 +250,17 @@ 

        Bayesian Opt {:powell (scan-and-minimize :powell f {:bounds bounds}), :brent (scan-and-minimize :brent f {:bounds bounds}), :bfgs (scan-and-minimize :bfgs f {:bounds bounds})}) -;;=> {:bfgs [(2.3571149047757025) -0.2350104692684255], -;;=> :brent [(2.3571149057838023) -0.2350104692684255], -;;=> :powell [(2.3571125931263115) -0.23501046921408636]}

        2d function

        +;;=> {:bfgs [(2.3571149048049227) -0.23501046926842556], +;;=> :brent [(2.3571149066758332) -0.23501046926842525], +;;=> :powell [(2.357114791634838) -0.23501046926829589]}

        2d function

        (let [bounds [[-5.0 5.0] [-5.0 5.0]]
               f (fn [x y]
                   (+ (m/sq (+ (* x x) y -11.0)) (m/sq (+ x (* y y) -7.0))))]
           {:bobyqa (scan-and-minimize :bobyqa f {:bounds bounds}),
            :gradient (scan-and-minimize :gradient f {:bounds bounds}),
            :bfgs (scan-and-minimize :bfgs f {:bounds bounds})})
        -;;=> {:bfgs [(2.9999999995839555 1.999999999938392) 6.981593795980213E-18],
        +;;=> {:bfgs [(2.999999999796513 1.9999999988947754) 2.679589659167391E-17],
         ;;=>  :bobyqa [(-2.805118086981481 3.131312518269862)
         ;;=>           4.1058320675767663E-20],
        -;;=>  :gradient [(3.5844283403285986 -1.8481265269092102)
        -;;=>             4.412799367501478E-20]}
        \ No newline at end of file +;;=> :gradient [(-3.779310253247502 -3.283185991415039) +;;=> 2.19298749248373E-18]}
        \ No newline at end of file diff --git a/docs/fastmath.optimization.lbfgsb.html b/docs/fastmath.optimization.lbfgsb.html index f2c13bcb..beac8017 100644 --- a/docs/fastmath.optimization.lbfgsb.html +++ b/docs/fastmath.optimization.lbfgsb.html @@ -1,4 +1,4 @@ -fastmath.optimization.lbfgsb documentation

        fastmath.optimization.lbfgsb

        Categories

          Other vars: ->lbfgsb grad-function

          ->lbfgsb

          (->lbfgsb params)

          Create lbfgsb object

          -

          grad-function

          (grad-function f goal)(grad-function f goal tol)
          \ No newline at end of file +fastmath.optimization.lbfgsb documentation

          fastmath.optimization.lbfgsb

          Categories

            Other vars: ->lbfgsb grad-function

            ->lbfgsb

            (->lbfgsb params)

            Create lbfgsb object

            +

            grad-function

            (grad-function f goal)(grad-function f goal tol)
            \ No newline at end of file diff --git a/docs/fastmath.protocols.html b/docs/fastmath.protocols.html index 09ae7921..2c8b71b3 100644 --- a/docs/fastmath.protocols.html +++ b/docs/fastmath.protocols.html @@ -1,17 +1,17 @@ -fastmath.protocols documentation

            fastmath.protocols

            Set of protocols for fastmath.

            +fastmath.protocols documentation

            fastmath.protocols

            DistributionIdProto

            protocol

            DistributionIdProto

            protocol

            Get name and parameter names from distribution

            members

            distribution-id

            (distribution-id d)

            Distribution id as keyword

            distribution-parameters

            (distribution-parameters d)

            List of distribution parameter names

            distribution?

            (distribution? d)

            Returns true if the object is distribution

            -

            DistributionProto

            protocol

            Get information from distributions.

            +

            DistributionProto

            protocol

            Get information from distributions.

            members

            cdf

            (cdf d v)(cdf d v1 v2)

            Cumulative probability.

            continuous?

            (continuous? d)

            Does distribution support continuous range?

            dimensions

            (dimensions d)

            Returns dimensions

            @@ -21,17 +21,17 @@

            probability

            (probability d v)

            Probability (PMF)

            sample

            (sample d)

            Returns random sample.

            source-object

            (source-object d)

            Returns Java object from backend library

            -

            GridProto

            protocol

            Common grid conversion functions.

            +

            GridProto

            protocol

            Common grid conversion functions.

            members

            cell->anchor

            (cell->anchor g cell)(cell->anchor g q r)

            Converts cell coordinates to anchor coordinates.

            cell->mid

            (cell->mid g cell)(cell->mid g q r)

            Converts cell coordinates to cell midpoint

            coords->cell

            (coords->cell g coords)(coords->cell g x y)

            Converts 2d space coordinates to cell coordinates.

            coords->mid

            (coords->mid g coords)(coords->mid g x y)

            Converts 2d space into cell midpoint.

            corners

            (corners g coords)(corners g coords scale)(corners g x y scale)

            Returns list of cell vertices for given 2d space coordinates.

            grid-type

            (grid-type g)

            Returns type of the cell.

            -

            MultivariateDistributionProto

            protocol

            Get information from distributions.

            +

            MultivariateDistributionProto

            protocol

            Get information from distributions.

            members

            covariance

            (covariance d)

            Variance

            means

            (means d)

            Mean

            -

            RNGProto

            protocol

            Defines set of random functions for different RNGs or distributions returning primitive values.

            +

            RNGProto

            protocol

            Defines set of random functions for different RNGs or distributions returning primitive values.

            members

            ->seq

            (->seq rng)(->seq rng n)

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

            brandom

            (brandom rng)(brandom rng p)

            Boolean random.

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

            @@ -52,11 +52,11 @@

            forward-2d

            (forward-2d t xss)

            Forward transform of sequence of sequences.

            reverse-1d

            (reverse-1d t xs)

            Reverse transform of sequence or array.

            reverse-2d

            (reverse-2d t xss)

            Reverse transform of sequence of sequences.

            -

            UnivariateDistributionProto

            protocol

            members

            lower-bound

            (lower-bound d)

            Lower value

            +

            UnivariateDistributionProto

            protocol

            members

            lower-bound

            (lower-bound d)

            Lower value

            mean

            (mean d)

            Mean

            upper-bound

            (upper-bound d)

            Higher value

            variance

            (variance d)

            Variance

            -

            VectorProto

            protocol

            Vector operations

            +

            VectorProto

            protocol

            Vector operations

            members

            abs

            (abs v1)

            Absolute value of vector elements

            add

            (add v1)(add v1 v2)

            Sum of two vectors.

            approx

            (approx v)(approx v d)

            Round to 2 (or d) decimal places

            @@ -85,6 +85,7 @@

            mx

            (mx v1)

            Maximum value of vector elements

            permute

            (permute v idxs)

            Permute vector elements with given indices.

            perpendicular

            (perpendicular v1)(perpendicular v1 v2)

            Perpendicular vector (only 2d).

            +

            prod

            (prod v1)

            Product of elements

            reciprocal

            (reciprocal v)

            Reciprocal of elements.

            rotate

            (rotate v1 angle)(rotate v1 anglex angley anglez)

            Rotate vector

            shift

            (shift v1 v)

            Add v value to every vector element.

            @@ -94,4 +95,4 @@

            to-polar

            (to-polar v1)

            To polar coordinates (2d, 3d only), first element is length, the rest angle.

            to-vec

            (to-vec v)

            Convert to Clojure primitive vector Vec.

            transform

            (transform v1 o vx vy)(transform v1 o vx vy vz)

            Transform vector; map point to coordinate system defined by origin, vx and vy (as bases), d and 3d only.

            -
            \ No newline at end of file + \ No newline at end of file diff --git a/docs/fastmath.protocols.matrix.html b/docs/fastmath.protocols.matrix.html index 9286806a..8af2c76e 100644 --- a/docs/fastmath.protocols.matrix.html +++ b/docs/fastmath.protocols.matrix.html @@ -1,3 +1,3 @@ -fastmath.protocols.matrix documentation

            fastmath.protocols.matrix

            MatrixProto

            protocol

            members

            add

            (add m1 m2)

            adds

            (adds m v)

            cols

            (cols m)

            column

            (column m id)

            det

            (det m)

            diag

            (diag m)

            emulm

            (emulm m1 m2)

            fmap

            (fmap m f)

            inverse

            (inverse m)

            mulm

            (mulm m1 m2)(mulm m1 t1? m2 t2?)

            muls

            (muls m v)

            mulv

            (mulv m v)

            ncol

            (ncol m)

            nrow

            (nrow m)

            row

            (row m id)

            rows

            (rows m)

            sub

            (sub m)(sub m1 m2)

            symmetric?

            (symmetric? m)

            to-acm-mat

            (to-acm-mat m)

            to-array2d

            (to-array2d m)

            trace

            (trace m)

            transpose

            (transpose m)

            vtmul

            (vtmul m v)
            \ No newline at end of file +fastmath.protocols.matrix documentation

            fastmath.protocols.matrix

            MatrixProto

            protocol

            members

            add

            (add m1 m2)

            adds

            (adds m v)

            cholesky

            (cholesky m)

            cols

            (cols m)

            column

            (column m id)

            det

            (det m)

            diag

            (diag m)

            emulm

            (emulm m1 m2)

            fmap

            (fmap m f)

            inverse

            (inverse m)

            mulm

            (mulm m1 m2)(mulm m1 t1? m2 t2?)

            muls

            (muls m v)

            mulv

            (mulv m v)

            ncol

            (ncol m)

            nrow

            (nrow m)

            row

            (row m id)

            rows

            (rows m)

            sub

            (sub m)(sub m1 m2)

            symmetric?

            (symmetric? m)

            to-double-array

            (to-double-array m)

            to-double-array2d

            (to-double-array2d m)

            to-float-array

            (to-float-array m)

            to-float-array2d

            (to-float-array2d m)

            trace

            (trace m)

            transpose

            (transpose m)

            vtmul

            (vtmul m v)
            \ No newline at end of file diff --git a/docs/fastmath.quaternion.html b/docs/fastmath.quaternion.html new file mode 100644 index 00000000..7d9066be --- /dev/null +++ b/docs/fastmath.quaternion.html @@ -0,0 +1,43 @@ + +fastmath.quaternion documentation

            fastmath.quaternion

            acos

            (acos q)

            acosh

            (acosh q)

            acot

            (acot q)

            acoth

            (acoth q)

            acsc

            (acsc q)

            acsch

            (acsch q)

            add

            (add q1 q2)

            Sum of two quaternions

            +

            arg

            (arg quaternion)

            Argument of quaternion, atan2(|vector(q)|, re(q))

            +

            asec

            (asec q)

            asech

            (asech q)

            asin

            (asin q)

            asinh

            (asinh q)

            atan

            (atan q)

            atanh

            (atanh q)

            complex->quaternion

            (complex->quaternion z)

            Create quaternion from complex number

            +

            conjugate

            (conjugate quaternion)

            Returns conjugate of quaternion

            +

            cos

            (cos q)

            cosh

            (cosh q)

            cot

            (cot q)

            coth

            (coth q)

            csc

            (csc q)

            csch

            (csch q)

            delta-eq

            (delta-eq q1 q2)(delta-eq q1 q2 accuracy)

            Compare quaternions with given accuracy (10e-6 by default)

            +

            div

            (div q1 q2)

            Divide two quaternions

            +

            exp

            (exp q)

            from-euler

            (from-euler [roll pitch yaw])(from-euler roll pitch yaw)

            Convert Euler ZYX (body 3-2-1) representation to quaternion

            +

            Input should be 3d vector contating roll (x), pitch (y) and yaw (z) angles, or individual values.

            +
              +
            • roll and yaw should be from [-pi, pi] range
            • +
            • pitch should be from [-pi/2, pi/2] range
            • +
            +

            im-i

            (im-i quaternion)

            Return i imaginary part

            +

            im-j

            (im-j quaternion)

            Return j imaginary part

            +

            im-k

            (im-k quaternion)

            Return k imaginary part

            +

            imaginary?

            (imaginary? quaternion)

            Is q is a pure imaginary number?

            +

            inf?

            (inf? quaternion)

            Is infinitive?

            +

            log

            (log q)

            logb

            (logb quaternion b)

            log with base b

            +

            mult

            (mult q1 q2)

            Multiply two quaternions.

            +

            nan?

            (nan? quaternion)

            Is NaN?

            +

            neg

            (neg quaternion)

            Negation of quaternion.

            +

            norm

            (norm quaternion)

            Norm of the quaternion, length of the vector

            +

            normalize

            (normalize quaternion)

            Normalize quaternion

            +

            pow

            (pow q p)

            Quaternion power

            +

            qsgn

            (qsgn re im-i im-j im-k)(qsgn q)

            sgn of the quaternion.

            +

            Returns 0 for 0+0i+0j+0k or calls m/sgn on real part otherwise.

            +

            quaternion

            (quaternion a b c d)(quaternion scalar [i j k])(quaternion a)

            Create quaternion from individual values or scalar and vector parts, reprezented as Vec4.

            +

            re

            (re quaternion)

            Returns scalar part of quaternion

            +

            real?

            (real? quaternion)

            Is q is a real number?

            +

            reciprocal

            (reciprocal quaternion)

            rotate

            (rotate in rotq)(rotate in angle u)

            Rotate 3d in vector around axis u, the same as fastmath.vector/axis-rotate.

            +

            rotation-quaternion

            (rotation-quaternion angle u)

            Create rotation quaternion around vector u and angle alpha

            +

            scalar

            (scalar quaternion)

            Returns scalar part of quaternion, double

            +

            scale

            (scale quaternion scale)

            Scale the quaternion

            +

            sec

            (sec q)

            sech

            (sech q)

            sin

            (sin q)

            sinh

            (sinh q)

            slerp

            (slerp q1 q2 t)

            Interpolate quaternions

            +

            sq

            (sq quaternion)

            Square of quaternion.

            +

            sqrt

            (sqrt q)

            sub

            (sub q1 q2)

            Difference of two quaternions

            +

            tan

            (tan q)

            tanh

            (tanh q)

            to-euler

            (to-euler q)

            Convert quaternion to Euler ZYX (body 3-2-1). Quaternion will be normalized.

            +

            Output will contain roll (x), pitch (y) and yaw (z) angles.

            +

            vector

            (vector quaternion)

            Returns vector part of quaternion, Vec3 type

            +

            zero?

            (zero? quaternion)

            Is zero?

            +
            \ No newline at end of file diff --git a/docs/fastmath.random.html b/docs/fastmath.random.html index 52fe60d2..6aa5c7ed 100644 --- a/docs/fastmath.random.html +++ b/docs/fastmath.random.html @@ -1,6 +1,6 @@ -fastmath.random documentation

            fastmath.random

            Various random and noise functions.

            +fastmath.random documentation

            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.

            @@ -82,15 +82,15 @@

            Discrete Noise

            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.

            -

            ->seq

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

            ->seq

            (->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.

            Examples

            Sequence of random values from distribution

            (->seq (distribution :gamma) 5)
            -;;=> (9.338595251977102
            -;;=>  0.6447322934022234
            -;;=>  2.9546608203555897
            -;;=>  2.1361644933461856
            -;;=>  2.179096738777491)
            +;;=> (3.0067488022135267
            +;;=>  1.4020291240773082
            +;;=>  13.327457354701531
            +;;=>  1.525168177213365
            +;;=>  1.4430890050414493)
             (->seq (distribution :gamma) 5 :stratified)
             ;;=> (0.538681218505258
             ;;=>  1.815596109861234
            @@ -102,13 +102,13 @@ 

            Distribution

            ;;=> 0.366695439109843 ;;=> 0.566695439109843 ;;=> 0.7666954391098431 -;;=> 0.9666954391098429)

            ball-random

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

            Return random vector from a ball

            -

            billow-noise

            (billow-noise)(billow-noise cfg__20703__auto__)

            Create billow-noise function with optional configuration.

            +;;=> 0.9666954391098429)

            ball-random

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

            Return random vector from a ball

            +

            billow-noise

            (billow-noise)(billow-noise cfg__20732__auto__)

            Create billow-noise function with optional configuration.

            Examples

            Usage

            (let [n (billow-noise {:seed 12345, :interpolation :none})]
               (n 0.5 1.1 -1.3))
             ;;=> 0.16031746031746036

            2d noise

            -

            brand

            Random boolean with default RNG.

            +

            brand

            Random boolean with default RNG.

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

            Examples

            Usage

            (brand)
            @@ -116,35 +116,35 @@ 

            Distribution

            (brand 0.1) ;;=> false

            Count number of true values with probability 0.15

            (count (filter true? (repeatedly 100000 (fn* [] (brand 0.15)))))
            -;;=> 14901

            brandom

            (brandom rng)(brandom rng p)

            Random boolean with provided RNG

            +;;=> 15091

            brandom

            (brandom rng)(brandom rng p)

            Random boolean with provided RNG

            Examples

            boolean

            (rngproto-snippet brandom ...)
            -;;=> true

            ccdf

            (ccdf d v)

            Complementary cumulative probability.

            -

            cdf

            (cdf d v)(cdf d v1 v2)

            Cumulative probability.

            +;;=> false

            ccdf

            (ccdf d v)

            Complementary cumulative probability.

            +

            cdf

            (cdf d v)(cdf d v1 v2)

            Cumulative probability.

            Examples

            Usage

            (cdf (distribution :gamma) 1)
             ;;=> 0.09020401043104985
             (cdf (distribution :gamma) 1 4)
            -;;=> 0.5037901398591113

            continuous?

            (continuous? d)

            Does distribution support continuous domain?

            +;;=> 0.5037901398591113

            continuous?

            (continuous? d)

            Does distribution support continuous domain?

            Examples

            Usage

            (continuous? (distribution :gamma))
             ;;=> true
             (continuous? (distribution :pascal))
             ;;=> false
             
            -;; Test: ok.

            covariance

            (covariance d)

            Distribution covariance matrix (for multivariate distributions)

            +;; Test: ok.

            covariance

            (covariance d)

            Distribution covariance matrix (for multivariate distributions)

            Examples

            Usage

            (covariance (distribution :multi-normal))
             ;;=> ((1.0 0.0) (0.0 1.0))
             (covariance (distribution :dirichlet {:alpha [2 2]}))
             ;;=> [[0.05 -0.05] [-0.05 0.05]]
             
            -;; Test: ok.

            default-normal

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

            +;; Test: ok.

            default-normal

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

            Examples

            Usage

            (sample default-normal)
            -;;=> 1.444215875679369
            +;;=> -0.4221634035506921
             (set-seed! default-normal 1234)
            -;;=> org.apache.commons.math3.distribution.NormalDistribution@7a4204ef
            +;;=> org.apache.commons.math3.distribution.NormalDistribution@1f136b88
             (sample default-normal)
             ;;=> 0.14115907833078006
             (irandom default-normal)
            @@ -152,18 +152,18 @@ 

            Distribution

            (mean default-normal) ;;=> 0.0 (variance default-normal) -;;=> 1.0

            default-rng

            Default RNG - JDK

            +;;=> 1.0

            default-rng

            Default RNG - JDK

            Examples

            Usage

            (set-seed! default-rng 111)
            -;;=> org.apache.commons.math3.random.JDKRandomGenerator@74b6c343
            +;;=> org.apache.commons.math3.random.JDKRandomGenerator@656d49a1
             (irandom default-rng)
             ;;=> -1196652709
             (set-seed! default-rng 999)
            -;;=> org.apache.commons.math3.random.JDKRandomGenerator@74b6c343
            +;;=> org.apache.commons.math3.random.JDKRandomGenerator@656d49a1
             (irandom default-rng)
             ;;=> -1242822577
             (set-seed! default-rng 111)
            -;;=> org.apache.commons.math3.random.JDKRandomGenerator@74b6c343
            +;;=> org.apache.commons.math3.random.JDKRandomGenerator@656d49a1
             (irandom default-rng)
             ;;=> -1196652709

            dimensions

            (dimensions d)

            Distribution dimensionality

            Examples

            Usage

            @@ -172,7 +172,7 @@

            Distribution

            (dimensions (distribution :dirichlet {:alpha (repeat 30 2.0)})) ;;=> 30 -;; Test: ok.

            discrete-noise

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

            Discrete noise. Parameters:

            +;; Test: ok.

            discrete-noise

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

            Discrete noise. Parameters:

            • X (long)
            • Y (long, optional)
            • @@ -187,7 +187,7 @@

              Distribution

              ;;=> 0.4702831345937602 (discrete-noise 123) ;;=> 0.28831296287864117

            Draw noise for 0-180 range.

            -

            distribution

            multimethod

            Create distribution object.

            +

            distribution

            multimethod

            Create distribution object.

            • First parameter is distribution as a :key.
            • Second parameter is a map with configuration.
            • @@ -195,14 +195,14 @@

              Distribution

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

            Examples

            Usage

            (distribution :beta)
            -;;=> org.apache.commons.math3.distribution.BetaDistribution@6692accf
            +;;=> org.apache.commons.math3.distribution.BetaDistribution@1be8135f
             (distribution :beta {:alpha 1.0, :beta 1.0})
            -;;=> org.apache.commons.math3.distribution.BetaDistribution@51ada4ed

            All parameters

            +;;=> org.apache.commons.math3.distribution.BetaDistribution@344f58d6

            All parameters

            (into (sorted-map)
            -      (map (fn* [p1__32715#]
            -             (vector p1__32715#
            +      (map (fn* [p1__32807#]
            +             (vector p1__32807#
                                  (sort (distribution-parameters (distribution
            -                                                     p1__32715#)))))
            +                                                     p1__32807#)))))
                        (keys (methods distribution))))
             ;;=> {:anderson-darling ({:n 1.0}),
             ;;=>  :bb (:bd :mu :sigma),
            @@ -518,14 +518,14 @@ 

            Distribution

            2d multidimensional normal (mean=0,0, covariances=I)

            2d multidimensional normal (mean=0,0, covariances=[1 -1 -1 2])

            2d dirichlet (alpha=2,0.8)

            -

            distribution-id

            (distribution-id d)

            Distribution identifier as keyword.

            +

            distribution-id

            (distribution-id d)

            Distribution identifier as keyword.

            Examples

            Usage

            (distribution-id (distribution :gamma))
             ;;=> :gamma
             (distribution-id default-normal)
             ;;=> :normal
             
            -;; Test: ok.

            distribution-parameters

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

            Distribution highest supported value.

            +;; Test: ok.

            distribution-parameters

            (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.

            Examples

            Usage

            (distribution-parameters (distribution :gamma))
            @@ -535,8 +535,8 @@ 

            Distribution

            (distribution-parameters default-normal) ;;=> [:sd :mu] -;; Test: ok.

            distribution?

            (distribution? distr)

            Checks if distr is a distribution object.

            -

            distributions-list

            List of distributions.

            +;; Test: ok.

            distribution?

            (distribution? distr)

            Checks if distr is a distribution object.

            +

            distributions-list

            List of distributions.

            Examples

            Number and list of distributions

            distributions-list
             ;;=> #{:anderson-darling :bb :bernoulli :beta :binomial
            @@ -556,7 +556,7 @@ 

            Distribution

            ;;=> :uniform-int :uniform-real :watson-g :watson-u :weibull :zabb :zabi ;;=> :zaga :zanbi :zibb :zibi :zinbi :zip :zip2 :zipf} (count distributions-list) -;;=> 83

            drand

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

            Random double number with default RNG.

            +;;=> 83

            drand

            (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).

            Examples

            Usage

            (drand)
            @@ -567,28 +567,30 @@ 

            Distribution

            ;;=> 11.178257652282884

            drandom

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

            Random double number with provided RNG

            Examples

            double

            (rngproto-snippet drandom ...)
            -;;=> 0.8690532195659586

            Double random value from distribution

            +;;=> 0.06701962727042732

            Double random value from distribution

            (drandom (distribution :gamma))
            -;;=> 3.7980437804625375

            fbm-noise

            (fbm-noise)(fbm-noise cfg__20703__auto__)

            Create fbm-noise function with optional configuration.

            +;;=> 6.329354086567372

            fbm-noise

            (fbm-noise)(fbm-noise cfg__20732__auto__)

            Create fbm-noise function with optional configuration.

            Examples

            Usage

            (let [n (fbm-noise {:interpolation :linear, :noise-type :value})]
               (n 0.5 1.1 -1.3))
            -;;=> 0.41496425382627966

            2d noise

            -

            flip

            (flip p)(flip)

            Returns 1 with given probability, 0 otherwise

            +;;=> 0.4168546210033432

            2d noise

            +

            flip

            (flip p)(flip)

            Returns 1 with given probability, 0 otherwise

            Examples

            Usage

            (flip)
             ;;=> 1
             (flip 0.2)
             ;;=> 0
             (repeatedly 10 (fn* [] (flip 0.1)))
            -;;=> (0 1 0 1 0 0 1 0 0 0)

            flipb

            (flipb p)(flipb)

            Returns true with given probability, false otherwise

            +;;=> (0 1 0 1 0 0 1 0 0 0)

            flip-rng

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

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

            +

            flipb

            (flipb p)(flipb)

            Returns true with given probability, false otherwise

            Examples

            Usage

            (flipb)
             ;;=> true
             (flipb 0.2)
             ;;=> false
             (repeatedly 10 (fn* [] (flipb 0.1)))
            -;;=> (false false false false false false false false false false)

            frand

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

            Random double number with default RNG.

            +;;=> (false false false false false false false false false false)

            flipb-rng

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

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

            +

            frand

            (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).

            Examples

            Usage

            (frand)
            @@ -599,9 +601,9 @@ 

            Distribution

            ;;=> 15.521044

            frandom

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

            Random double number with provided RNG

            Examples

            float

            (rngproto-snippet frandom ...)
            -;;=> 0.38781476

            Float random value from distribution (sample cast to float)

            +;;=> 0.5313778

            Float random value from distribution (sample cast to float)

            (frandom (distribution :gamma))
            -;;=> 2.1697888

            grand

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

            Random gaussian double number with default RNG.

            +;;=> 4.370595

            grand

            (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).

            Examples

            Usage

            (grand)
            @@ -612,13 +614,13 @@ 

            Distribution

            ;;=> 8.045099200233572

            grandom

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

            Random gaussian double number with provided RNG

            Examples

            gaussian double

            (rngproto-snippet grandom ...)
            -;;=> 0.08249794434126573

            icdf

            (icdf d v)

            Inverse cumulative probability

            +;;=> -0.6728837945388857

            icdf

            (icdf d v)

            Inverse cumulative probability

            Examples

            Usage

            (icdf (distribution :gamma) 0.5)
            -;;=> 3.3566939800333233

            integrate-pdf

            (integrate-pdf pdf-func mn mx steps)(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 function, returns CDF and iCDF

            +;;=> 3.3566939800333233

            integrate-pdf

            (integrate-pdf pdf-func mn mx steps)(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 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

            -

            irand

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

            Random integer number with default RNG.

            +

            irand

            (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).

            Examples

            Usage

            (irand)
            @@ -629,9 +631,9 @@ 

            Distribution

            ;;=> 16

            irandom

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

            Random integer number with provided RNG

            Examples

            integer

            (rngproto-snippet irandom ...)
            -;;=> -1215083642

            Integer random value from distribution (sample cast to int)

            +;;=> 1455081240

            Integer random value from distribution (sample cast to int)

            (irandom (distribution :gamma))
            -;;=> 6

            jittered-sequence-generator

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

            Create jittered sequence generator.

            +;;=> 4

            jittered-sequence-generator

            (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.

            @@ -639,28 +641,28 @@

            Distribution

            (let [gen1 (jittered-sequence-generator :r2 2 0.5)
                   gen2 (jittered-sequence-generator :r2 2 0.5)]
               [(first gen1) (first gen2)])
            -;;=> [[0.35672590506969504 0.3429804320698949]
            -;;=>  [0.3483662837005658 0.30353072436954287]]

            Jittered (0.5) R2 plot (500 samples)

            +;;=> [[0.27411060522326863 0.37253956285622764] +;;=> [0.29572045931878443 0.3284307457115735]]

            Jittered (0.5) R2 plot (500 samples)

            Jittered (0.5) Halton plot (500 samples)

            Jittered (0.5) Sobol plot (500 samples)

            Jittered (0.5) Sphere plot (500 samples)

            Jittered (0.5) Gaussian plot (500 samples)

            Jittered (0.5) Default plot (500 samples)

            -

            likelihood

            (likelihood d vs)

            Likelihood of samples

            +

            likelihood

            (likelihood d vs)

            Likelihood of samples

            Examples

            Usage

            (likelihood (distribution :gamma) [10 0.5 0.5 1 2])
            -;;=> 4.452548659934162E-6

            log-likelihood

            (log-likelihood d vs)

            Log likelihood of samples

            +;;=> 4.452548659934162E-6

            log-likelihood

            (log-likelihood d vs)

            Log likelihood of samples

            Examples

            Usage

            (log-likelihood (distribution :gamma) [10 0.5 0.5 1 2])
            -;;=> -12.322033893165353

            lower-bound

            (lower-bound d)

            Distribution lowest supported value

            +;;=> -12.322033893165353

            lower-bound

            (lower-bound d)

            Distribution lowest supported value

            Examples

            Usage

            (lower-bound (distribution :gamma))
             ;;=> 0.0
             
            -;; Test: ok.

            lpdf

            (lpdf d v)

            Log density

            +;; Test: ok.

            lpdf

            (lpdf d v)

            Log density

            Examples

            Usage

            (lpdf (distribution :gamma) 1)
            -;;=> -1.8862943611198908

            lrand

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

            Random long number with default RNG.

            +;;=> -1.8862943611198908

            lrand

            (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).

            Examples

            Usage

            (lrand)
            @@ -671,77 +673,77 @@ 

            Distribution

            ;;=> 19

            lrandom

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

            Random long number with provided RNG

            Examples

            long

            (rngproto-snippet lrandom ...)
            -;;=> 8255623744776393858

            Long random value from distribution (sample cast to long)

            +;;=> -3175270031798328528

            Long random value from distribution (sample cast to long)

            (lrandom (distribution :gamma))
            -;;=> 2

            mean

            (mean d)

            Distribution mean

            +;;=> 1

            mean

            (mean d)

            Distribution mean

            Examples

            Usage

            (mean (distribution :gamma))
             ;;=> 4.0
             
            -;; Test: ok.

            means

            (means d)

            Distribution means (for multivariate distributions)

            +;; Test: ok.

            means

            (means d)

            Distribution means (for multivariate distributions)

            Examples

            Usage

            (means (distribution :multi-normal))
             ;;=> [0.0 0.0]
             (means (distribution :dirichlet {:alpha [2 2]}))
             ;;=> (0.5 0.5)
             
            -;; Test: ok.

            noise

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

            Improved Perlin Noise.

            +;; Test: ok.

            noise

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

            Improved Perlin Noise.

            6 octaves, quintic interpolation.

            Examples

            Usage

            (noise 3.3)
            -;;=> 0.4863771428571427
            +;;=> 0.17802717460317485
             (noise 3.3 1.1)
            -;;=> 0.5620622179961904
            +;;=> 0.46523967878095224
             (noise 3.3 0.0 -0.1)
            -;;=> 0.5007101511517461

            2d noise

            -

            noise-generators

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

            +;;=> 0.4567598342501587

            2d noise

            +

            noise-generators

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

            Examples

            List of names (keys)

            (keys noise-generators)
            -;;=> (:fbm :single :billow :ridgemulti)

            noise-interpolations

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

            +;;=> (:fbm :single :billow :ridgemulti)

            noise-interpolations

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

            Examples

            List of names (keys)

            (keys noise-interpolations)
            -;;=> (:none :linear :hermite :quintic)

            noise-types

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

            +;;=> (:none :linear :hermite :quintic)

            noise-types

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

            Examples

            List of names (keys)

            (keys noise-types)
            -;;=> (:value :gradient :simplex)

            observe

            macro

            (observe d vs)

            Log likelihood of samples. Alias for log-likelihood.

            +;;=> (:value :gradient :simplex)

            observe

            macro

            (observe d vs)

            Log likelihood of samples. Alias for log-likelihood.

            Examples

            Usage

            (observe (distribution :gamma) [10 0.5 0.5 1 2])
            -;;=> -12.322033893165353

            observe1

            (observe1 d v)

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

            +;;=> -12.322033893165353

            observe1

            (observe1 d v)

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

            Examples

            Usage

            (observe1 (distribution :gamma) 10)
            -;;=> -4.083709268125845

            pdf

            (pdf d v)

            Density

            +;;=> -4.083709268125845

            pdf

            (pdf d v)

            Density

            Examples

            Usage

            (pdf (distribution :gamma) 1)
             ;;=> 0.15163266492815838
             (pdf (distribution :pascal) 1)
            -;;=> 9.5367431640625E-6

            probability

            (probability d v)

            Probability (PMF)

            +;;=> 9.5367431640625E-6

            probability

            (probability d v)

            Probability (PMF)

            Examples

            Usage

            (probability (distribution :gamma) 1)
             ;;=> 0.15163266492815838
             (probability (distribution :pascal) 1)
            -;;=> 9.5367431640625E-6

            random-noise-cfg

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

            Create random noise configuration.

            +;;=> 9.5367431640625E-6

            random-noise-cfg

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

            Create random noise configuration.

            Optional map with fixed values.

            Examples

            Random configuration

            (random-noise-cfg)
            -;;=> {:gain 0.322139923164584,
            -;;=>  :generator :ridgemulti,
            -;;=>  :interpolation :quintic,
            -;;=>  :lacunarity 1.9176121136112807,
            -;;=>  :noise-type :simplex,
            +;;=> {:gain 0.5066632167432485,
            +;;=>  :generator :billow,
            +;;=>  :interpolation :linear,
            +;;=>  :lacunarity 2.1800521196541762,
            +;;=>  :noise-type :value,
             ;;=>  :normalize? true,
            -;;=>  :octaves 8,
            -;;=>  :seed -475178238,
            -;;=>  :warp-depth 1,
            -;;=>  :warp-scale 0.0}

            random-noise-fn

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

            Create random noise function from all possible options.

            +;;=> :octaves 4, +;;=> :seed -399001627, +;;=> :warp-depth 2, +;;=> :warp-scale 0.4698011222895738}

            random-noise-fn

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

            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.

            Examples

            Create function

            (random-noise-fn)
            -;;=> fastmath.random$billow_noise$fn__20721@30b2f3b5
            +;;=> fastmath.random$billow_noise$fn__20750@319cbb18
             (random-noise-fn (random-noise-cfg))
            -;;=> fastmath.random$fbm_noise$fn__20717@3a7933a0

            One

            +;;=> fastmath.random$single_noise$fn__20742@8882fd3

            One

            Two

            Three

            -

            randval

            macro

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

            Return value with given probability (default 0.5)

            +

            randval

            macro

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

            Return value with given probability (default 0.5)

            Examples

            Usage

            (randval :val-one :val-two)
             ;;=> :val-one
            @@ -749,19 +751,20 @@ 

            Distribution

            ;;=> :high-probability

            Check probability of nil (should return value around 1000).

            (count (filter nil?
                            (repeatedly 1000000 (fn* [] (randval 0.001 nil 101)))))
            -;;=> 952

            ridgedmulti-noise

            (ridgedmulti-noise)(ridgedmulti-noise cfg__20703__auto__)

            Create ridgedmulti-noise function with optional configuration.

            +;;=> 1019

            randval-rng

            macro

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

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

            +

            ridgedmulti-noise

            (ridgedmulti-noise)(ridgedmulti-noise cfg__20732__auto__)

            Create ridgedmulti-noise function with optional configuration.

            Examples

            Usage

            (let [n
                   (ridgedmulti-noise
                    {:octaves 3, :lacunarity 2.1, :gain 0.7, :noise-type :simplex})]
               (n 0.5 1.1 -1.3))
            -;;=> 0.29206521847895894

            2d noise

            -

            rng

            multimethod

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

            +;;=> 0.35030055891668704

            2d noise

            +

            rng

            multimethod

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

            Examples

            Creation

            (rng :mersenne)
            -;;=> org.apache.commons.math3.random.MersenneTwister@98ef834
            +;;=> org.apache.commons.math3.random.MersenneTwister@1d0e669b
             (rng :isaac 1234)
            -;;=> org.apache.commons.math3.random.ISAACRandom@1ac18537

            Usage

            +;;=> org.apache.commons.math3.random.ISAACRandom@7b033a75

            Usage

            (irandom (rng :mersenne 999) 15 25)
             ;;=> 24

            rngs-list

            List of all possible RNGs.

            Examples

            Contains

            @@ -769,10 +772,12 @@

            Distribution

            ;;=> (:isaac :jdk :mersenne ;;=> :well1024a :well19937a ;;=> :well19937c :well44497a -;;=> :well44497b :well512a)

            sample

            (sample d)

            Random sample

            +;;=> :well44497b :well512a)

            roll-a-dice

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

            Roll a dice with given sides

            +

            roll-a-dice-rng

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

            Roll a dice with given sides and given rng

            +

            sample

            (sample d)

            Random sample

            Examples

            Random value from distribution

            (sample (distribution :gamma))
            -;;=> 2.709109155416231

            sequence-generator

            multimethod

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

            +;;=> 1.2169466036243723

            sequence-generator

            multimethod

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

            Values:

            • :r2, :halton, :sobol, :default - range [0-1] for each dimension
            • @@ -812,11 +817,11 @@

              Distribution

            Sphere plot (500 samples)

            Gaussian plot (500 samples)

            Default plot (500 samples)

            -

            sequence-generators-list

            List of random sequence generator. See sequence-generator.

            +

            sequence-generators-list

            List of random sequence generator. See sequence-generator.

            Examples

            Generator names.

            (sort sequence-generators-list)
            -;;=> (:ball :default :gaussian :halton :r2 :sobol :sphere)

            set-seed

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

            Create and return new RNG

            -

            set-seed!

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

            Sets seed.

            +;;=> (:ball :default :gaussian :halton :r2 :sobol :sphere)

            set-seed

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

            Create and return new RNG

            +

            set-seed!

            (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

            Examples

            Set seed for the RNG object

            @@ -835,24 +840,24 @@

            Distribution

            (set-seed! :smile 1234)
             ;;=> nil

            Set seed to both SMILE and fastmath default RNGs

            (set-seed! 1234)
            -;;=> org.apache.commons.math3.random.JDKRandomGenerator@74b6c343

            Set to random seed both default RNGs

            +;;=> org.apache.commons.math3.random.JDKRandomGenerator@656d49a1

            Set to random seed both default RNGs

            (set-seed!)
            -;;=> org.apache.commons.math3.random.JDKRandomGenerator@74b6c343

            simplex

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

            Simplex noise. 6 octaves.

            +;;=> org.apache.commons.math3.random.JDKRandomGenerator@656d49a1

            simplex

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

            Simplex noise. 6 octaves.

            Examples

            Usage

            (simplex 3.3)
            -;;=> 0.37317187056
            +;;=> 0.6525392810438096
             (simplex 3.3 1.1)
            -;;=> 0.33595758451118996
            +;;=> 0.4992060978009244
             (simplex 3.3 0.0 -0.1)
            -;;=> 0.3157868077601413

            2d noise

            -

            single-noise

            (single-noise)(single-noise cfg__20703__auto__)

            Create single-noise function with optional configuration.

            +;;=> 0.5027365575805084

            2d noise

            +

            single-noise

            (single-noise)(single-noise cfg__20732__auto__)

            Create single-noise function with optional configuration.

            Examples

            Usage

            (let [n (single-noise {:interpolation :linear})] (n 0.5 1.1 -1.3))
            -;;=> 0.479

            2d noise

            -

            source-object

            (source-object d)

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

            +;;=> 0.634

            2d noise

            +

            source-object

            (source-object d)

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

            Examples

            Usage

            (source-object default-normal)
            -;;=> org.apache.commons.math3.distribution.NormalDistribution@7a4204ef

            synced-rng

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

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

            +;;=> org.apache.commons.math3.distribution.NormalDistribution@1f136b88

            synced-rng

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

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

            Examples

            Usage

            (drandom (synced-rng :mersenne 1234))
             ;;=> 0.0685985404954157

            upper-bound

            (upper-bound d)

            Distribution highest supported value

            @@ -860,21 +865,21 @@

            Distribution

            (upper-bound (distribution :gamma))
             ;;=> Infinity
             
            -;; Test: ok.

            variance

            (variance d)

            Distribution variance

            +;; Test: ok.

            variance

            (variance d)

            Distribution variance

            Examples

            Usage

            (variance (distribution :gamma))
             ;;=> 8.0
             
            -;; Test: ok.

            vnoise

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

            Value Noise.

            +;; Test: ok.

            vnoise

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

            Value Noise.

            6 octaves, Hermite interpolation (cubic, h01).

            Examples

            Usage

            (vnoise 3.3)
            -;;=> 0.7118823098349076
            +;;=> 0.3206900454559337
             (vnoise 3.3 1.1)
            -;;=> 0.6256694813199928
            +;;=> 0.405033127977853
             (vnoise 3.3 0.0 -0.1)
            -;;=> 0.7645039402625281

            2d noise

            -

            warp-noise-fn

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

            Create warp noise (see Inigo Quilez article).

            +;;=> 0.5235283697595818

            2d noise

            +

            warp-noise-fn

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

            Create warp noise (see Inigo Quilez article).

            Parameters:

            • noise function, default: vnoise
            • @@ -885,5 +890,5 @@

              Distribution

            Examples

            Usage

            (let [n (warp-noise-fn simplex 2.0 2.0)]
               [(n 0.0) (n 1.0 0.5) (n 2 2 2)])
            -;;=> [0.40514091608287256 0.4384328723070078 0.6539788263760881]

            Default warp (noise=vnoise, scale=4.0, depth=1.0).

            -
            \ No newline at end of file +;;=> [0.4465743065877865 0.4444313141229481 0.6482438784376463]

            Default warp (noise=vnoise, scale=4.0, depth=1.0).

            +
            \ No newline at end of file diff --git a/docs/fastmath.signal.html b/docs/fastmath.signal.html index 69c4cb84..1ff22a1b 100644 --- a/docs/fastmath.signal.html +++ b/docs/fastmath.signal.html @@ -1,6 +1,6 @@ -fastmath.signal documentation

            fastmath.signal

            Signal processing (effect) and generation (oscillators).

            +fastmath.signal documentation

            fastmath.signal

            Signal processing (effect) and generation (oscillators).

            Singal is any sequence with double values.

            Signal processing

            To process signal use apply-effects or apply-effects-raw (operates on double-array only) function.

            @@ -172,7 +172,7 @@

            File operations

            (let [lpf (effect :simple-lowpass {:cutoff 10000})
                   sgnal (m/seq->double-array [-1.0 1.0 -0.5 0.5 -0.1 0.1 0 0])]
               (apply-effects-raw sgnal lpf))
            -;;=> [D@748412d5

            Reset state every two samples

            +;;=> [D@67c1ab90

            Reset state every two samples

            (let [lpf (effect :simple-lowpass {:cutoff 10000})
                   sgnal (m/seq->double-array [-1.0 1.0 -0.5 0.5 -0.1 0.1 0 0])]
               (seq (apply-effects-raw sgnal lpf 2)))
            @@ -193,9 +193,9 @@ 

            File operations

            "After call on sample" result, "Extracted sample" (result)}) ;;=> {"After call on sample" -;;=> #object[fastmath.signal.EffectsList 0x70c5de63 "simple-highpass (0.38911967999610275) -> simple-lowpass (0.08629142927556396)"], +;;=> #object[fastmath.signal.EffectsList 0x3a82c52a "simple-highpass (0.38911967999610275) -> simple-lowpass (0.08629142927556396)"], ;;=> "Composed effects" -;;=> #object[fastmath.signal.EffectsList 0x5b65490d "simple-highpass (0.0) -> simple-lowpass (0.0)"], +;;=> #object[fastmath.signal.EffectsList 0x91d6ffa "simple-highpass (0.0) -> simple-lowpass (0.0)"], ;;=> "Extracted sample" 0.08629142927556396}

            db->linear

            (db->linear x)

            DB to Linear

            Examples

            Usage

            (db->linear 0.5)
            @@ -348,7 +348,7 @@ 

            File operations

            Returns sampled signal as double array.

            Examples

            Usage

            (let [w (oscillator :sin 0.2 0.9 0.2)] (oscillator->signal w 44100 5))
            -;;=> [D@7aeb8fc0

            oscillator-gain

            (oscillator-gain fs gain)

            Examples

            Usage

            +;;=> [D@7cbdfa68

            oscillator-gain

            (oscillator-gain fs gain)

            Examples

            Usage

            (let [wave-sin (oscillator :sin 1.0 1.0 0.5)
                   gained (oscillator-gain wave-sin 0.22)]
               {:original (wave-sin 0.75), :gained (gained 0.75)})
            @@ -368,7 +368,7 @@ 

            File operations

            Examples

            Usage

            (let [s (oscillator->signal (oscillator :sin 1 1 0) 11050 5)]
               (save-signal s "signal.raw"))
            -;;=> [D@75c3384c

            savgol-filter

            (savgol-filter)(savgol-filter length)(savgol-filter length order)(savgol-filter length order derivative)

            Creates Savitzky-Golay smoothing filter.

            +;;=> [D@c1fd373

            savgol-filter

            (savgol-filter)(savgol-filter length)(savgol-filter length order)(savgol-filter length order derivative)

            Creates Savitzky-Golay smoothing filter.

            Arguments:

            • length - length of the kernel (default: 5)
            • diff --git a/docs/fastmath.solver.html b/docs/fastmath.solver.html index 8cb164ed..e0f991b0 100644 --- a/docs/fastmath.solver.html +++ b/docs/fastmath.solver.html @@ -1,6 +1,6 @@ -fastmath.solver documentation

              fastmath.solver

              Categories

                Other vars: find-root

                find-root

                (find-root f lower-bound upper-bound)(find-root f lower-bound upper-bound {:keys [absolute-accuracy relative-accuracy max-iters initial-value solver], :or {max-iters 100, solver :brent}})

                Find zero (root) of a function f in given range lower-bound, upper-bound.

                +fastmath.solver documentation

                fastmath.solver

                Categories

                  Other vars: find-root quadratic

                  find-root

                  (find-root f lower-bound upper-bound)(find-root f lower-bound upper-bound {:keys [absolute-accuracy relative-accuracy max-iters initial-value solver], :or {max-iters 100, solver :brent}})

                  Find zero (root) of a function f in given range lower-bound, upper-bound.

                  Optional parameters:

                  • :absolute-accuracy - default 1.0e-8
                  • @@ -9,4 +9,5 @@
                  • :initial-value - algorithm starting value
                  • :solver - one of: :brent (default), :bisection, :illinois, :muller, :muller2, :pegasus, :regula-falsi, :ridders and :secant.
                  -
                  \ No newline at end of file +

                  quadratic

                  (quadratic a b c)

                  Solution of quadratic formula ax^2+bx+c=0, returns nil when there are no solutions

                  +
                  \ No newline at end of file diff --git a/docs/fastmath.stats.bootstrap.html b/docs/fastmath.stats.bootstrap.html index 14aae160..e5b3c7c5 100644 --- a/docs/fastmath.stats.bootstrap.html +++ b/docs/fastmath.stats.bootstrap.html @@ -1,12 +1,12 @@ -fastmath.stats.bootstrap documentation

                  fastmath.stats.bootstrap

                  Bootstrap methods and confidence intervals

                  +fastmath.stats.bootstrap documentation

                  fastmath.stats.bootstrap

                  Bootstrap methods and confidence intervals

                  bootstrap

                  (bootstrap input)(bootstrap input statistic)(bootstrap input statistic {:keys [rng samples size method antithetic? smoothing dimensions include?], :or {samples 500}, :as params})

                  Create set of samples from given data (nonparametric) or model (parametric).

                  Input: * sequence of values (any type) or sequence of sequences for multidimensional data * a map containing: * :data - sequence * :model - model for parametric bootstrap (optional) * statistic function which returns statistic value (optional)

                  Parameters: * :samples - number of bootstrapped samples (default: 500) * :size - forced size of individual sample (default: same as source) * :method * nil (default) - random * :jackknife for leave-one-out jackknife * :jackknife+ for positive jackknife * any method accepted by fastmath.random/->seq * :rng - random number generator (see: fastmath.random/rng) * :smoothing - smoothing bootstrap: * :kde - kernel density estimation, additional options are: :kernel (default) and :bandwidth (auto) * :gaussian - add random value from N(0,standard error) * :distribution - distribution used to auto generate model (distribution) from data: * :real-discrete-distribution - default * :integer-discrete-distribution - for integer values * :categorical-distribution - for any other type * :dimensions - if set to :multi - multidimensional data and models are created * :antithetic? - antithetic sampling (default: false) * :include? - if set to true (default: false) original dataset is included in samples

                  Model can be: * any distribution object * any 0-arity function which returns random sample

                  When model is ommited, function creates discrete distribution. When multidimensional data are provided, models should be created for every dimension (as a sequence).

                  -

                  bootstrap-stats

                  (bootstrap-stats {:keys [data samples], :as input} statistic)

                  Calculate bootstrap analysis.

                  +

                  bootstrap-stats

                  (bootstrap-stats {:keys [data samples], :as input} statistic)

                  Calculate bootstrap analysis.

                  Arguments:

                  • a map containing :data and :samples
                  • @@ -20,19 +20,19 @@
                  • :bias - difference between mean of ts and t0
                  • :mean, :median, :variance, :stddev, :sem - statistics from ts
                  -

                  ci-basic

                  (ci-basic boot-data)(ci-basic boot-data alpha)(ci-basic {:keys [t0 ts]} alpha estimation-strategy)

                  Basic percentile confidence interval

                  +

                  ci-basic

                  (ci-basic boot-data)(ci-basic boot-data alpha)(ci-basic {:keys [t0 ts]} alpha estimation-strategy)

                  Basic percentile confidence interval

                  :t0 and :ts are obligatory

                  -

                  ci-bc

                  (ci-bc boot-data)(ci-bc boot-data alpha)(ci-bc {:keys [t0 ts]} alpha estimation-strategy)

                  Bias-corrected confidence interval

                  -

                  ci-bca

                  (ci-bca boot-data)(ci-bca boot-data alpha)(ci-bca {:keys [t0 ts data statistic]} alpha estimation-strategy)

                  Bias-corrected and accelerated confidence interval.

                  +

                  ci-bc

                  (ci-bc boot-data)(ci-bc boot-data alpha)(ci-bc {:keys [t0 ts]} alpha estimation-strategy)

                  Bias-corrected confidence interval

                  +

                  ci-bca

                  (ci-bca boot-data)(ci-bca boot-data alpha)(ci-bca {:keys [t0 ts data statistic]} alpha estimation-strategy)

                  Bias-corrected and accelerated confidence interval.

                  There are two ways to calculate acceleration: * jackknife method (when boot-data contains :data and :statistic) * empirical from bootstrap estimations ts otherwise

                  -

                  ci-normal

                  (ci-normal boot-data)(ci-normal {:keys [t0 ts stddev bias]} alpha)

                  Normal (gaussian) bias-corrected confidence interval

                  +

                  ci-normal

                  (ci-normal boot-data)(ci-normal {:keys [t0 ts stddev bias]} alpha)

                  Normal (gaussian) bias-corrected confidence interval

                  :t0 and :ts are obligatory

                  -

                  ci-percentile

                  (ci-percentile boot-data)(ci-percentile boot-data alpha)(ci-percentile {:keys [t0 ts]} alpha estimation-strategy)

                  Percentile confidence interval

                  +

                  ci-percentile

                  (ci-percentile boot-data)(ci-percentile boot-data alpha)(ci-percentile {:keys [t0 ts]} alpha estimation-strategy)

                  Percentile confidence interval

                  :t0 and :ts are obligatory

                  -

                  ci-studentized

                  (ci-studentized boot-data)(ci-studentized boot-data alpha)(ci-studentized {:keys [t0 ts data samples]} alpha estimation-strategy)

                  Confidence interval from studentized data.

                  +

                  ci-studentized

                  (ci-studentized boot-data)(ci-studentized boot-data alpha)(ci-studentized {:keys [t0 ts data samples]} alpha estimation-strategy)

                  Confidence interval from studentized data.

                  :t0, :ts, :data and :samples are obligatory in boot-data

                  -

                  ci-t

                  (ci-t boot-data)(ci-t {:keys [t0 ts stddev]} alpha)

                  Student’s T confidence interval.

                  +

                  ci-t

                  (ci-t boot-data)(ci-t {:keys [t0 ts stddev]} alpha)

                  Student’s T confidence interval.

                  :t0 and :ts are obligatory

                  -

                  jackknife

                  (jackknife vs)

                  Generates set of samples using jackknife leave-one-out method

                  -

                  jackknife+

                  (jackknife+ vs)

                  Generates set of samples using jackknife positive method

                  -
                  \ No newline at end of file +

                  jackknife

                  (jackknife vs)

                  Generates set of samples using jackknife leave-one-out method

                  +

                  jackknife+

                  (jackknife+ vs)

                  Generates set of samples using jackknife positive method

                  +
                \ No newline at end of file diff --git a/docs/fastmath.stats.html b/docs/fastmath.stats.html index 9b51b04e..c9d6e6c6 100644 --- a/docs/fastmath.stats.html +++ b/docs/fastmath.stats.html @@ -1,6 +1,6 @@ -fastmath.stats documentation

                fastmath.stats

                Statistics functions.

                +fastmath.stats documentation

                fastmath.stats

                Statistics functions.

                • Descriptive statistics.
                • Correlation / covariance
                • @@ -51,16 +51,16 @@
                  Descriptiv

                Examples

                Usage

                (acf (repeatedly 1000 r/grand) 5)
                 ;;=> (1.0
                -;;=>  0.02481827283370266
                -;;=>  -0.016643111047625267
                -;;=>  -0.04387141411591325
                -;;=>  -0.0175258579033391
                -;;=>  -0.022982146321944872)
                +;;=>  0.024818272833702658
                +;;=>  -0.016643111047625263
                +;;=>  -0.04387141411591324
                +;;=>  -0.017525857903339097
                +;;=>  -0.02298214632194487)
                 (acf (repeatedly 1000 r/grand) [10 20 100 500])
                -;;=> (-0.037660639529149706
                -;;=>  -0.0340344086980366
                -;;=>  -0.010242012560395728
                -;;=>  0.004501378382446301)
                +;;=> (-0.0376606395291497
                +;;=>  -0.034034408698036596
                +;;=>  -0.010242012560395726
                +;;=>  0.0045013783824463)
                 (acf [1 2 3 4 5 4 3 2 1])
                 ;;=> (1.0
                 ;;=>  0.5396825396825397
                @@ -88,8 +88,8 @@ 
                Descriptiv ;;=> :cis (0.653321328180018 ;;=> 0.8218653739461048 ;;=> 0.8219599072345126 -;;=> 0.9281841012727746)}

                ad-test-one-sample

                (ad-test-one-sample xs)(ad-test-one-sample xs distribution-or-ys)(ad-test-one-sample xs distribution-or-ys {:keys [sides kernel bandwidth], :or {sides :one-sided-greater, kernel :gaussian}})

                Anderson-Darling test

                -

                adjacent-values

                (adjacent-values vs)(adjacent-values vs estimation-strategy)(adjacent-values vs q1 q3 m)

                Lower and upper adjacent values (LAV and UAV).

                +;;=> 0.9281841012727746)}

                ad-test-one-sample

                (ad-test-one-sample xs)(ad-test-one-sample xs distribution-or-ys)(ad-test-one-sample xs distribution-or-ys {:keys [sides kernel bandwidth], :or {sides :one-sided-greater, kernel :gaussian}})

                Anderson-Darling test

                +

                adjacent-values

                (adjacent-values vs)(adjacent-values vs estimation-strategy)(adjacent-values vs q1 q3 m)

                Lower and upper adjacent values (LAV and UAV).

                Let Q1 is 25-percentile and Q3 is 75-percentile. IQR is (- Q3 Q1).

                • LAV is smallest value which is greater or equal to the LIF = (- Q1 (* 1.5 IQR)).
                • @@ -178,7 +178,7 @@
                  Descriptiv ;;=> :cn 4.0, ;;=> :cp 4.0, ;;=> :dor 0.3333333333333333, -;;=> :f-beta #, +;;=> :f-beta #, ;;=> :f-measure 0.28571428571428575, ;;=> :f1-score 0.28571428571428575, ;;=> :fall-out 0.5, @@ -218,7 +218,7 @@
                  Descriptiv ;;=> :total 8.0, ;;=> :tp 1, ;;=> :tpr 0.25, -;;=> :ts 0.16666666666666666}

                Treat 1 as true value.

                +;;=> :ts 0.16666666666666666}

                Treat 1 as true value.

                (binary-measures-all [1 0 1 0 1 0 1 0] [1 0 0 1 0 0 0 1] [1])
                 ;;=> {:accuracy 0.375,
                 ;;=>  :ba 0.375,
                @@ -226,7 +226,7 @@ 
                Descriptiv ;;=> :cn 4.0, ;;=> :cp 4.0, ;;=> :dor 0.3333333333333333, -;;=> :f-beta #, +;;=> :f-beta #, ;;=> :f-measure 0.28571428571428575, ;;=> :f1-score 0.28571428571428575, ;;=> :fall-out 0.5, @@ -266,7 +266,7 @@
                Descriptiv ;;=> :total 8.0, ;;=> :tp 1, ;;=> :tpr 0.25, -;;=> :ts 0.16666666666666666}

                Treat :a and :b as true value.

                +;;=> :ts 0.16666666666666666}

                Treat :a and :b as true value.

                (binary-measures-all [:a :b :c :d :e :f :a :b]
                                      [:a :b :a :b :a :f :d :b]
                                      {:a true, :b true, :c false})
                @@ -276,7 +276,7 @@ 
                Descriptiv ;;=> :cn 4.0, ;;=> :cp 4.0, ;;=> :dor 1.0, -;;=> :f-beta #, +;;=> :f-beta #, ;;=> :f-measure 0.6, ;;=> :f1-score 0.6, ;;=> :fall-out 0.75, @@ -316,7 +316,7 @@
                Descriptiv ;;=> :total 8.0, ;;=> :tp 3, ;;=> :tpr 0.75, -;;=> :ts 0.42857142857142855}

                F-beta is a function. When beta is equal 1.0, you get f1-score.

                +;;=> :ts 0.42857142857142855}

                F-beta is a function. When beta is equal 1.0, you get f1-score.

                (let [fbeta (:f-beta (binary-measures-all
                                       [true false true false true false true false]
                                       [true false false true false false false true]))]
                @@ -325,78 +325,78 @@ 
                Descriptiv

                Possible methods are: * :asymptotic (normal aproximation, based on central limit theorem), default * :agresti-coull * :clopper-pearson * :wilson * :prop.test - one sample proportion test * :cloglog * :logit * :probit * :arcsine * :all - apply all methods and return a map of triplets

                Default alpha is 0.05

                Returns a triple lower ci, upper ci, p=successes/trials

                -

                binomial-ci-methods

                binomial-test

                (binomial-test xs)(binomial-test xs maybe-params)(binomial-test number-of-successes number-of-trials {:keys [alpha p ci-method sides], :or {alpha 0.05, p 0.5, ci-method :asymptotic, sides :two-sided}})

                Binomial test

                +

                binomial-ci-methods

                binomial-test

                (binomial-test xs)(binomial-test xs maybe-params)(binomial-test number-of-successes number-of-trials {:keys [alpha p ci-method sides], :or {alpha 0.05, p 0.5, ci-method :asymptotic, sides :two-sided}})

                Binomial test

                • alpha - significance level (default: 0.05)
                • sides - one of: :two-sided (default), :one-sided-less (short: :one-sided) or :one-sided-greater
                • ci-method - see binomial-ci-methods
                • p - tested probability
                -

                bootstrap

                deprecated in Please use fastmath.stats.bootstrap/bootstrap instead

                (bootstrap vs)(bootstrap vs samples)(bootstrap vs samples size)

                Generate set of samples of given size from provided data.

                +

                bootstrap

                deprecated in Please use fastmath.stats.bootstrap/bootstrap instead

                (bootstrap vs)(bootstrap vs samples)(bootstrap vs samples size)

                Generate set of samples of given size from provided data.

                Default samples is 200, number of size defaults to sample size.

                Examples

                Usage

                (bootstrap [1 2 3 4 1 2 3 1 2 1] 2 20)
                 ;;=> ((3.0
                 ;;=>   1.0
                 ;;=>   2.0
                -;;=>   4.0
                 ;;=>   1.0
                +;;=>   2.0
                +;;=>   2.0
                 ;;=>   1.0
                -;;=>   4.0
                 ;;=>   3.0
                -;;=>   4.0
                +;;=>   1.0
                 ;;=>   2.0
                 ;;=>   1.0
                 ;;=>   1.0
                +;;=>   1.0
                 ;;=>   3.0
                 ;;=>   2.0
                -;;=>   1.0
                -;;=>   1.0
                +;;=>   4.0
                 ;;=>   2.0
                +;;=>   3.0
                +;;=>   3.0
                +;;=>   4.0)
                +;;=>  (1.0
                +;;=>   4.0
                 ;;=>   1.0
                 ;;=>   1.0
                -;;=>   1.0)
                -;;=>  (2.0
                 ;;=>   2.0
                +;;=>   3.0
                 ;;=>   1.0
                 ;;=>   3.0
                +;;=>   3.0
                 ;;=>   2.0
                 ;;=>   2.0
                +;;=>   1.0
                 ;;=>   2.0
                 ;;=>   1.0
                +;;=>   1.0
                 ;;=>   3.0
                 ;;=>   1.0
                 ;;=>   1.0
                 ;;=>   4.0
                -;;=>   1.0
                -;;=>   3.0
                -;;=>   2.0
                -;;=>   3.0
                -;;=>   1.0
                -;;=>   3.0
                -;;=>   3.0
                -;;=>   1.0))
                +;;=>   2.0))
                 (let [data [1 2 3 4 1 2 3 1 2 1]
                       fdata (frequencies data)
                       bdata (bootstrap data 5 1000)]
                   {:source fdata, :bootstrapped (map frequencies bdata)})
                -;;=> {:bootstrapped ({1.0 376, 2.0 325, 3.0 204, 4.0 95}
                -;;=>                 {1.0 400, 2.0 312, 3.0 195, 4.0 93}
                -;;=>                 {1.0 413, 2.0 305, 3.0 195, 4.0 87}
                -;;=>                 {1.0 387, 2.0 312, 3.0 201, 4.0 100}
                -;;=>                 {1.0 411, 2.0 301, 3.0 207, 4.0 81}),
                +;;=> {:bootstrapped ({1.0 413, 2.0 295, 3.0 203, 4.0 89}
                +;;=>                 {1.0 405, 2.0 308, 3.0 197, 4.0 90}
                +;;=>                 {1.0 429, 2.0 293, 3.0 188, 4.0 90}
                +;;=>                 {1.0 403, 2.0 283, 3.0 204, 4.0 110}
                +;;=>                 {1.0 386, 2.0 301, 3.0 207, 4.0 106}),
                 ;;=>  :source {1 4, 2 3, 3 2, 4 1}}

                bootstrap-ci

                deprecated in Please use fastmath.stats.boostrap/ci-basic instead

                (bootstrap-ci vs)(bootstrap-ci vs alpha)(bootstrap-ci vs alpha samples)(bootstrap-ci vs alpha samples stat-fn)

                Bootstrap method to calculate confidence interval.

                Alpha defaults to 0.98, samples to 1000. Last parameter is statistical function used to measure, default: mean.

                Returns ci and statistical function value.

                Examples

                Usage

                (bootstrap-ci [-5 1 1 1 1 2 2 5 11 71])
                -;;=> [-5.599999999999998 17.9 9.0]
                +;;=> [-6.300000000000001 17.8 9.0]
                 (bootstrap-ci [-5 1 1 1 1 2 2 5 11 71] 0.8)
                -;;=> [2.5 15.8 9.0]
                +;;=> [2.8000000000000007 15.7 9.0]
                 (bootstrap-ci [-5 1 1 1 1 2 2 5 11 71] 0.8 100000)
                 ;;=> [2.5999999999999996 15.7 9.0]
                 (bootstrap-ci [-5 1 1 1 1 2 2 5 11 71] 0.98 1000 median)
                -;;=> [-20.698 2.7 1.5]

                brown-forsythe-test

                (brown-forsythe-test xss)(brown-forsythe-test xss params)

                chisq-test

                (chisq-test contingency-table-or-xs)(chisq-test contingency-table-or-xs params)

                ci

                (ci vs)(ci vs alpha)

                T-student based confidence interval for given data. Alpha value defaults to 0.05.

                +;;=> [-20.698 2.7 1.5]

                brown-forsythe-test

                (brown-forsythe-test xss)(brown-forsythe-test xss params)

                chisq-test

                (chisq-test contingency-table-or-xs)(chisq-test contingency-table-or-xs params)

                ci

                (ci vs)(ci vs alpha)

                T-student based confidence interval for given data. Alpha value defaults to 0.05.

                Last value is mean.

                Examples

                Usage

                (ci [-5 1 1 1 1 2 2 5 11 71])
                @@ -487,7 +487,7 @@ 
                Descriptiv
                (let [a [:a :a :b :b :f :a :a :b :b :c :a :a :b :b :c :a :a :b :b :c]
                       b [:b :f :a :a :b :b :y :z :c :b :b :c :a :a :b :b :c :a :a :b]]
                   (cramers-v-corrected a b))
                -;;=> 0.3410563654946855

                cressie-read-test

                (cressie-read-test contingency-table-or-xs)(cressie-read-test contingency-table-or-xs params)

                demean

                (demean vs)

                Subtract mean from sequence

                +;;=> 0.3410563654946855

                cressie-read-test

                (cressie-read-test contingency-table-or-xs)(cressie-read-test contingency-table-or-xs params)

                demean

                (demean vs)

                Subtract mean from sequence

                Examples

                Usage

                (demean [-5 1 1 1 1 2 2 5 11 71])
                 ;;=> (-14.0 -8.0 -8.0 -8.0 -8.0 -7.0 -7.0 -4.0 2.0 62.0)

                epsilon-sq

                (epsilon-sq [group1 group2])(epsilon-sq group1 group2)

                Less biased R2

                @@ -506,11 +506,11 @@
                Descriptiv (estimate-bins vs :rice) ;;=> 20 (estimate-bins vs :doane) -;;=> 16 +;;=> 17 (estimate-bins vs :scott) -;;=> 31 +;;=> 39 (estimate-bins vs :freedman-diaconis) -;;=> 76

                estimation-strategies-list

                List of estimation strategies for percentile/quantile functions.

                +;;=> 98

                estimation-strategies-list

                List of estimation strategies for percentile/quantile functions.

                Examples

                List of estimation strategies for percentile

                (sort (keys estimation-strategies-list))
                 ;;=> (:legacy :r1 :r2 :r3 :r4 :r5 :r6 :r7 :r8 :r9)

                eta-sq

                (eta-sq [group1 group2])(eta-sq group1 group2)

                R2, coefficient of determination

                @@ -526,7 +526,7 @@
                Descriptiv
              • alpha - significance level (default: 0.05)
              • sides - one of: :two-sided (default), :one-sided-less (short: :one-sided) or :one-sided-greater
              • -

                fligner-killeen-test

                (fligner-killeen-test xss)(fligner-killeen-test xss {:keys [sides], :or {sides :one-sided-greater}})

                freeman-tukey-test

                (freeman-tukey-test contingency-table-or-xs)(freeman-tukey-test contingency-table-or-xs params)

                geomean

                (geomean vs)

                Geometric mean for positive values only

                +

                fligner-killeen-test

                (fligner-killeen-test xss)(fligner-killeen-test xss {:keys [sides], :or {sides :one-sided-greater}})

                freeman-tukey-test

                (freeman-tukey-test contingency-table-or-xs)(freeman-tukey-test contingency-table-or-xs params)

                geomean

                (geomean vs)

                Geometric mean for positive values only

                Examples

                Geometric mean

                (geomean [1 2 3 1 1 2 1 11 111])
                 ;;=> 2.903203203730772

                glass-delta

                (glass-delta [group1 group2])(glass-delta group1 group2)

                Glass’s delta effect size for two groups

                @@ -566,20 +566,20 @@
                Descriptiv

                If difference between min and max values is 0, number of bins is set to 1.

                Examples

                3 bins from uniform distribution.

                (histogram (repeatedly 1000 rand) 3)
                -;;=> {:bins ([3.6688282750596546E-4 332]
                -;;=>         [0.3330912011095961 332]
                -;;=>         [0.6658155193916863 336]),
                -;;=>  :max 0.9985398376737764,
                -;;=>  :min 3.6688282750596546E-4,
                +;;=> {:bins ([6.237964863657908E-4 335]
                +;;=>         [0.33350733411402445 353]
                +;;=>         [0.6663908717416831 312]),
                +;;=>  :max 0.9992744093693418,
                +;;=>  :min 6.237964863657908E-4,
                 ;;=>  :samples 1000,
                 ;;=>  :size 3,
                -;;=>  :step 0.33272431828209015}

                3 bins from uniform distribution for given range.

                +;;=> :step 0.33288353762765865}

                3 bins from uniform distribution for given range.

                (histogram (repeatedly 10000 rand) 3 [0.1 0.5])
                 ;;=> {:bins
                -;;=>  ([0.1 1282] [0.23333333333333334 1347] [0.3666666666666667 1275]),
                +;;=>  ([0.1 1328] [0.23333333333333334 1355] [0.3666666666666667 1376]),
                 ;;=>  :max 0.5,
                 ;;=>  :min 0.1,
                -;;=>  :samples 3904,
                +;;=>  :samples 4059,
                 ;;=>  :size 3,
                 ;;=>  :step 0.13333333333333333}

                5 bins from normal distribution.

                (histogram (repeatedly 10000 r/grand) 5)
                @@ -611,9 +611,9 @@ 
                Descriptiv
                (kendall-correlation (repeatedly 100000 (partial r/grand 1.0 10.0))
                                      (repeatedly 100000 (partial r/drand -10.0 -5.0)))
                 ;;=> 2.81850018500185E-4

                kruskal-test

                (kruskal-test xss)(kruskal-test xss {:keys [sides], :or {sides :right}})

                Kruskal-Wallis rank sum test.

                -

                ks-test-one-sample

                (ks-test-one-sample xs)(ks-test-one-sample xs distribution-or-ys)(ks-test-one-sample xs distribution-or-ys {:keys [sides kernel bandwidth distinct?], :or {sides :two-sided, kernel :gaussian, distinct? true}})

                One sample Kolmogorov-Smirnov test

                -

                ks-test-two-samples

                (ks-test-two-samples xs ys)(ks-test-two-samples xs ys {:keys [sides distinct?], :or {sides :two-sided, distinct? true}})

                Two samples Kolmogorov-Smirnov test

                -

                kullback-leibler-divergence

                (kullback-leibler-divergence [vs1 vs2])(kullback-leibler-divergence vs1 vs2)

                Kullback-Leibler divergence of two sequences.

                +

                ks-test-one-sample

                (ks-test-one-sample xs)(ks-test-one-sample xs distribution-or-ys)(ks-test-one-sample xs distribution-or-ys {:keys [sides kernel bandwidth distinct?], :or {sides :two-sided, kernel :gaussian, distinct? true}})

                One sample Kolmogorov-Smirnov test

                +

                ks-test-two-samples

                (ks-test-two-samples xs ys)(ks-test-two-samples xs ys {:keys [sides distinct?], :or {sides :two-sided, distinct? true}})

                Two samples Kolmogorov-Smirnov test

                +

                kullback-leibler-divergence

                (kullback-leibler-divergence [vs1 vs2])(kullback-leibler-divergence vs1 vs2)

                Kullback-Leibler divergence of two sequences.

                Examples

                Kullback-Leibler divergence.

                (kullback-leibler-divergence (repeatedly 100 (fn* [] (r/irand 100)))
                                              (repeatedly 100 (fn* [] (r/irand 100))))
                @@ -633,7 +633,7 @@ 
                Descriptiv

                L1

                (L1 [vs1 vs2-or-val])(L1 vs1 vs2-or-val)

                Manhattan distance

                L2

                (L2 [vs1 vs2-or-val])(L2 vs1 vs2-or-val)

                Euclidean distance

                L2sq

                (L2sq [vs1 vs2-or-val])(L2sq vs1 vs2-or-val)

                Squared euclidean distance

                -

                levene-test

                (levene-test xss)(levene-test xss {:keys [sides statistic scorediff], :or {sides :one-sided-greater, statistic mean, scorediff abs}})

                LInf

                (LInf [vs1 vs2-or-val])(LInf vs1 vs2-or-val)

                Chebyshev distance

                +

                levene-test

                (levene-test xss)(levene-test xss {:keys [sides statistic scorediff], :or {sides :one-sided-greater, statistic mean, scorediff abs}})

                LInf

                (LInf [vs1 vs2-or-val])(LInf vs1 vs2-or-val)

                Chebyshev distance

                mad-extent

                (mad-extent vs)

                -/+ median-absolute-deviation and median

                Examples

                median absolute deviation from median for gaussian distribution

                @@ -665,7 +665,7 @@
                Descriptiv ;;=> 3.0

                minimum

                (minimum vs)

                Minimum value from sequence.

                Examples

                Minimum value

                (minimum [1 2 3 -1 -1 2 -1 11 111])
                -;;=> -1.0

                minimum-discrimination-information-test

                (minimum-discrimination-information-test contingency-table-or-xs)(minimum-discrimination-information-test contingency-table-or-xs params)

                mode

                (mode vs method)(mode vs method opts)(mode vs)

                Find the value that appears most often in a dataset vs.

                +;;=> -1.0

                minimum-discrimination-information-test

                (minimum-discrimination-information-test contingency-table-or-xs)(minimum-discrimination-information-test contingency-table-or-xs params)

                mode

                (mode vs method)(mode vs method opts)(mode vs)

                Find the value that appears most often in a dataset vs.

                For sample from continuous distribution, three algorithms are possible: * :histogram - calculated from histogram * :kde - calculated from KDE * :pearson - mode = mean-3(median-mean) * :default - discrete mode

                Histogram accepts optional :bins (see histogram). KDE method accepts :kde for kernel name (default :gaussian) and :bandwidth (auto). Pearson can accept :estimation-strategy for median.

                See also modes.

                @@ -707,12 +707,12 @@
                Descriptiv ;;=> 666.2 (moment [3 7 5 9 -8] 0.5 {:absolute? true}) ;;=> 1.8986344545712772

                mse

                (mse [vs1 vs2-or-val])(mse vs1 vs2-or-val)

                Mean squared error

                -

                multinomial-likelihood-ratio-test

                (multinomial-likelihood-ratio-test contingency-table-or-xs)(multinomial-likelihood-ratio-test contingency-table-or-xs params)

                neyman-modified-chisq-test

                (neyman-modified-chisq-test contingency-table-or-xs)(neyman-modified-chisq-test contingency-table-or-xs params)

                omega-sq

                (omega-sq [group1 group2])(omega-sq group1 group2)

                Adjusted R2

                +

                multinomial-likelihood-ratio-test

                (multinomial-likelihood-ratio-test contingency-table-or-xs)(multinomial-likelihood-ratio-test contingency-table-or-xs params)

                neyman-modified-chisq-test

                (neyman-modified-chisq-test contingency-table-or-xs)(neyman-modified-chisq-test contingency-table-or-xs params)

                omega-sq

                (omega-sq [group1 group2])(omega-sq group1 group2)

                Adjusted R2

                Examples

                Usage

                (let [t [10 10 20 20 20 30 30 30 40 50]
                       c [-50 20 30 40 40 50 10 20 30 10]]
                   (omega-sq t c))
                -;;=> -0.04795737122557726

                one-way-anova-test

                (one-way-anova-test xss)(one-way-anova-test xss {:keys [sides], :or {sides :one-sided-greater}})

                outer-fence-extent

                (outer-fence-extent vs)(outer-fence-extent vs estimation-strategy)

                Returns LOF, UOF and median

                +;;=> -0.04795737122557726

                one-way-anova-test

                (one-way-anova-test xss)(one-way-anova-test xss {:keys [sides], :or {sides :one-sided-greater}})

                outer-fence-extent

                (outer-fence-extent vs)(outer-fence-extent vs estimation-strategy)

                Returns LOF, UOF and median

                outliers

                (outliers vs)(outliers vs estimation-strategy)(outliers vs q1 q3)

                Find outliers defined as values outside inner fences.

                Let Q1 is 25-percentile and Q3 is 75-percentile. IQR is (- Q3 Q1).

                  @@ -727,23 +727,23 @@
                  Descriptiv
                  (count (outliers (repeatedly 3000000 r/grand)))
                   ;;=> 20911

                p-overlap

                (p-overlap [group1 group2])(p-overlap group1 group2)(p-overlap group1 group2 {:keys [kde bandwidth min-iterations steps], :or {kde :gaussian, min-iterations 3, steps 500}})

                Overlapping index, kernel density approximation

                p-value

                (p-value stat)(p-value distribution stat)(p-value distribution stat sides)

                Calculate p-value for given distribution (default: N(0,1)), stat and sides (one of :two-sided, :one-sided-greater or :one-sided-less/:one-sided).

                -

                pacf

                (pacf data)(pacf data lags)

                Caluclate pacf (partial autocorrelation function) for given number of lags.

                +

                pacf

                (pacf data)(pacf data lags)

                Caluclate pacf (partial autocorrelation function) for given number of lags.

                If lags is omitted function returns maximum possible number of lags.

                pacf returns also lag 0 (which is 0.0).

                See also acf, acf-ci, pacf-ci

                Examples

                Usage

                (pacf (repeatedly 1000 r/grand) 10)
                 ;;=> (0.0
                -;;=>  -0.007493264913704035
                -;;=>  0.0395094028897875
                -;;=>  -0.02711968252716128
                -;;=>  -8.127647576342595E-4
                -;;=>  0.02318435307600106
                -;;=>  -0.07492493089581811
                -;;=>  -0.004158017214958471
                +;;=>  -0.007493264913704033
                +;;=>  0.03950940288978749
                +;;=>  -0.027119682527161276
                +;;=>  -8.127647576342593E-4
                +;;=>  0.023184353076001057
                +;;=>  -0.07492493089581809
                +;;=>  -0.00415801721495847
                 ;;=>  -0.029857518595778
                -;;=>  -0.025366182150073035
                -;;=>  0.02293649431732737)
                +;;=>  -0.025366182150073028
                +;;=>  0.02293649431732736)
                 (pacf [1 2 3 4 5 4 3 2 1])
                 ;;=> (0.0
                 ;;=>  0.5396825396825397
                @@ -753,15 +753,15 @@ 
                Descriptiv ;;=> 0.17585056996358742 ;;=> -0.2652225487589841 ;;=> -0.17978918763554708 -;;=> -0.10771973872263883)

                pacf-ci

                (pacf-ci data)(pacf-ci data lags)(pacf-ci data lags alpha)

                pacf with added confidence interval data.

                +;;=> -0.10771973872263883)

                pacf-ci

                (pacf-ci data)(pacf-ci data lags)(pacf-ci data lags alpha)

                pacf with added confidence interval data.

                Examples

                Usage

                (pacf-ci (repeatedly 1000 r/grand) 3)
                 ;;=> {:ci 0.06197950323045615,
                 ;;=>  :pacf
                -;;=>  (0.0 -0.049307948814106516 -0.005276481462760805 -0.03643226574541987)}
                +;;=>  (0.0 -0.04930794881410651 -0.005276481462760803 -0.03643226574541986)}
                 (pacf-ci [1 2 3 4 5 4 3 2 1] 3)
                 ;;=> {:ci 0.653321328180018,
                -;;=>  :pacf (0.0 0.5396825396825397 -0.4299857803057234 -0.388084834596935)}

                pearson-correlation

                (pearson-correlation [vs1 vs2])(pearson-correlation vs1 vs2)

                Pearson’s correlation of two sequences.

                +;;=> :pacf (0.0 0.5396825396825397 -0.4299857803057234 -0.388084834596935)}

                pearson-correlation

                (pearson-correlation [vs1 vs2])(pearson-correlation vs1 vs2)

                Pearson’s correlation of two sequences.

                Examples

                Pearson’s correlation of uniform and gaussian distribution samples.

                (pearson-correlation (repeatedly 100000 (partial r/grand 1.0 10.0))
                                      (repeatedly 100000 (partial r/drand -10.0 -5.0)))
                @@ -812,7 +812,7 @@ 
                Descriptiv (percentile-bc-extent (repeatedly 100000 r/grand) 10) ;;=> [-1.2644568505959903 1.2992608668913583 0.006974183450094526] (percentile-bc-extent (repeatedly 100000 r/grand) 30 70) -;;=> [-0.5390348516759447 0.5110256349062376 7.918286580104579E-4]

                percentile-bca-extent

                (percentile-bca-extent vs)(percentile-bca-extent vs p)(percentile-bca-extent vs p1 p2)(percentile-bca-extent vs p1 p2 estimation-strategy)(percentile-bca-extent vs p1 p2 accel estimation-strategy)

                Return bias corrected percentile range and mean for bootstrap samples. Also accounts for variance variations throught the accelaration parameter. See https://projecteuclid.org/euclid.ss/1032280214

                +;;=> [-0.5390348516759447 0.5110256349062376 7.918286580104579E-4]

                percentile-bca-extent

                (percentile-bca-extent vs)(percentile-bca-extent vs p)(percentile-bca-extent vs p1 p2)(percentile-bca-extent vs p1 p2 estimation-strategy)(percentile-bca-extent vs p1 p2 accel estimation-strategy)

                Return bias corrected percentile range and mean for bootstrap samples. Also accounts for variance variations throught the accelaration parameter. See https://projecteuclid.org/euclid.ss/1032280214

                p - calculates extent of bias corrected p and 100-p (default: p=2.5)

                Set estimation-strategy to :r7 to get the same result as in R coxed::bca.

                Examples

                for samples from gaussian distribution

                @@ -821,7 +821,7 @@
                Descriptiv (percentile-bca-extent (repeatedly 100000 r/grand) 10) ;;=> [-1.2666928768037038 1.2838206326649084 0.0011417437187627867] (percentile-bca-extent (repeatedly 100000 r/grand) 30 70) -;;=> [-0.5316035303243614 0.5241767534807082 0.001668106379069707]

                percentile-extent

                (percentile-extent vs)(percentile-extent vs p)(percentile-extent vs p1 p2)(percentile-extent vs p1 p2 estimation-strategy)

                Return percentile range and median.

                +;;=> [-0.5316035303243614 0.5241767534807082 0.001668106379069707]

                percentile-extent

                (percentile-extent vs)(percentile-extent vs p)(percentile-extent vs p1 p2)(percentile-extent vs p1 p2 estimation-strategy)

                Return percentile range and median.

                p - calculates extent of p and 100-p (default: p=25)

                Examples

                for samples from gaussian distribution

                (percentile-extent (repeatedly 100000 r/grand))
                @@ -851,7 +851,7 @@ 
                Descriptiv

                See variance.

                Examples

                Population variance

                (population-variance [1 2 3 -1 -1 2 -1 11 111])
                -;;=> 1185.6543209876543

                power-divergence-test

                (power-divergence-test contingency-table-or-xs)(power-divergence-test contingency-table-or-xs {:keys [lambda ci-sides sides p alpha bootstrap-samples ddof], :or {lambda m/TWO_THIRD, sides :one-sided-greater, ci-sides :two-sided, alpha 0.05, bootstrap-samples 1000, ddof 0}})

                powmean

                (powmean vs power)

                Generalized power mean

                +;;=> 1185.6543209876543

                power-divergence-test

                (power-divergence-test contingency-table-or-xs)(power-divergence-test contingency-table-or-xs {:keys [lambda ci-sides sides p alpha bootstrap-samples ddof], :or {lambda m/TWO_THIRD, sides :one-sided-greater, ci-sides :two-sided, alpha 0.05, bootstrap-samples 1000, ddof 0}})

                powmean

                (powmean vs power)

                Generalized power mean

                Examples

                Power mean

                (powmean [1 2 3 1 1 2 1 11 111] 0.0)
                 ;;=> 2.903203203730772
                @@ -1011,7 +1011,7 @@ 
                Descriptiv
              • sides - one of: :two-sided, :one-sided-less (short: :one-sided) or :one-sided-greater
              • mu - mean (default: 0.0)
              • -

                t-test-two-samples

                (t-test-two-samples xs ys)(t-test-two-samples xs ys {:keys [paired? equal-variances?], :or {paired? false, equal-variances? false}, :as params})

                Two samples Student’s t-test

                +

                t-test-two-samples

                (t-test-two-samples xs ys)(t-test-two-samples xs ys {:keys [paired? equal-variances?], :or {paired? false, equal-variances? false}, :as params})

                Two samples Student’s t-test

                • alpha - significance level (default: 0.05)
                • sides - one of: :two-sided (default), :one-sided-less (short: :one-sided) or :one-sided-greater
                • @@ -1019,7 +1019,7 @@
                  Descriptiv
                • paired? - unpaired or paired test, boolean (default: false)
                • equal-variances? - unequal or equal variances, boolean (default: false)
                -

                trim

                (trim vs)(trim vs quantile)(trim vs quantile estimation-strategy)(trim vs low high nan)

                Return trimmed data. Trim is done by using quantiles, by default is set to 0.2.

                +

                trim

                (trim vs)(trim vs quantile)(trim vs quantile estimation-strategy)(trim vs low high nan)

                Return trimmed data. Trim is done by using quantiles, by default is set to 0.2.

                tschuprows-t

                (tschuprows-t group1 group2)(tschuprows-t contingency-table)

                Tschuprows T effect size for discrete data

                Examples

                Usage

                (let [a [:a :a :b :b :f :a :a :b :b :c :a :a :b :b :c :a :a :b :b :c]
                @@ -1077,7 +1077,7 @@ 
                Descriptiv ;;=> :stat 0.5222329678670935, ;;=> :stderr 0.9574271077563381, ;;=> :t 0.5222329678670935, -;;=> :test-type :two-sided}

                ttest-two-samples

                deprecated in Use [[t-test-two-samples]]

                Examples

                Usage

                +;;=> :test-type :two-sided}

                ttest-two-samples

                deprecated in Use [[t-test-two-samples]]

                Examples

                Usage

                (ttest-two-samples [1 2 3 4 5 6 7 8 9 10]
                                    [7 8 9 10 11 12 13 14 15 16 17 18 19 20])
                 ;;=> {:alpha 0.05,
                @@ -1154,7 +1154,7 @@ 
                Descriptiv ;;=> :stat -3.156496045715208, ;;=> :stderr 31.680698645494967, ;;=> :t -3.156496045715208, -;;=> :test-type :two-sided}

                variance

                (variance vs)(variance vs u)

                Calculate variance of vs.

                +;;=> :test-type :two-sided}

                variance

                (variance vs)(variance vs u)

                Calculate variance of vs.

                See population-variance.

                Examples

                Variance.

                (variance [1 2 3 -1 -1 2 -1 11 111])
                @@ -1178,7 +1178,7 @@ 
                Descriptiv
              • sides - one of: :two-sided, :one-sided-less (short: :one-sided) or :one-sided-greater
              • mu - mean (default: 0.0)
              • -

                z-test-two-samples

                (z-test-two-samples xs ys)(z-test-two-samples xs ys {:keys [paired? equal-variances?], :or {paired? false, equal-variances? false}, :as params})

                Two samples z-test

                +

                z-test-two-samples

                (z-test-two-samples xs ys)(z-test-two-samples xs ys {:keys [paired? equal-variances?], :or {paired? false, equal-variances? false}, :as params})

                Two samples z-test

                • alpha - significance level (default: 0.05)
                • sides - one of: :two-sided (default), :one-sided-less (short: :one-sided) or :one-sided-greater
                • @@ -1186,4 +1186,4 @@
                  Descriptiv
                • paired? - unpaired or paired test, boolean (default: false)
                • equal-variances? - unequal or equal variances, boolean (default: false)
                -
                \ No newline at end of file +
                \ No newline at end of file diff --git a/docs/fastmath.transform.html b/docs/fastmath.transform.html index c644c691..0c48adb9 100644 --- a/docs/fastmath.transform.html +++ b/docs/fastmath.transform.html @@ -1,6 +1,6 @@ -fastmath.transform documentation

                fastmath.transform

                Transforms.

                +fastmath.transform documentation

                fastmath.transform

                Transforms.

                See transformer and TransformProto for details.

                Wavelet

                Based on JWave library.

                @@ -116,7 +116,7 @@

                Fourier

                Examples

                Usage

                (transformer :packet :discrete-mayer)
                -;;=> jwave.transforms.WaveletPacketTransform@5de80493

                wavelets-list

                List of all possible wavelets.

                +;;=> jwave.transforms.WaveletPacketTransform@7b42883

                wavelets-list

                List of all possible wavelets.

                Examples

                List of wavelets

                (sort wavelets-list)
                 ;;=> (:battle-23
                diff --git a/docs/fastmath.vector.html b/docs/fastmath.vector.html
                index fe30142f..80fdd0fc 100644
                --- a/docs/fastmath.vector.html
                +++ b/docs/fastmath.vector.html
                @@ -1,6 +1,6 @@
                 
                -fastmath.vector documentation

                fastmath.vector

                Mathematical vector operations.

                +fastmath.vector documentation

                fastmath.vector

                acos

                (acos vector)

                Apply acos to vector elements.

                Examples

                Usage

                (acos (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [1.0471975511965976 ##NaN ##NaN 1.5707963267948966]

                acosh

                (acosh vector)

                Apply acosh to vector elements.

                +;;=> [1.0471975511965976 ##NaN ##NaN 1.5707963267948966]

                acosh

                (acosh vector)

                Apply acosh to vector elements.

                Examples

                Usage

                (acosh (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [##NaN ##NaN 1.37285914424258 ##NaN]

                acot

                (acot vector)

                Apply acot to vector elements.

                +;;=> [##NaN ##NaN 1.37285914424258 ##NaN]

                acot

                (acot vector)

                Apply acot to vector elements.

                Examples

                Usage

                (acot (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                 ;;=> [1.1071487177940904 2.5535900500422257 0.44441920990109884
                -;;=>  1.5707963267948966]

                acoth

                (acoth vector)

                Apply acoth to vector elements.

                +;;=> 1.5707963267948966]

                acoth

                (acoth vector)

                Apply acoth to vector elements.

                Examples

                Usage

                (acoth (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [##NaN -0.8047189562170501 0.5180459658433878 ##NaN]

                acsc

                (acsc vector)

                Apply acsc to vector elements.

                +;;=> [##NaN -0.8047189562170501 0.5180459658433878 ##NaN]

                acsc

                (acsc vector)

                Apply acsc to vector elements.

                Examples

                Usage

                (acsc (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [##NaN -0.7297276562269663 0.49631736212546657 ##NaN]

                add

                (add v)(add v1 v2)

                Sum of two vectors.

                +;;=> [##NaN -0.7297276562269663 0.49631736212546657 ##NaN]

                acsch

                (acsch vector)

                Apply acsch to vector elements.

                +

                add

                (add v)(add v1 v2)

                Sum of two vectors.

                Examples

                Usage

                (add (vec2 1 2) (vec2 -1 -2))
                -;;=> [0.0 0.0]

                aligned?

                (aligned? v1 v2 tol)(aligned? v1 v2)

                Are vectors aligned (have the same direction)?

                +;;=> [0.0 0.0]

                aligned?

                (aligned? v1 v2 tol)(aligned? v1 v2)

                Are vectors aligned (have the same direction)?

                Examples

                Usage

                (aligned? (vec2 1.0 1.0) (vec2 2.0 2.000001))
                 ;;=> true
                @@ -72,31 +73,31 @@ 

                Types

                (aligned? (vec2 1.0 1.0) (vec2 2.0 2.00001) 0.001) ;;=> true -;; Test: ok.

                angle-between

                (angle-between v1 v2)

                Angle between two vectors

                +;; Test: ok.

                angle-between

                (angle-between v1 v2)

                Angle between two vectors

                See also relative-angle-between.

                Examples

                Usage

                (m/degrees (angle-between (vec3 1.0 0.0 0.0) (vec3 0.0 1.0 0.0)))
                 ;;=> 90.0
                 (m/degrees (angle-between (vec (repeatedly 50 rand))
                                           (vec (repeatedly 50 rand))))
                -;;=> 47.112737511777

                applyf

                deprecated in v1.3.0

                Same as fmap. Deprecated.

                +;;=> 39.57994267909173

                applyf

                deprecated in v1.3.0

                Same as fmap. Deprecated.

                Examples

                Usage

                (applyf [5 3] (fn [v] (m/sin v)))
                -;;=> [-0.9589242746631386 0.1411200080598671]

                approx

                (approx v)(approx v d)

                Round to 2 (or d) decimal places

                +;;=> [-0.9589242746631386 0.1411200080598671]

                approx

                (approx v)(approx v d)

                Round to 2 (or d) decimal places

                Examples

                Usage

                (approx (vec2 (m/sin -1) (m/cos 1)))
                 ;;=> [-0.84 0.54]
                 (approx (vec2 (m/sin -1) (m/cos 1)) 6)
                -;;=> [-0.841471 0.540302]

                array->vec2

                (array->vec2 arr)

                Doubles array to Vec2

                +;;=> [-0.841471 0.540302]

                array->vec2

                (array->vec2 arr)

                Doubles array to Vec2

                Examples

                Usage

                (array->vec2 (double-array [11 22 33 44 55]))
                -;;=> [11.0 22.0]

                array->vec3

                (array->vec3 arr)

                Doubles array to Vec3

                +;;=> [11.0 22.0]

                array->vec3

                (array->vec3 arr)

                Doubles array to Vec3

                Examples

                Usage

                (array->vec3 (double-array [11 22 33 44 55]))
                -;;=> [11.0 22.0 33.0]

                array->vec4

                (array->vec4 arr)

                Doubles array to Vec4

                +;;=> [11.0 22.0 33.0]

                array->vec4

                (array->vec4 arr)

                Doubles array to Vec4

                Examples

                Usage

                (array->vec4 (double-array [11 22 33 44 55]))
                -;;=> [11.0 22.0 33.0 44.0]

                array-vec

                (array-vec xs)

                Make ArrayVec type based on provided sequence xs.

                +;;=> [11.0 22.0 33.0 44.0]

                array-vec

                (array-vec xs)

                Make ArrayVec type based on provided sequence xs.

                Examples

                Usage

                (array-vec [1 2 3 4 5 6 7])
                 ;;=> [1.0 2.0 3.0 4.0 5.0 6.0 7.0]
                @@ -109,7 +110,7 @@ 

                Types

                (count (array-vec (range 0.1 1.0 0.05))) ;;=> 18 (seq (array-vec [1 2])) -;;=> (1.0 2.0)

                as-vec

                (as-vec v)(as-vec v xs)

                Create vector from sequence as given type. If there is no sequence fill with 0.0.

                +;;=> (1.0 2.0)

                as-vec

                (as-vec v)(as-vec v xs)

                Create vector from sequence as given type. If there is no sequence fill with 0.0.

                Examples

                Create vectors

                (as-vec [1 2 3])
                 ;;=> [0.0 0.0 0.0]
                @@ -118,31 +119,31 @@ 

                Types

                (as-vec (vec3 1 2 3) (repeat -10)) ;;=> [-10.0 -10.0 -10.0] (type (as-vec (array-vec [1 1 11 2 3]) (repeat -10))) -;;=> class fastmath.vector.ArrayVec

                asec

                (asec vector)

                Apply asec to vector elements.

                +;;=> class fastmath.vector.ArrayVec

                asec

                (asec vector)

                Apply asec to vector elements.

                Examples

                Usage

                (asec (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [##NaN 2.300523983021863 1.07447896466943 ##NaN]

                asech

                (asech vector)

                Apply asech to vector elements.

                +;;=> [##NaN 2.300523983021863 1.07447896466943 ##NaN]

                asech

                (asech vector)

                Apply asech to vector elements.

                Examples

                Usage

                (asech (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [1.3169578969248166 ##NaN ##NaN ##Inf]

                asin

                (asin vector)

                Apply asin to vector elements.

                +;;=> [1.3169578969248166 ##NaN ##NaN ##Inf]

                asin

                (asin vector)

                Apply asin to vector elements.

                Examples

                Usage

                (asin (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.5235987755982989 ##NaN ##NaN 0.0]

                asinh

                (asinh vector)

                Apply asinh to vector elements.

                +;;=> [0.5235987755982989 ##NaN ##NaN 0.0]

                asinh

                (asinh vector)

                Apply asinh to vector elements.

                Examples

                Usage

                (asinh (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.48121182505960347 -1.1947632172871094 1.4874828366412711 0.0]

                atan

                (atan vector)

                Apply atan to vector elements.

                +;;=> [0.48121182505960347 -1.1947632172871094 1.4874828366412711 0.0]

                atan

                (atan vector)

                Apply atan to vector elements.

                Examples

                Usage

                (atan (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.4636476090008061 -0.9827937232473292 1.1263771168937977 0.0]

                atanh

                (atanh vector)

                Apply atanh to vector elements.

                +;;=> [0.4636476090008061 -0.9827937232473292 1.1263771168937977 0.0]

                atanh

                (atanh vector)

                Apply atanh to vector elements.

                Examples

                Usage

                (atanh (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.5493061443340548 ##NaN ##NaN 0.0]

                average

                (average v)(average v weights)

                Mean or weighted average of the vector

                -

                average-vectors

                (average-vectors init vs)(average-vectors vs)

                Average / centroid of vectors. Input: initial vector (optional), list of vectors

                +;;=> [0.5493061443340548 ##NaN ##NaN 0.0]

                average

                (average v)(average v weights)

                Mean or weighted average of the vector

                +

                average-vectors

                (average-vectors init vs)(average-vectors vs)

                Average / centroid of vectors. Input: initial vector (optional), list of vectors

                Examples

                Usage

                (average-vectors [[1 2] [0 1] [3 4] [1 2] [4 -1]])
                 ;;=> [1.8 1.6]
                 (average-vectors (vec2 0 0) [(vec2 1 1) (vec2 1 1) (vec2 1 1)])
                -;;=> [0.75 0.75]

                axis-rotate

                (axis-rotate v angle axis)(axis-rotate v angle axis pivot)

                Rotate vector. Only for Vec3 types

                +;;=> [0.75 0.75]

                axis-rotate

                (axis-rotate v angle axis)(axis-rotate v angle axis pivot)

                Rotate vector. Only for Vec3 types

                Examples

                Usage

                (axis-rotate (vec3 1.0 0.0 0.0) m/HALF_PI (vec3 0.0 1.0 0.0))
                 ;;=> [6.12323399538461E-17 0.0 -1.0]
                @@ -150,110 +151,111 @@ 

                Types

                m/HALF_PI (vec3 0.0 1.0 0.0) (vec3 1.0 1.0 1.0)) -;;=> [0.0 0.0 0.9999999999999999]

                base-from

                (base-from v)

                List of perpendicular vectors (basis). Works only for Vec2 and Vec3 types.

                +;;=> [0.0 0.0 0.9999999999999999]

                base-from

                (base-from v)

                List of perpendicular vectors (basis). Works only for Vec2 and Vec3 types.

                Examples

                Usage

                (base-from (vec3 0.1 1.0 -1.0))
                 ;;=> [[0.1 1.0 -1.0] [0.0 -0.7071067811865475 -0.7071067811865475]
                 ;;=>  [-1.414213562373095 0.07071067811865475 -0.07071067811865475]]
                 (base-from (vec2 1.0 0.0))
                -;;=> [[1.0 0.0] [-0.0 1.0]]

                cbrt

                (cbrt vector)

                Apply cbrt to vector elements.

                +;;=> [[1.0 0.0] [-0.0 1.0]]

                cb

                (cb vector)

                Apply cb to vector elements.

                +

                cbrt

                (cbrt vector)

                Apply cbrt to vector elements.

                Examples

                Usage

                (cbrt (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.7937005259840997 -1.1447142425533319 1.2805791649874945 0.0]

                ceil

                (ceil vector)

                Apply ceil to vector elements.

                +;;=> [0.7937005259840997 -1.1447142425533319 1.2805791649874945 0.0]

                ceil

                (ceil vector)

                Apply ceil to vector elements.

                Examples

                Usage

                (ceil (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [1.0 -1.0 3.0 0.0]

                clamp

                (clamp v mn mx)(clamp v)

                Clamp elements.

                +;;=> [1.0 -1.0 3.0 0.0]

                clamp

                (clamp v mn mx)(clamp v)

                Clamp elements.

                Examples

                Clamp

                (clamp [-1 -2 -3 1 2 3])
                 ;;=> [0.0 0.0 0.0 1.0 2.0 3.0]
                 (clamp [-1 -2 -3 1 2 3] -2.5 2.5)
                -;;=> [-1.0 -2.0 -2.5 1.0 2.0 2.5]

                cos

                (cos vector)

                Apply cos to vector elements.

                +;;=> [-1.0 -2.0 -2.5 1.0 2.0 2.5]

                cos

                (cos vector)

                Apply cos to vector elements.

                Examples

                Usage

                (cos (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.8775825618903728 0.07073720166770284 -0.5048461045998573 1.0]

                cosh

                (cosh vector)

                Apply cosh to vector elements.

                +;;=> [0.8775825618903728 0.07073720166770284 -0.5048461045998573 1.0]

                cosh

                (cosh vector)

                Apply cosh to vector elements.

                Examples

                Usage

                (cosh (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [1.1276259652063807 2.3524096152432477 4.1443131704103155 1.0]

                cot

                (cot vector)

                Apply cot to vector elements.

                +;;=> [1.1276259652063807 2.3524096152432477 4.1443131704103155 1.0]

                cot

                (cot vector)

                Apply cot to vector elements.

                Examples

                Usage

                (cot (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [1.8304877217124518 -0.0709148443026525 -0.5848478064594647
                -;;=>  1.6331239354134602E16]

                coth

                (coth vector)

                Apply coth to vector elements.

                +;;=> [1.830487721712452 -0.07091484430265245 -0.5848478064594645 ##Inf]

                coth

                (coth vector)

                Apply coth to vector elements.

                Examples

                Usage

                (coth (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [2.163953413738653 -1.104791392982512 1.0304477349900076 ##Inf]

                cross

                (cross v1 v2)

                Cross product

                +;;=> [2.163953413738653 -1.104791392982512 1.0304477349900076 ##Inf]

                cross

                (cross v1 v2)

                Cross product

                Examples

                Usage

                (cross (vec3 1 2 3) (vec3 4 3 2))
                 ;;=> [-5.0 10.0 -5.0]
                 (cross (vec2 1 2) (vec2 -1 2))
                -;;=> 4.0

                csc

                (csc vector)

                Apply csc to vector elements.

                +;;=> 4.0

                csc

                (csc vector)

                Apply csc to vector elements.

                Examples

                Usage

                (csc (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [2.0858296429334886 -1.0025113042467249 1.1584675035237058 ##Inf]

                csch

                (csch vector)

                Apply csch to vector elements.

                +;;=> [2.0858296429334886 -1.0025113042467249 1.1584675035237058 ##Inf]

                csch

                (csch vector)

                Apply csch to vector elements.

                Examples

                Usage

                (csch (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                 ;;=> [1.9190347513349437 -0.46964244059522453 0.24864137738123349 ##Inf]

                Usage

                (csch (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [1.9190347513349437 -0.46964244059522453 0.24864137738123349 ##Inf]

                degrees

                (degrees vector)

                Apply degrees to vector elements.

                +;;=> [1.9190347513349437 -0.46964244059522453 0.24864137738123349 ##Inf]

                degrees

                (degrees vector)

                Apply degrees to vector elements.

                Examples

                Usage

                (degrees (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [28.64788975654116 -85.94366926962348 120.32113697747289 0.0]

                dhash-code

                (dhash-code state a)(dhash-code a)

                double hashcode

                -

                dist

                (dist v1 v2)

                Euclidean distance between vectors

                +;;=> [28.64788975654116 -85.94366926962348 120.32113697747289 0.0]

                delta-eq

                (delta-eq v1 v2 tol)(delta-eq v1 v2)

                Equality with given toleance

                +

                dhash-code

                (dhash-code state a)(dhash-code a)

                double hashcode

                +

                dist

                (dist v1 v2)

                Euclidean distance between vectors

                Examples

                Usage

                (dist (vec4 1.0 2.0 -1.0 -2.0) (vec4 1.0 -2.0 3.0 4.0))
                 ;;=> 8.246211251235321
                 (dist [9 8 7 6 5 4 3 2 1] [9 8 7 6 5 5 5 5 5])
                -;;=> 5.477225575051661

                dist-abs

                (dist-abs v1 v2)

                Manhattan distance between vectors

                +;;=> 5.477225575051661

                dist-abs

                (dist-abs v1 v2)

                Manhattan distance between vectors

                Examples

                Usage

                (dist-abs (vec4 1.0 2.0 -1.0 -2.0) (vec4 1.0 -2.0 3.0 4.0))
                 ;;=> 14.0
                 (dist-abs [9 8 7 6 5 4 3 2 1] [9 8 7 6 5 5 5 5 5])
                -;;=> 10.0

                dist-ang

                (dist-ang v1 v2)

                Angular distance

                +;;=> 10.0

                dist-ang

                (dist-ang v1 v2)

                Angular distance

                Examples

                Usage

                (dist-ang (vec4 1.0 2.0 -1.0 -2.0) (vec4 1.0 -2.0 3.0 4.0))
                 ;;=> 0.7996068408289091
                 (dist-ang [9 8 7 6 5 4 3 2 1] [9 8 7 6 5 5 5 5 5])
                -;;=> 0.09160164480902667

                dist-canberra

                (dist-canberra v1 v2)

                Canberra distance

                +;;=> 0.09160164480902667

                dist-canberra

                (dist-canberra v1 v2)

                Canberra distance

                Examples

                Usage

                (dist-canberra (vec4 1.0 2.0 -1.0 -2.0) (vec4 1.0 -2.0 3.0 4.0))
                 ;;=> 3.0
                 (dist-canberra [9 8 7 6 5 4 3 2 1] [9 8 7 6 5 5 5 5 5])
                -;;=> 1.4563492063492063

                dist-cheb

                (dist-cheb v1 v2)

                Chebyshev distance between 2d vectors

                +;;=> 1.4563492063492063

                dist-cheb

                (dist-cheb v1 v2)

                Chebyshev distance between 2d vectors

                Examples

                Usage

                (dist-cheb (vec4 1.0 2.0 -1.0 -2.0) (vec4 1.0 -2.0 3.0 4.0))
                 ;;=> 6.0
                 (dist-cheb [9 8 7 6 5 4 3 2 1] [9 8 7 6 5 5 5 5 5])
                -;;=> 4.0

                dist-discrete

                (dist-discrete v1 v2)

                Discrete distance between 2d vectors

                +;;=> 4.0

                dist-discrete

                (dist-discrete v1 v2)

                Discrete distance between 2d vectors

                Examples

                Usage

                (dist-discrete (vec4 1.0 2.0 -1.0 -2.0) (vec4 1.0 -2.0 3.0 4.0))
                 ;;=> 3.0
                 (dist-discrete [9 8 7 6 5 4 3 2 1] [9 8 7 6 5 5 5 5 5])
                -;;=> 4.0

                dist-emd

                (dist-emd v1 v2)

                Earth Mover’s Distance

                +;;=> 4.0

                dist-emd

                (dist-emd v1 v2)

                Earth Mover’s Distance

                Examples

                Usage

                (dist-emd (vec4 1.0 2.0 -1.0 -2.0) (vec4 1.0 -2.0 3.0 4.0))
                 ;;=> 4.0
                 (dist-emd [9 8 7 6 5 4 3 2 1] [9 8 7 6 5 5 5 5 5])
                -;;=> 10.0

                dist-sq

                (dist-sq v1 v2)

                Squared Euclidean distance between vectors

                +;;=> 10.0

                dist-sq

                (dist-sq v1 v2)

                Squared Euclidean distance between vectors

                Examples

                Usage

                (dist-sq (vec4 1.0 2.0 -1.0 -2.0) (vec4 1.0 -2.0 3.0 4.0))
                 ;;=> 68.0
                 (dist-sq [9 8 7 6 5 4 3 2 1] [9 8 7 6 5 5 5 5 5])
                -;;=> 30.0

                distances

                Examples

                List of distances

                +;;=> 30.0

                distances

                Examples

                List of distances

                (sort (keys distances))
                -;;=> (:abs :angular :canberra :cheb :discrete :emd :euclid :euclid-sq)

                div

                (div v1 v)(div v1)

                Vector division or reciprocal.

                +;;=> (:abs :angular :canberra :cheb :discrete :emd :euclid :euclid-sq)

                div

                (div v1 v)(div v1)

                Vector division or reciprocal.

                Examples

                Usage

                (div [5 4 3 5] 4.0)
                 ;;=> [1.25 1.0 0.75 1.25]

                Applied to vector is reciprocal

                (div [1 2 4 -5])
                -;;=> [1.0 0.5 0.25 -0.2]

                dot

                (dot v1 v2)

                Dot product of two vectors.

                +;;=> [1.0 0.5 0.25 -0.2]

                dot

                (dot v1 v2)

                Dot product of two vectors.

                Examples

                Usage

                (dot (vec4 1 0 0 0) (vec4 -1 0 -1 0))
                -;;=> -1.0

                econstrain

                (econstrain v mn mx)

                Element-wise constrain

                +;;=> -1.0

                econstrain

                (econstrain v mn mx)

                Element-wise constrain

                Examples

                Usage

                (econstrain (vec3 2 0 -2) -1 1)
                -;;=> [1.0 0.0 -1.0]

                ediv

                (ediv v1 v2)

                Element-wise division of two vectors.

                +;;=> [1.0 0.0 -1.0]

                ediv

                (ediv v1 v2)

                Element-wise division of two vectors.

                Examples

                Usage

                (ediv (vec2 1 3) (vec2 2 4))
                -;;=> [0.5 0.75]

                einterpolate

                (einterpolate v1 v2 v)(einterpolate v1 v2 v f)

                Interpolate vector selement-wise, optionally set interpolation fn (default: lerp)

                +;;=> [0.5 0.75]

                einterpolate

                (einterpolate v1 v2 v)(einterpolate v1 v2 v f)

                Interpolate vector selement-wise, optionally set interpolation fn (default: lerp)

                Examples

                Usage

                (einterpolate (vec2 -1 -1) (vec2 1 1) (vec2 0.25 0.75))
                 ;;=> [-0.5 0.5]
                @@ -261,57 +263,57 @@ 

                Types

                (vec2 1 1) (vec2 0.25 0.75) m/smooth-interpolation) -;;=> [-0.6875 0.6875]

                emn

                (emn v1 v2)

                Element-wise min from two vectors.

                +;;=> [-0.6875 0.6875]

                emn

                (emn v1 v2)

                Element-wise min from two vectors.

                Examples

                Usage

                (emn [-1 2] [1 -2])
                -;;=> [-1.0 -2.0]

                emult

                (emult v1 v2)

                Element-wise vector multiplication (Hadamard product).

                +;;=> [-1.0 -2.0]

                emult

                (emult v1 v2)

                Element-wise vector multiplication (Hadamard product).

                Examples

                Usage

                (emult (vec3 1 2 3) (vec3 9 9 9))
                -;;=> [9.0 18.0 27.0]

                emx

                (emx v1 v2)

                Element-wise max from two vectors.

                +;;=> [9.0 18.0 27.0]

                emx

                (emx v1 v2)

                Element-wise max from two vectors.

                Examples

                Usage

                (emx [-1 2] [1 -2])
                -;;=> [1.0 2.0]

                exp

                (exp vector)

                Apply exp to vector elements.

                +;;=> [1.0 2.0]

                exp

                (exp vector)

                Apply exp to vector elements.

                Examples

                Usage

                (exp (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [1.6487212707001282 0.22313016014842985 8.16616991256765 1.0]

                expm1

                (expm1 vector)

                Apply expm1 to vector elements.

                +;;=> [1.6487212707001282 0.22313016014842985 8.16616991256765 1.0]

                expm1

                (expm1 vector)

                Apply expm1 to vector elements.

                Examples

                Usage

                (expm1 (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.6487212707001282 -0.7768698398515701 7.16616991256765 0.0]

                faceforward

                (faceforward n v)

                Flip normal n to match the same direction as v.

                +;;=> [0.6487212707001282 -0.7768698398515701 7.16616991256765 0.0]

                faceforward

                (faceforward n v)

                Flip normal n to match the same direction as v.

                Examples

                Usage

                (faceforward (vec2 1.0 1.0) (vec2 -1.0 -3.0))
                 ;;=> [-1.0 -1.0]
                 (faceforward (vec2 1.0 1.0) (vec2 1.0 0.0))
                -;;=> [1.0 1.0]

                floor

                (floor vector)

                Apply floor to vector elements.

                +;;=> [1.0 1.0]

                floor

                (floor vector)

                Apply floor to vector elements.

                Examples

                Usage

                (floor (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.0 -2.0 2.0 0.0]

                fmap

                (fmap v f)

                Apply function to all vector values (like map but returns the same type).

                +;;=> [0.0 -2.0 2.0 0.0]

                fmap

                (fmap v f)

                Apply function to all vector values (like map but returns the same type).

                Examples

                Usage

                (fmap [5 3] (fn [v] (m/sin v)))
                -;;=> [-0.9589242746631386 0.1411200080598671]

                frac

                (frac vector)

                Apply frac to vector elements.

                +;;=> [-0.9589242746631386 0.1411200080598671]

                frac

                (frac vector)

                Apply frac to vector elements.

                Examples

                Usage

                (frac (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.5 0.5 0.10000000000000009 0.0]

                from-polar

                (from-polar v)

                From polar coordinates (2d, 3d only)

                +;;=> [0.5 0.5 0.10000000000000009 0.0]

                from-polar

                (from-polar v)

                From polar coordinates (2d, 3d only)

                Examples

                Usage

                (from-polar (vec2 1.0 (m/radians 90)))
                 ;;=> [6.12323399538461E-17 1.0]
                 (from-polar (vec3 1.0 (m/radians 90) (m/radians 45)))
                -;;=> [0.7071067811865476 0.7071067811865475 6.12323399538461E-17]

                generate-vec2

                (generate-vec2 f1 f2)(generate-vec2 f)

                Generate Vec2 with fn(s)

                +;;=> [0.7071067811865476 0.7071067811865475 6.12323399538461E-17]

                generate-vec2

                (generate-vec2 f1 f2)(generate-vec2 f)

                Generate Vec2 with fn(s)

                Examples

                Usage

                (generate-vec2 (constantly 2))
                 ;;=> [2.0 2.0]
                 (generate-vec2 rand (constantly 1))
                -;;=> [0.07256179097106774 1.0]

                generate-vec3

                (generate-vec3 f1 f2 f3)(generate-vec3 f)

                Generate Vec3 with fn(s)

                +;;=> [0.47270573541960936 1.0]

                generate-vec3

                (generate-vec3 f1 f2 f3)(generate-vec3 f)

                Generate Vec3 with fn(s)

                Examples

                Usage

                (generate-vec3 rand)
                -;;=> [0.19411383068751242 0.5803200562037911 0.11123856448070413]
                +;;=> [0.43355112657170225 0.7996146342199197 0.8638598435744879]
                 (generate-vec3 rand (constantly 1) (constantly 2))
                -;;=> [0.7239251956474805 1.0 2.0]

                generate-vec4

                (generate-vec4 f1 f2 f3 f4)(generate-vec4 f)

                Generate Vec4 with fn(s)

                +;;=> [0.3323612928213867 1.0 2.0]

                generate-vec4

                (generate-vec4 f1 f2 f3 f4)(generate-vec4 f)

                Generate Vec4 with fn(s)

                Examples

                Usage

                (generate-vec4 rand)
                -;;=> [0.11832876704046924 0.8431673524156665 0.21740956001841527
                -;;=>  0.5263302053065584]
                +;;=> [0.18535306751065117 0.8663829122320332 0.40138340601374456
                +;;=>  0.021421674191622775]
                 (generate-vec4 rand rand (constantly 1) (constantly 2))
                -;;=> [0.26170753019905457 0.6905634281232684 1.0 2.0]

                heading

                (heading v)

                Angle between vector and unit vector [1,0,...]

                +;;=> [0.704209581038395 0.5095570085568898 1.0 2.0]

                heading

                (heading v)

                Angle between vector and unit vector [1,0,...]

                Examples

                Usage

                (m/degrees (heading (vec2 1.0 1.0)))
                 ;;=> 45.0
                @@ -322,12 +324,12 @@ 

                Types

                (heading [1 2 3 4 5 6 7 8 9]) ;;=> 1.5115267439240436 (heading (array-vec [1 2 3 4 5 6 7 8 9])) -;;=> 1.5115267439240436

                interpolate

                (interpolate v1 v2 t)(interpolate v1 v2 t f)

                Interpolate vectors, optionally set interpolation fn (default: lerp)

                +;;=> 1.5115267439240436

                interpolate

                (interpolate v1 v2 t)(interpolate v1 v2 t f)

                Interpolate vectors, optionally set interpolation fn (default: lerp)

                Examples

                Usage

                (interpolate (vec2 -1 -1) (vec2 1 1) 0.25)
                 ;;=> [-0.5 -0.5]
                 (interpolate (vec2 -1 -1) (vec2 1 1) 0.25 m/smooth-interpolation)
                -;;=> [-0.6875 -0.6875]

                is-near-zero?

                (is-near-zero? v)(is-near-zero? v tol)

                Is vector almost zero? (all absolute values of elements are less than tol tolerance or 1.0e-6)

                +;;=> [-0.6875 -0.6875]

                is-near-zero?

                (is-near-zero? v)(is-near-zero? v tol)

                Is vector almost zero? (all absolute values of elements are less than tol tolerance or 1.0e-6)

                Examples

                Usage

                (is-near-zero? [0 1.0E-7])
                 ;;=> true
                @@ -336,50 +338,51 @@ 

                Types

                (is-near-zero? [0 1.0E-6] 1.0E-4) ;;=> true -;; Test: ok.

                is-zero?

                (is-zero? v)

                Is vector zero?

                +;; Test: ok.

                is-zero?

                (is-zero? v)

                Is vector zero?

                Examples

                Usage

                (is-zero? [0 1.0E-7])
                 ;;=> false
                 (is-zero? [0 0.0])
                -;;=> true

                jinc

                (jinc vector)

                Apply jinc to vector elements.

                -

                limit

                (limit v len)

                Limit length of the vector by given value

                +;;=> true

                jinc

                (jinc vector)

                Apply jinc to vector elements.

                +

                lerp

                (lerp v1 v2 t)

                Linear interpolation of vectors

                +

                limit

                (limit v len)

                Limit length of the vector by given value

                Examples

                Usage

                (limit (vec3 1.0 1.0 1.0) 1.0)
                 ;;=> [0.5773502691896258 0.5773502691896258 0.5773502691896258]
                 (limit (vec3 1.0 1.0 1.0) 2.0)
                -;;=> [1.0 1.0 1.0]

                ln

                (ln vector)

                Apply ln to vector elements.

                +;;=> [1.0 1.0 1.0]

                ln

                (ln vector)

                Apply ln to vector elements.

                Examples

                Usage

                (ln (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [-0.6931471805599453 ##NaN 0.7419373447293773 ##-Inf]

                log

                (log vector)

                Apply log to vector elements.

                +;;=> [-0.6931471805599453 ##NaN 0.7419373447293773 ##-Inf]

                log

                (log vector)

                Apply log to vector elements.

                Examples

                Usage

                (log (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [-0.6931471805599453 ##NaN 0.7419373447293773 ##-Inf]

                log10

                (log10 vector)

                Apply log10 to vector elements.

                +;;=> [-0.6931471805599453 ##NaN 0.7419373447293773 ##-Inf]

                log10

                (log10 vector)

                Apply log10 to vector elements.

                Examples

                Usage

                (log10 (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [-0.3010299956639812 ##NaN 0.3222192947339193 ##-Inf]

                log1mexp

                (log1mexp vector)

                Apply log1mexp to vector elements.

                -

                log1p

                (log1p vector)

                Apply log1p to vector elements.

                +;;=> [-0.3010299956639812 ##NaN 0.3222192947339193 ##-Inf]

                log1mexp

                (log1mexp vector)

                Apply log1mexp to vector elements.

                +

                log1p

                (log1p vector)

                Apply log1p to vector elements.

                Examples

                Usage

                (log1p (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.4054651081081644 ##NaN 1.1314021114911006 0.0]

                log1pexp

                (log1pexp vector)

                Apply log1pexp to vector elements.

                -

                log1pmx

                (log1pmx vector)

                Apply log1pmx to vector elements.

                -

                log1psq

                (log1psq vector)

                Apply log1psq to vector elements.

                -

                log2

                (log2 vector)

                Apply log2 to vector elements.

                +;;=> [0.4054651081081644 ##NaN 1.1314021114911006 0.0]

                log1pexp

                (log1pexp vector)

                Apply log1pexp to vector elements.

                +

                log1pmx

                (log1pmx vector)

                Apply log1pmx to vector elements.

                +

                log1psq

                (log1psq vector)

                Apply log1psq to vector elements.

                +

                log2

                (log2 vector)

                Apply log2 to vector elements.

                Examples

                Usage

                (log2 (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [-1.0 ##NaN 1.070389327891398 ##-Inf]

                logexpm1

                (logexpm1 vector)

                Apply logexpm1 to vector elements.

                -

                logit

                (logit vector)

                Apply logit to vector elements.

                -

                logmeanexp

                (logmeanexp v)

                logmxp1

                (logmxp1 vector)

                Apply logmxp1 to vector elements.

                -

                logsoftmax

                (logsoftmax v)

                logsumexp

                (logsumexp v)

                mag

                (mag v)

                Length of the vector.

                +;;=> [-1.0 ##NaN 1.070389327891398 ##-Inf]

                logexpm1

                (logexpm1 vector)

                Apply logexpm1 to vector elements.

                +

                logit

                (logit vector)

                Apply logit to vector elements.

                +

                logmeanexp

                (logmeanexp v)

                logmxp1

                (logmxp1 vector)

                Apply logmxp1 to vector elements.

                +

                logsoftmax

                (logsoftmax v)

                logsumexp

                (logsumexp v)

                mag

                (mag v)

                Length of the vector.

                Examples

                Length of the vector

                (mag (vec2 1 1))
                 ;;=> 1.4142135623730951
                 
                -;; Test: ok.

                magsq

                (magsq v)

                Length of the vector squared.

                +;; Test: ok.

                magsq

                (magsq v)

                Length of the vector squared.

                Examples

                Length of the vector, squared

                (magsq [1 2 1 2])
                 ;;=> 10.0
                 
                -;; Test: ok.

                make-vector

                (make-vector dims xs)(make-vector dims)

                Returns fixed size vector for given number of dimensions.

                +;; Test: ok.

                make-vector

                (make-vector dims xs)(make-vector dims)

                Returns fixed size vector for given number of dimensions.

                Proper type is used.

                Examples

                Usage

                (make-vector 2)
                @@ -399,51 +402,52 @@ 

                Types

                (make-vector 6 (cycle [1 2 3])) ;;=> [1.0 2.0 3.0 1.0 2.0 3.0] (type (make-vector 6)) -;;=> class fastmath.vector.ArrayVec

                maxdim

                (maxdim v)

                Index of maximum value.

                +;;=> class fastmath.vector.ArrayVec

                maxdim

                (maxdim v)

                Index of maximum value.

                Examples

                Usage

                (let [v (vec (repeatedly 100 (fn [] (- (int (rand-int 200)) 100))))
                       mdim (maxdim v)]
                   [mdim (v mdim)])
                -;;=> [60 99]
                +;;=> [80 99]
                 (maxdim (vec3 1 2 3))
                -;;=> 2

                mindim

                (mindim v)

                Index of minimum value.

                +;;=> 2

                mindim

                (mindim v)

                Index of minimum value.

                Examples

                Usage

                (let [v (vec (repeatedly 100 (fn [] (- (int (rand-int 200)) 100))))
                       mdim (mindim v)]
                   [mdim (v mdim)])
                -;;=> [11 -99]
                +;;=> [93 -100]
                 (mindim (vec3 1 2 3))
                -;;=> 0

                mn

                (mn v)

                Minimum value of vector elements

                +;;=> 0

                mn

                (mn v)

                Minimum value of vector elements

                Examples

                Usage

                (mn (vec4 -1 -2 3 4))
                -;;=> -2.0

                mult

                (mult v x)

                Multiply vector by number x.

                +;;=> -2.0

                mult

                (mult v x)

                Multiply vector by number x.

                Examples

                Usage

                (mult (vec4 5 4 3 5) 4.0)
                -;;=> [20.0 16.0 12.0 20.0]

                mx

                (mx v)

                Maximum value of vector elements

                +;;=> [20.0 16.0 12.0 20.0]

                mx

                (mx v)

                Maximum value of vector elements

                Examples

                Usage

                (mx (vec4 -1 -2 3 4))
                -;;=> 4.0

                nonzero-count

                (nonzero-count v)

                Count non zero velues in vector

                +;;=> 4.0

                nonzero-count

                (nonzero-count v)

                Count non zero velues in vector

                Examples

                Usage

                (nonzero-count [1 2 3 -1 0 2 0 0])
                -;;=> 5

                normalize

                (normalize v)

                Normalize vector (set length = 1.0)

                +;;=> 5

                normalize

                (normalize v)

                Normalize vector (set length = 1.0)

                Examples

                Usage

                (normalize (vec2 1.0 -1.0))
                -;;=> [0.7071067811865475 -0.7071067811865475]

                permute

                (permute v idxs)

                Permute vector elements with given indices.

                +;;=> [0.7071067811865475 -0.7071067811865475]

                permute

                (permute v idxs)

                Permute vector elements with given indices.

                Examples

                Usage

                (permute (vec4 1 2 3 4) (vec4 0 3 2 1))
                -;;=> [1.0 4.0 3.0 2.0]

                perpendicular

                (perpendicular v)(perpendicular v1 v2)

                Perpendicular vector. Only for Vec2 and Vec3 types.

                +;;=> [1.0 4.0 3.0 2.0]

                perpendicular

                (perpendicular v)(perpendicular v1 v2)

                Perpendicular vector. Only for Vec2 and Vec3 types.

                Examples

                Usage

                (perpendicular (vec2 -4 0))
                 ;;=> [-0.0 -1.0]
                 (perpendicular (vec3 1.0 0.0 0.0) (vec3 0.0 -1.0 0.0))
                -;;=> [0.0 0.0 -1.0]

                project

                (project v1 v2)

                Project v1 onto v2

                -

                radians

                (radians vector)

                Apply radians to vector elements.

                +;;=> [0.0 0.0 -1.0]

                prod

                (prod v)

                Product of elements

                +

                project

                (project v1 v2)

                Project v1 onto v2

                +

                radians

                (radians vector)

                Apply radians to vector elements.

                Examples

                Usage

                (radians (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.008726646259971648 -0.026179938779914945 0.03665191429188092 0.0]

                reciprocal

                (reciprocal v)

                Reciprocal of elements.

                +;;=> [0.008726646259971648 -0.026179938779914945 0.03665191429188092 0.0]

                reciprocal

                (reciprocal v)

                Reciprocal of elements.

                Examples

                Usage

                (reciprocal (vec3 1 2 5))
                -;;=> [1.0 0.5 0.2]

                relative-angle-between

                (relative-angle-between v1 v2)

                Angle between two vectors relative to each other.

                +;;=> [1.0 0.5 0.2]

                relative-angle-between

                (relative-angle-between v1 v2)

                Angle between two vectors relative to each other.

                See also angle-between.

                Examples

                Usage

                (m/degrees (relative-angle-between (vec3 1.0 0.0 0.0)
                @@ -451,92 +455,92 @@ 

                Types

                ;;=> 90.0 (m/degrees (relative-angle-between (vec (repeatedly 50 rand)) (vec (repeatedly 50 rand)))) -;;=> 12.97021749559487

                rint

                (rint vector)

                Apply rint to vector elements.

                +;;=> 7.038199609205948

                rint

                (rint vector)

                Apply rint to vector elements.

                Examples

                Usage

                (rint (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.0 -2.0 2.0 0.0]

                rotate

                (rotate v angle)(rotate v angle-x angle-y angle-z)

                Rotate vector. Only for Vec2 and Vec3 types.

                +;;=> [0.0 -2.0 2.0 0.0]

                rotate

                (rotate v angle)(rotate v angle-x angle-y angle-z)

                Rotate vector. Only for Vec2 and Vec3 types.

                Examples

                Usage

                (rotate (vec2 1 2) (m/radians 90))
                 ;;=> [-2.0 1.0000000000000002]
                 (rotate (vec3 1 2 3) (m/radians 90) 0 0)
                -;;=> [1.0 -3.0 2.0]

                round

                (round vector)

                Apply round to vector elements.

                +;;=> [1.0 -3.0 2.0]

                round

                (round vector)

                Apply round to vector elements.

                Examples

                Usage

                (round (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [1.0 -1.0 2.0 0.0]

                safe-sqrt

                (safe-sqrt vector)

                Apply safe-sqrt to vector elements.

                +;;=> [1.0 -1.0 2.0 0.0]

                safe-sqrt

                (safe-sqrt vector)

                Apply safe-sqrt to vector elements.

                Examples

                Usage

                (safe-sqrt (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.7071067811865476 0.0 1.449137674618944 0.0]

                sec

                (sec vector)

                Apply sec to vector elements.

                +;;=> [0.7071067811865476 0.0 1.449137674618944 0.0]

                sec

                (sec vector)

                Apply sec to vector elements.

                Examples

                Usage

                (sec (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [1.139493927324549 14.136832902969918 -1.9808016559672244 1.0]

                sech

                (sech vector)

                Apply sech to vector elements.

                +;;=> [1.139493927324549 14.136832902969918 -1.9808016559672244 1.0]

                sech

                (sech vector)

                Apply sech to vector elements.

                Examples

                Usage

                (sech (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.886818883970074 0.4250960349422804 0.2412945062018547 1.0]

                seq->vec2

                (seq->vec2 xs)

                Any seq to Vec2

                +;;=> [0.886818883970074 0.4250960349422804 0.2412945062018547 1.0]

                seq->vec2

                (seq->vec2 xs)

                Any seq to Vec2

                Examples

                Usage

                (seq->vec2 [11 22 33 44 55])
                -;;=> [11.0 22.0]

                seq->vec3

                (seq->vec3 xs)

                Any seq to Vec3

                +;;=> [11.0 22.0]

                seq->vec3

                (seq->vec3 xs)

                Any seq to Vec3

                Examples

                Usage

                (seq->vec3 (lazy-seq (quote (1 2))))
                -;;=> [1.0 2.0 0.0]

                seq->vec4

                (seq->vec4 xs)

                Any seq to Vec4

                +;;=> [1.0 2.0 0.0]

                seq->vec4

                (seq->vec4 xs)

                Any seq to Vec4

                Examples

                Usage

                (seq->vec4 (double-array [11 22 33 44 55]))
                -;;=> [11.0 22.0 33.0 44.0]

                set-mag

                (set-mag v len)

                Set length of the vector

                +;;=> [11.0 22.0 33.0 44.0]

                set-mag

                (set-mag v len)

                Set length of the vector

                Examples

                Usage

                (set-mag (vec2 0.22 0.22) (m/sqrt 2.0))
                 ;;=> [1.0000000000000002 1.0000000000000002]
                 (set-mag (vec2 1.0 1.0) 0.0)
                -;;=> [0.0 0.0]

                sfrac

                (sfrac vector)

                Apply sfrac to vector elements.

                +;;=> [0.0 0.0]

                sfrac

                (sfrac vector)

                Apply sfrac to vector elements.

                Examples

                Usage

                (sfrac (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.5 -0.5 0.10000000000000009 0.0]

                sgn

                (sgn vector)

                Apply sgn to vector elements.

                +;;=> [0.5 -0.5 0.10000000000000009 0.0]

                sgn

                (sgn vector)

                Apply sgn to vector elements.

                Examples

                Usage

                (sgn (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [1.0 -1.0 1.0 1.0]

                shift

                (shift v)(shift v x)

                Add value to every vector element.

                -

                sigmoid

                (sigmoid vector)

                Apply sigmoid to vector elements.

                +;;=> [1.0 -1.0 1.0 1.0]

                shift

                (shift v)(shift v x)

                Add value to every vector element.

                +

                sigmoid

                (sigmoid vector)

                Apply sigmoid to vector elements.

                Examples

                Usage

                (sigmoid (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.6224593312018546 0.18242552380635632 0.8909031788043871 0.5]

                signum

                (signum vector)

                Apply signum to vector elements.

                +;;=> [0.6224593312018546 0.18242552380635632 0.8909031788043871 0.5]

                signum

                (signum vector)

                Apply signum to vector elements.

                Examples

                Usage

                (signum (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [1.0 -1.0 1.0 0.0]

                sim-cos

                (sim-cos v1 v2)

                Cosine similarity

                +;;=> [1.0 -1.0 1.0 0.0]

                sim-cos

                (sim-cos v1 v2)

                Cosine similarity

                Examples

                Usage

                (sim-cos (vec4 1.0 2.0 -1.0 -2.0) (vec4 1.0 -2.0 3.0 4.0))
                 ;;=> -0.808290376865476
                 (sim-cos [9 8 7 6 5 4 3 2 1] [9 8 7 6 5 5 5 5 5])
                -;;=> 0.9588777312999299

                sin

                (sin vector)

                Apply sin to vector elements.

                +;;=> 0.9588777312999299

                sin

                (sin vector)

                Apply sin to vector elements.

                Examples

                Usage

                (sin (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.47942553860420295 -0.9974949866040544 0.8632093666488738 0.0]

                sinc

                (sinc vector)

                Apply sinc to vector elements.

                +;;=> [0.47942553860420295 -0.9974949866040544 0.8632093666488738 0.0]

                sinc

                (sinc vector)

                Apply sinc to vector elements.

                Examples

                Usage

                (sinc (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.6366197723675814 -0.2122065907891938 0.04683960205159357 1.0]

                sinh

                (sinh vector)

                Apply sinh to vector elements.

                +;;=> [0.6366197723675814 -0.2122065907891938 0.04683960205159357 1.0]

                sinh

                (sinh vector)

                Apply sinh to vector elements.

                Examples

                Usage

                (sinh (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.5210953054937474 -2.1292794550948178 4.021856742157334 0.0]

                softmax

                (softmax v)

                sq

                (sq vector)

                Apply sq to vector elements.

                +;;=> [0.5210953054937474 -2.1292794550948178 4.021856742157334 0.0]

                softmax

                (softmax v)

                sq

                (sq vector)

                Apply sq to vector elements.

                Examples

                Usage

                (sq (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.25 2.25 4.41 0.0]

                sqrt

                (sqrt vector)

                Apply sqrt to vector elements.

                +;;=> [0.25 2.25 4.41 0.0]

                sqrt

                (sqrt vector)

                Apply sqrt to vector elements.

                Examples

                Usage

                (sqrt (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.7071067811865476 ##NaN 1.449137674618944 0.0]

                sub

                (sub v)(sub v1 v2)

                Subtraction of two vectors.

                +;;=> [0.7071067811865476 ##NaN 1.449137674618944 0.0]

                sub

                (sub v)(sub v1 v2)

                Subtraction of two vectors.

                Examples

                Usage

                (sub (vec2 1 2) (vec2 -1 -2))
                -;;=> [2.0 4.0]

                sum

                (sum v)

                Sum of elements

                +;;=> [2.0 4.0]

                sum

                (sum v)

                Sum of elements

                Examples

                Usage

                (sum (vec (range 1000)))
                -;;=> 499500.0

                tan

                (tan vector)

                Apply tan to vector elements.

                +;;=> 499500.0

                tan

                (tan vector)

                Apply tan to vector elements.

                Examples

                Usage

                (tan (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.5463024898437905 -14.101419947171719 -1.7098465429045075 0.0]

                tanh

                (tanh vector)

                Apply tanh to vector elements.

                +;;=> [0.5463024898437905 -14.101419947171719 -1.7098465429045075 0.0]

                tanh

                (tanh vector)

                Apply tanh to vector elements.

                Examples

                Usage

                (tanh (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.46211715726000974 -0.9051482536448664 0.9704519366134539 0.0]

                to-polar

                (to-polar v)

                To polar coordinates (2d, 3d only), first element is length, the rest angle.

                +;;=> [0.46211715726000974 -0.9051482536448664 0.9704519366134539 0.0]

                to-polar

                (to-polar v)

                To polar coordinates (2d, 3d only), first element is length, the rest angle.

                Examples

                Usage

                (to-polar (vec2 1.0 1.0))
                 ;;=> [1.4142135623730951 0.7853981633974483]
                 (to-polar (vec3 1.0 0.0 1.0))
                -;;=> [1.4142135623730951 0.7853981633974483 0.0]

                to-vec

                deprecated in v1.5.0

                Same as vec->Vec. Deprecated.

                -

                transform

                (transform v o vx vy)(transform v o vx vy vz)

                Transform vector; map point to coordinate system defined by origin, vx and vy (as bases), Only for Vec2 and Vec3 types.

                +;;=> [1.4142135623730951 0.7853981633974483 0.0]

                to-vec

                deprecated in v1.5.0

                Same as vec->Vec. Deprecated.

                +

                transform

                (transform v o vx vy)(transform v o vx vy vz)

                Transform vector; map point to coordinate system defined by origin, vx and vy (as bases), Only for Vec2 and Vec3 types.

                Examples

                Usage

                (transform (vec2 1 1) (vec2 -1 -1) (vec2 1.0 0.0) (vec2 0.0 1.0))
                 ;;=> [0.0 0.0]
                @@ -545,12 +549,12 @@ 

                Types

                (vec3 1.0 0.0 1.0) (vec3 0.0 1.0 0.0) (vec3 0.0 1.0 1.0)) -;;=> [0.0 1.0 2.0]

                triple-product

                (triple-product a b c)

                a o (b x c)

                -

                trunc

                (trunc vector)

                Apply trunc to vector elements.

                +;;=> [0.0 1.0 2.0]

                triple-product

                (triple-product a b c)

                a o (b x c)

                +

                trunc

                (trunc vector)

                Apply trunc to vector elements.

                Examples

                Usage

                (trunc (fastmath.vector/vec4 0.5 -1.5 2.1 0.0))
                -;;=> [0.0 -1.0 2.0 0.0]

                vec->RealVector

                (vec->RealVector v)

                Convert to Apache Commons Math RealVector

                -

                vec->Vec

                (vec->Vec v)

                Convert to Clojure primitive vector Vec.

                +;;=> [0.0 -1.0 2.0 0.0]

                vec->RealVector

                (vec->RealVector v)

                Convert to Apache Commons Math RealVector

                +

                vec->Vec

                (vec->Vec v)

                Convert to Clojure primitive vector Vec.

                Examples

                Check types

                (type (vec->Vec [1 2 3]))
                 ;;=> class clojure.core.Vec
                @@ -561,7 +565,7 @@ 

                Types

                (type (vec->Vec (vec4 1 2 3 4))) ;;=> class clojure.core.Vec (type (vec->Vec (array-vec 1))) -;;=> class clojure.core.Vec

                vec2

                (vec2 x y)(vec2)

                Make 2d vector.

                +;;=> class clojure.core.Vec

                vec2

                (vec2 x y)(vec2)

                Make 2d vector.

                Examples

                Usage

                (vec2 0.5 -0.5)
                 ;;=> [0.5 -0.5]
                @@ -571,7 +575,7 @@ 

                Types

                ;;=> 6.5

                As function

                [((vec2 11 22) 0) ((vec2 11 22) 1)]
                 ;;=> [11.0 22.0]

                As sequence

                -
                (map (fn* [p1__34355#] (* 2.0 p1__34355#)) (vec2 1 2))
                +
                (map (fn* [p1__34447#] (* 2.0 p1__34447#)) (vec2 1 2))
                 ;;=> (2.0 4.0)
                 (reduce clojure.core/+ (vec2 6 4))
                 ;;=> 10.0
                @@ -588,14 +592,14 @@ 

                Types

                (filter clojure.core/neg? (vec2 -1 2)) ;;=> (-1.0)

                Count

                (count (vec2 4 3))
                -;;=> 2

                vec3

                (vec3 x y z)(vec3 v z)(vec3)

                Make Vec2 vector

                +;;=> 2

                vec3

                (vec3 x y z)(vec3 v z)(vec3)

                Make Vec2 vector

                Examples

                Usage

                (vec3)
                 ;;=> [0.0 0.0 0.0]
                 (vec3 0.5 -0.5 1.0)
                 ;;=> [0.5 -0.5 1.0]
                 (let [v (vec2 1 2)] (vec3 v -1.0))
                -;;=> [1.0 2.0 -1.0]

                vec4

                (vec4 x y z w)(vec4 v w)(vec4 v z w)(vec4)

                Make Vec4 vector

                +;;=> [1.0 2.0 -1.0]

                vec4

                (vec4 x y z w)(vec4 v w)(vec4 v z w)(vec4)

                Make Vec4 vector

                Examples

                Usage

                (vec4)
                 ;;=> [0.0 0.0 0.0 0.0]
                @@ -604,8 +608,8 @@ 

                Types

                (let [v (vec2 1 2)] (vec4 v -1.0 0.1)) ;;=> [1.0 2.0 -1.0 0.1] (let [v (vec3 0 1 2)] (vec4 v 0.1)) -;;=> [0.0 1.0 2.0 0.1]

                xlogx

                (xlogx vector)

                Apply xlogx to vector elements.

                -

                zero-count

                (zero-count v)

                Count zeros in vector

                +;;=> [0.0 1.0 2.0 0.1]

                xlogx

                (xlogx vector)

                Apply xlogx to vector elements.

                +

                zero-count

                (zero-count v)

                Count zeros in vector

                Examples

                Usage

                (zero-count [1 2 3 -1 0 2 0 0])
                -;;=> 3
                \ No newline at end of file +;;=> 3
                \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index f6312bfa..da243e64 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,9 +1,9 @@ -Fastmath 2.2.1-SNAPSHOT

                Fastmath 2.2.1-SNAPSHOT

                Released under the MIT Licence

                Fast and primitive math library.

                Installation

                To install, add the following dependency to your project or build file:

                [generateme/fastmath "2.2.1-SNAPSHOT"]

                Namespaces

                fastmath.clustering

                Clustering.

                +Fastmath 2.2.2-SNAPSHOT

                Fastmath 2.2.2-SNAPSHOT

                Released under the MIT Licence

                Fast and primitive math library.

                Installation

                To install, add the following dependency to your project or build file:

                [generateme/fastmath "2.2.2-SNAPSHOT"]

                Namespaces

                fastmath.core

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

                -

                Categories

                  Other vars: * + - / < << <= == > >= >> >>> Ci I0 Si abs acos acosh acot acoth acovercos acoversin acrd acsc acsch aexcsc aexsec ahacovercos ahacoversin ahavercos ahaversin approx approx-eq approx= asec asech asin asinh atan atan2 atanh avercos aversin bessel-j between-? between? bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-test bit-xor bits->double bool-and bool-not bool-or bool-xor cb cbrt ceil cexpexp cloglog cnorm co-intervals combinations constrain copy-sign cos cos-interpolation cosh cot coth covercos coversin crd csc csch cut dec degrees delta-eq delta= difference-of-products digamma dist double-array->seq double-bits double-double-array->seq double-high-bits double-low-bits eq erf erfc evalpoly even? excsc exp expm1 exsec factorial factorial20 fast* fast+ fast- fast-identity fast-max fast-min floor fma fpow frac gamma gcd group-by-intervals hacovercos hacoversin havercos haversin haversine haversine-dist high-2-exp high-exp hypot hypot-sqrt iabs inc inf? inv-erf inv-erfc inv-gamma-1pm1 invalid-double? itrunc jinc lcm lerp ln log log-I0 log-beta log-combinations log-factorial log-gamma log-gamma-1p log10 log1mexp log1p log1pexp log1pmx log1psq log2 log2mexp logaddexp logb logcosh logexpm1 logistic logit logmxp1 logsubexp logsumexp low-2-exp low-exp make-norm makepoly max mevalpoly min minkowski mlerp mnorm mod muladd nan? neg-inf? neg? negmuladd next-double norm not-neg? not-pos? not== odd? one? order pos-inf? pos? pow pow2 pow3 prev-double qceil qcos qdist qexp qfloor qlog qpow qround qsin qsqrt quad-interpolation quot radians rank rank1 regularized-beta regularized-gamma-p regularized-gamma-q rem remainder rint round round-even round-up-pow2 rqsqrt safe-sqrt sample sec sech seq->double-array seq->double-double-array sfrac sgn sigmoid signum sin sinc sinh slice-range smooth-interpolation smoothstep sq sqrt sum-of-products tan tanh trigamma trunc unsigned-bit-shift-right unuse-primitive-operators use-primitive-operators valid-double? vercos versin wrap xexpx xexpy xlog1py xlogx xlogy zero?

                  fastmath.core

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

                  +

                  Categories

                    Other vars: * + - / < << <= == > >= >> >>> Ci I0 Si abs acos acosh acot acoth acovercos acoversin acrd acsc acsch aexcsc aexsec ahacovercos ahacoversin ahavercos ahaversin approx approx-eq approx= asec asech asin asinh atan atan2 atanh avercos aversin bessel-j between-? between? bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-test bit-xor bits->double bool-and bool-not bool-or bool-xor cb cbrt ceil cexpexp cloglog cnorm co-intervals combinations constrain copy-sign cos cos-interpolation cosh cot coth covercos coversin crd csc csch cut dec degrees delta-eq delta= difference-of-products digamma dist double-array->seq double-bits double-double-array->seq double-exponent double-high-bits double-low-bits double-significand eq erf erfc evalpoly even? excsc exp expm1 exsec factorial factorial20 fast* fast+ fast- fast-identity fast-max fast-min floor fma fpow frac gamma gcd group-by-intervals hacovercos hacoversin havercos haversin haversine haversine-dist high-2-exp high-exp hypot hypot-sqrt iabs inc inf? inv-erf inv-erfc inv-gamma-1pm1 invalid-double? itrunc jinc lcm lerp ln log log-I0 log-beta log-combinations log-factorial log-gamma log-gamma-1p log10 log1mexp log1p log1pexp log1pmx log1psq log2 log2int log2mexp logaddexp logb logcosh logexpm1 logistic logit logmxp1 logsubexp logsumexp low-2-exp low-exp make-norm makepoly max mevalpoly min minkowski mlerp mnorm mod muladd nan? neg-inf? neg? negative-zero? negmuladd next-double norm not-neg? not-pos? not== odd? one? order pos-inf? pos? pow pow2 pow3 prev-double qceil qcos qdist qexp qfloor qlog qpow qround qsin qsqrt quad-interpolation quot radians rank rank1 regularized-beta regularized-gamma-p regularized-gamma-q rem remainder rint round round-even round-up-pow2 rqsqrt safe-sqrt sample sec sech seq->double-array seq->double-double-array sfrac sgn sigmoid signum sin sinc sinh slice-range smooth-interpolation smoothstep sq sqrt sum-of-products tan tanh trigamma trunc ulp unsigned-bit-shift-right unuse-primitive-operators use-primitive-operators valid-double? vercos versin wrap xexpx xexpy xlog1py xlogx xlogy zero?

                    fastmath.curves

                    Collection of parametric curves

                    Categories

                      Other vars: add curve curves-list mult parametrization

                      fastmath.efloat

                      (re)Implementation of EFloat/Interval from pbrt-v3/pbrt-v4.

                      @@ -13,12 +13,12 @@

                      fastmath.solver

                      Categories

                        Other vars: find-root

                        fastmath.solver

                        Categories

                          Other vars: find-root quadratic

                          fastmath.stats

                          Statistics functions.

                          Categories

                            Other vars: ->confusion-matrix L0 L1 L2 L2sq LInf acf acf-ci ad-test-one-sample adjacent-values ameasure binary-measures binary-measures-all binomial-ci binomial-ci-methods binomial-test bootstrap bootstrap-ci brown-forsythe-test chisq-test ci cliffs-delta coefficient-matrix cohens-d cohens-d-corrected cohens-f cohens-f2 cohens-kappa cohens-q cohens-u2 cohens-u3 cohens-w contingency-2x2-measures contingency-2x2-measures-all contingency-table contingency-table->marginals correlation correlation-matrix count= covariance covariance-matrix cramers-c cramers-v cramers-v-corrected cressie-read-test demean epsilon-sq estimate-bins estimation-strategies-list eta-sq extent f-test fligner-killeen-test freeman-tukey-test geomean glass-delta harmean hedges-g hedges-g* hedges-g-corrected histogram hpdi-extent inner-fence-extent iqr jensen-shannon-divergence kendall-correlation kruskal-test ks-test-one-sample ks-test-two-samples kullback-leibler-divergence kurtosis levene-test mad mad-extent mae mape maximum mcc me mean mean-absolute-deviation means-ratio means-ratio-corrected median median-3 median-absolute-deviation minimum minimum-discrimination-information-test mode modes moment mse multinomial-likelihood-ratio-test neyman-modified-chisq-test omega-sq one-way-anova-test outer-fence-extent outliers p-overlap p-value pacf pacf-ci pearson-correlation pearson-r percentile percentile-bc-extent percentile-bca-extent percentile-extent percentiles pi pi-extent pooled-stddev pooled-variance population-stddev population-variance power-divergence-test powmean psnr quantile quantile-extent quantiles r2 r2-determination rank-epsilon-sq rank-eta-sq rescale rmse robust-standardize rows->contingency-table rss second-moment sem sem-extent skewness span spearman-correlation standardize stats-map stddev stddev-extent sum t-test-one-sample t-test-two-samples trim tschuprows-t ttest-one-sample ttest-two-samples variance variation weighted-kappa winsor wmean wmedian wmw-odds wquantile wquantiles z-test-one-sample z-test-two-samples

                            \ No newline at end of file +
                            \ No newline at end of file diff --git a/src/fastmath/optimization.clj b/src/fastmath/optimization.clj index d3e63e5f..a2797db1 100644 --- a/src/fastmath/optimization.clj +++ b/src/fastmath/optimization.clj @@ -10,7 +10,9 @@ * Multidirectional simplex * CMAES * Gradient + * L-BFGS-B * Bayesian Optimization (see below) + * Linear optimization All optimizers require bounds. @@ -57,7 +59,9 @@ ## Bayesian Optimization - Bayesian optimizer can be used for optimizing expensive to evaluate black box functions. Refer this [article](http://krasserm.github.io/2018/03/21/bayesian-optimization/) or this [article](https://nextjournal.com/a/LKqpdDdxiggRyHhqDG5FH?token=Ss1Qq3MzHWN8ZyEt9UC1ZZ)" + Bayesian optimizer can be used for optimizing expensive to evaluate black box functions. Refer this [article](http://krasserm.github.io/2018/03/21/bayesian-optimization/) or this [article](https://nextjournal.com/a/LKqpdDdxiggRyHhqDG5FH?token=Ss1Qq3MzHWN8ZyEt9UC1ZZ) + + ## Linear optimization " (:require [fastmath.core :as m] [fastmath.random :as r] [fastmath.vector :as v] @@ -67,6 +71,8 @@ (:import [org.apache.commons.math3.optim.nonlinear.scalar GoalType ObjectiveFunction ObjectiveFunctionGradient] [org.apache.commons.math3.optim.univariate SearchInterval BrentOptimizer UnivariateObjectiveFunction UnivariatePointValuePair] [org.apache.commons.math3.optim BaseOptimizer OptimizationData MaxEval MaxIter SimpleBounds SimpleValueChecker InitialGuess PointValuePair] + [org.apache.commons.math3.optim.linear LinearObjectiveFunction LinearConstraint + Relationship LinearConstraintSet SimplexSolver NonNegativeConstraint PivotSelectionRule] [org.apache.commons.math3.analysis UnivariateFunction MultivariateFunction MultivariateVectorFunction] [org.apache.commons.math3.optim.nonlinear.scalar MultivariateFunctionMappingAdapter] [org.apache.commons.math3.optim.nonlinear.scalar.noderiv BOBYQAOptimizer PowellOptimizer NelderMeadSimplex SimplexOptimizer MultiDirectionalSimplex CMAESOptimizer CMAESOptimizer$PopulationSize CMAESOptimizer$Sigma] @@ -235,15 +241,16 @@ (wrap-multivariate-function f))) (defn- parse-result - [^MultivariateFunctionMappingAdapter mfma res] - (condp instance? res - UnivariatePointValuePair (let [^UnivariatePointValuePair res res] - [(list (.getPoint res)) (.getValue res)]) - PointValuePair (let [^PointValuePair res res] - [(seq (if mfma - (.unboundedToBounded mfma (.getPointRef res)) - (.getPointRef res))) (.getValue res)]) - res)) + ([res] (parse-result nil res)) + ([^MultivariateFunctionMappingAdapter mfma res] + (condp instance? res + UnivariatePointValuePair (let [^UnivariatePointValuePair res res] + [(list (.getPoint res)) (.getValue res)]) + PointValuePair (let [^PointValuePair res res] + [(seq (if mfma + (.unboundedToBounded mfma (.getPointRef res)) + (.getPointRef res))) (.getValue res)]) + res))) (defn- find-dimensions ^long [bounds] @@ -309,6 +316,14 @@ :iterations (.-k obj) :gradient (seq (.m_grad obj))})))))) +(defn- maybe-stats? + [stats? ^BaseOptimizer optimizer res] + (if-not stats? + res + {:result res + :evaluations (.getEvaluations optimizer) + :iterations (.getIterations optimizer)})) + (defn- optimizer [method f {:keys [max-evals max-iters goal bounds stats? population-size bounded? gradient-h] :or {gradient-h 0.0001} @@ -357,15 +372,11 @@ (fn local-optimizer ([] (local-optimizer nil)) - ([init] (let [res (->> (conj base-opt-data (wrap-initial method bounds init mfma)) - (into-array OptimizationData) - (.optimize optimizer) - (parse-result mfma))] - (if-not stats? - res - {:result res - :evaluations (.getEvaluations optimizer) - :iterations (.getIterations optimizer)})))))))) + ([init] (->> (conj base-opt-data (wrap-initial method bounds init mfma)) + (into-array OptimizationData) + (.optimize optimizer) + (parse-result mfma) + (maybe-stats? stats? optimizer)))))))) (defn minimizer "Create optimizer which minimizes function. @@ -374,7 +385,7 @@ [method f config] (optimizer method f (assoc config :goal :minimize))) (defn maximizer - "Create optimizer which maximizer function. + "Create optimizer which maximizes function. Returns function which performs optimization for optionally given initial point." [method f config] (optimizer method f (assoc config :goal :maximize))) @@ -557,7 +568,77 @@ :xs xs :ys ys})))) -;; root finding methods +;; linear optimization + +(defn- constraint-relations + ^Relationship [relation] + (cond + (#{:>= '>= :geq} relation) Relationship/GEQ + (#{:<= '<= :leq} relation) Relationship/LEQ + :else Relationship/EQ)) + +(defn- build-constraint + ^LinearConstraint [[left relation right]] + (let [relationship (constraint-relations relation)] + (if (number? right) + (LinearConstraint. (m/seq->double-array left) relationship (double right)) + (LinearConstraint. (m/seq->double-array (butlast left)) + (double (last left)) + relationship + (m/seq->double-array (butlast right)) + (double (last right)))))) + +(defn linear-optimization + "Solves a linear problem. + + Target is defined as a vector of coefficients and constant as the last value: + `[a1 a2 a3 ... c]` means `f(x1,x2,x3) = a1*x1 + a2*x2 + a3*x3 + ... + c` + + Constraints are defined as a sequence of one of the following triplets: + + * `[a1 a2 a3 ...] R n` - which means `a1*x1+a2*x2+a3*x3+... R n` + * `[a1 a2 a3 ... ca] R [b1 b2 b3 ... cb] - which means `a1*x1+a2*x2+a3*x3+...+ca R b1*x1+b2*x2+b3*x3+...+cb` + where `R` is a relationship and can be one of `<=`, `>=` or `=` as symbol or keyword. Also `:leq`, `:geq` and `:eq` are valid. + + Function returns pair of optimal point and function value. If `stat?` option is set to true, returns also information about number of iterations. + + Possible options: + + * `:goal` - `:minimize` (default) or `:maximize` + * `:rule` - pivot selection rule, `:dantzig` (default) or `:bland` + * `:max-iter` - maximum number of iterations, maximum integer by default + * `:non-negative?` - allow non-negative variables only, default: `false` + * `:epsilon` - convergence value, default: `1.0e-6`: + * `:max-ulps` - floating point comparisons, default: `10` ulp + * `:cut-off` - pivot elements smaller than cut-off are treated as zero, default: `1.0e-10` + + ```clojure + (linear-optimization [-1 4 0] [[-3 1] :<= 6 + [-1 -2] :>= -4 + [0 1] :>= -3]) + ;; => [(9.999999999999995 -3.0) -21.999999999999993] + ```" + ([target constraints] (linear-optimization target constraints {})) + ([target constraints {:keys [goal ^double epsilon ^int max-ulps ^double cut-off + rule non-negative? ^int max-iter stats?] + :or {goal :minimize epsilon 1.0e-6 max-ulps 10 cut-off 1.0e-10 + rule :dantzig non-negative? false max-iter Integer/MAX_VALUE}}] + (let [goal (if (= goal :minimize) GoalType/MINIMIZE GoalType/MAXIMIZE) + rule (if (= rule :dantzig) PivotSelectionRule/DANTZIG PivotSelectionRule/BLAND) + max-iter (MaxIter. max-iter) + non-negative? (NonNegativeConstraint. non-negative?) + target (LinearObjectiveFunction. (m/seq->double-array (butlast target)) + (double (last target))) + constraints (->> constraints + (partition 3) + ^java.util.Collection (map build-constraint) + (LinearConstraintSet.)) + ^BaseOptimizer solver (SimplexSolver. epsilon max-ulps cut-off)] + (->> [goal rule max-iter non-negative? target constraints] + (into-array OptimizationData) + (.optimize solver) + (parse-result nil) + (maybe-stats? stats? solver))))) #_(let [f (fn [^double x ^double y] (inc (- (- (* x x)) (m/sq (dec y))))) diff --git a/test/fastmath/optimization_test.clj b/test/fastmath/optimization_test.clj new file mode 100644 index 00000000..94695700 --- /dev/null +++ b/test/fastmath/optimization_test.clj @@ -0,0 +1,28 @@ +(ns fastmath.optimization-test + (:require [fastmath.optimization :as sut] + [clojure.test :as t] + [fastmath.vector :as v] + [fastmath.core :as m])) + +(t/deftest linear-programming + (t/are [res target constrains opts] (let [[p v] res + [rp rv] (sut/linear-optimization target constrains opts)] + (and (v/delta-eq (vec rp) p) + (m/delta-eq v rv))) + ;; scipy + [[10 -3] -22] [-1 4 0] [[-3 1] :<= 6 + [-1 -2] :>= -4 + [0 1] :>= -3] nil + + ;; http://people.brunel.ac.uk/~mastjjb/jeb/or/morelp.html + [[45.0 6.25] 1.25] [1 1 -50] [[50 24] :leq 2400 + [30 33] :leq 2100 + [1 0] :geq 45 + [0 1] :geq 5] {:goal :maximize} + + ;; transportation problem https://dewwool.com/linear-programming-examples/ + [[0.0 0.0 10.0 30.0 20.0 20.0] 290.0] [5 4 6 3 2 5 0] '[[1 1 1 0 0 0] <= 50 + [0 0 0 1 1 1] <= 70 + [1 0 0 1 0 0] >= 30 + [0 1 0 0 1 0] >= 20 + [0 0 1 0 0 1] >= 30] {:non-negative? true}))