diff --git a/CHANGELOG.md b/CHANGELOG.md index 42245a31..6d432242 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Change Log All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). +## [1.1.2] + +### Added + +* estimators for number of bins in histogram +* kernel-density function + ## [1.1.1] ### Changed diff --git a/README.md b/README.md index 2fa2f86d..16c56d71 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Originally it was a part of generative art/glich [Clojure2d](https://github.com/ ## Installation ```clojure -[generateme/fastmath "1.1.1"] +[generateme/fastmath "1.1.2"] ``` ## Documentation diff --git a/docs/fastmath.clustering.html b/docs/fastmath.clustering.html index 53b9e1a6..a5f01eb4 100755 --- a/docs/fastmath.clustering.html +++ b/docs/fastmath.clustering.html @@ -1,6 +1,6 @@ -fastmath.clustering documentation

fastmath.clustering

Clustering algorithms.

+fastmath.clustering documentation

fastmath.clustering

Clustering algorithms.

Various clustering algrorithms backed by SMILE library.

Currently implemented: only partition clustering.

Input data

@@ -65,9 +65,9 @@

Regrouping

:data :clustering :obj :predict) ;;=> {:clusters 2, -;;=> :info {:distortion 11220.0, :maxneighbor 100, :numlocalminima 8}, -;;=> :representatives ((0.0) (125.0)), -;;=> :sizes (101 899), +;;=> :info {:distortion 11621.0, :maxneighbor 100, :numlocalminima 8}, +;;=> :representatives ((126.0) (-1.0)), +;;=> :sizes (893 107), ;;=> :type :clarans}

clustering-methods-list

List of clustering methods.

Examples

List of methods

clustering-methods-list
 ;;=> (:dbscan :k-means :mec
 ;;=>          :clarans :g-means
@@ -94,7 +94,7 @@ 

Regrouping

;;=> {:clusters 8, ;;=> :info {:minpts 10.0, :radius 20.0}, ;;=> :representatives nil, -;;=> :sizes (1179 1136 1089 1089 117 114 137 139 0), +;;=> :sizes (1110 1121 1132 108 1165 120 116 128 0), ;;=> :type :dbscan}

denclue

(denclue data sigma m)

DENsity CLUstering algorithm.

Input:

    @@ -106,7 +106,7 @@

    Regrouping

    (denclue (repeatedly 100 (fn* [] (r/randval (r/drand) (r/drand 5 6)))) 1 10)) -;;=> [2 (44 56) nil] +;;=> [2 (61 39) nil] (map (fn [m] (dissoc m :data)) (regroup @@ -116,12 +116,12 @@

    Regrouping

    10))) ;;=> ({:key 0, ;;=> :outliers? false, -;;=> :representative (5.497646714525611), -;;=> :size 907} +;;=> :representative (5.4885025003100845), +;;=> :size 895} ;;=> {:key 1, ;;=> :outliers? false, -;;=> :representative (0.4776953453267522), -;;=> :size 93})

deterministic-annealing

(deterministic-annealing data max-clusters)(deterministic-annealing data max-clusters alpha)

Deterministic Annealing algorithm.

+;;=> :representative (0.48723616051539753), +;;=> :size 105})

deterministic-annealing

(deterministic-annealing data max-clusters)(deterministic-annealing data max-clusters alpha)

Deterministic Annealing algorithm.

Input:

  • data - sequence of samples
  • @@ -137,12 +137,12 @@

    Regrouping

    (regroup))) ;;=> ({:key 1, ;;=> :outliers? false, -;;=> :representative (5.014297930195461 2.5729807461589758), -;;=> :size 508} +;;=> :representative (4.959806312537571 2.4871696762711326), +;;=> :size 478} ;;=> {:key 0, ;;=> :outliers? false, -;;=> :representative (-0.08242718156433262 2.311519619593723), -;;=> :size 492})

distances-list

List of distances used in some clustring methods.

Examples

List of distances

distances-list
+;;=>   :representative (-0.09905633931763892 2.3833226176495117),
+;;=>   :size 522})

distances-list

List of distances used in some clustring methods.

Examples

List of distances

distances-list
 ;;=> (:chebyshev :euclidean :manhattan)

g-means

(g-means data max-clusters)

G-Means algorithm.

Input:

    @@ -152,7 +152,7 @@

    Regrouping

    See more in SMILE doc

Examples

Expect 2 clusters, uniform distribution.

((juxt :clusters :sizes :representatives)
  (g-means (repeatedly 100 (fn* [] (r/randval (r/drand) (r/drand 5 6))))
           4))
-;;=> [2 (42 58) ((0.6303717675825354) (5.556703932918526))]

k-means

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

K-Means++ algorithm.

+;;=> [2 (48 52) ((5.446422151877801) (0.48014682889023114))]

k-means

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

K-Means++ algorithm.

Input:

  • data - sequence of samples
  • @@ -162,34 +162,34 @@

    Regrouping

See more in SMILE doc

Examples

Usage

(k-means [1 2 3 -1 -1 2 -1 11 111] 4)
 ;;=> #fastmath.clustering/ClusteringResult
-;;=>  {:clustering (3 3 3 0 0 3 0 2 1),
+;;=>  {:clustering (1 1 1 3 3 1 3 2 0),
 ;;=>   :clusters 4,
 ;;=>   :data [1 2 3 -1 -1 2 -1 11 111],
 ;;=>   :info {:distortion 2.0000000000000004},
 ;;=>   :obj
-;;=>   #object[smile.clustering.KMeans 0xfda84f7 "K-Means distortion: 2,00000\r\nClusters of 9 data points of dimension 1:\r\n  0\t    3 (33.3%)\r\n  1\t    1 (11.1%)\r\n  2\t    1 (11.1%)\r\n  3\t    4 (44.4%)\r\n"],
-;;=>   :predict #,
-;;=>   :representatives ((-1.0) (111.0) (11.0) (2.0)),
-;;=>   :sizes (3 1 1 4),
-;;=>   :type :k-means}

Clusters group into separate maps.

(regroup (k-means [1 2 3 -1 -1 2 -1 11 111] 4))
+;;=>   #object[smile.clustering.KMeans 0x462733f4 "K-Means distortion: 2,00000\r\nClusters of 9 data points of dimension 1:\r\n  0\t    1 (11.1%)\r\n  1\t    4 (44.4%)\r\n  2\t    1 (11.1%)\r\n  3\t    3 (33.3%)\r\n"],
+;;=>   :predict #,
+;;=>   :representatives ((111.0) (2.0) (11.0) (-1.0)),
+;;=>   :sizes (1 4 1 3),
+;;=>   :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,
 ;;=>   :outliers? false,
 ;;=>   :representative (2.0),
 ;;=>   :size 4}
 ;;=>  {:data (-1 -1 -1),
-;;=>   :key 2,
+;;=>   :key 0,
 ;;=>   :outliers? false,
 ;;=>   :representative (-1.0),
 ;;=>   :size 3}
-;;=>  {:data (11), :key 0, :outliers? false, :representative (11.0), :size 1}
+;;=>  {:data (11), :key 2, :outliers? false, :representative (11.0), :size 1}
 ;;=>  {:data (111),
 ;;=>   :key 1,
 ;;=>   :outliers? false,
 ;;=>   :representative (111.0),
 ;;=>   :size 1})

Use as predictor

(let [cl (k-means [1 2 3 -1 -1 2 -1 11 111] 4)]
   [(cl -1) (cl 10) (cl 100) (cl 1) (cl -1000) (cl 1000)])
-;;=> [3 0 2 1 3 2]

mec

(mec data max-clusters radius)(mec data dist max-clusters radius)

Nonparametric Minimum Conditional Entropy Clustering algorithm.

+;;=> [3 2 1 0 3 1]

mec

(mec data max-clusters radius)(mec data dist max-clusters radius)

Nonparametric Minimum Conditional Entropy Clustering algorithm.

Input:

  • data - sequence of samples
  • @@ -208,10 +208,10 @@

    Regrouping

    20) :data :clustering :obj :predict) -;;=> {:clusters 5, -;;=> :info {:entropy 283.36136928676956}, +;;=> {:clusters 4, +;;=> :info {:entropy 0.0}, ;;=> :representatives nil, -;;=> :sizes (1286 228 2254 995 237), +;;=> :sizes (2271 2226 259 244), ;;=> :type :mec}

neural-gas

(neural-gas data clusters)(neural-gas data clusters lambda-i lambda-f eps-i eps-f steps)

Neural Gas algorithm.

Input:

    @@ -228,31 +228,31 @@

    Regrouping

See more in SMILE doc

Examples

Usage

(neural-gas [1 2 3 -1 -1 2 -1 11 111] 4)
 ;;=> #fastmath.clustering/ClusteringResult
-;;=>  {:clustering (0 0 0 0 0 0 0 3 1),
+;;=>  {:clustering (3 3 3 3 3 3 3 0 1),
 ;;=>   :clusters 4,
 ;;=>   :data [1 2 3 -1 -1 2 -1 11 111],
-;;=>   :info {:distortion 100.21135606663056},
+;;=>   :info {:distortion 100.21133258180804},
 ;;=>   :obj
-;;=>   #object[smile.vq.NeuralGas 0x5d4b9d25 "Neural Gas distortion: 100,21136\r\nClusters of 9 data points of dimension 1:\r\n  0\t    7 (77.8%)\r\n  1\t    1 (11.1%)\r\n  2\t    0 ( 0.0%)\r\n  3\t    1 (11.1%)\r\n"],
-;;=>   :predict #,
-;;=>   :representatives ((0.6767057694246992)
+;;=>   #object[smile.vq.NeuralGas 0x3011e6ef "Neural Gas distortion: 100,21133\r\nClusters of 9 data points of dimension 1:\r\n  0\t    1 (11.1%)\r\n  1\t    1 (11.1%)\r\n  2\t    0 ( 0.0%)\r\n  3\t    7 (77.8%)\r\n"],
+;;=>   :predict #,
+;;=>   :representatives ((9.498437706658049)
 ;;=>                     (102.02680736489556)
 ;;=>                     (38.047386026088205)
-;;=>                     (9.498429886559977)),
-;;=>   :sizes (7 1 0 1),
-;;=>   :type :neural-gas}

Clusters group into separate maps.

(regroup (neural-gas [1 2 3 -1 -1 2 -1 11 111] 4))
+;;=>                     (0.676705769486632)),
+;;=>   :sizes (1 1 0 7),
+;;=>   :type :neural-gas}

Clusters group into separate maps.

(regroup (neural-gas [1 2 3 -1 -1 2 -1 11 111] 4))
 ;;=> ({:data (1 2 3 -1 -1 2 -1),
-;;=>   :key 1,
+;;=>   :key 0,
 ;;=>   :outliers? false,
-;;=>   :representative (0.6767057694450506),
+;;=>   :representative (0.676705769486632),
 ;;=>   :size 7}
 ;;=>  {:data (11),
-;;=>   :key 3,
+;;=>   :key 2,
 ;;=>   :outliers? false,
-;;=>   :representative (9.498431345311419),
+;;=>   :representative (9.498437706658049),
 ;;=>   :size 1}
 ;;=>  {:data (111),
-;;=>   :key 0,
+;;=>   :key 1,
 ;;=>   :outliers? false,
 ;;=>   :representative (102.02680736489556),
 ;;=>   :size 1})

outlier-id

const

;;=> 2147483647

Id of the cluster which contain outliers.

regroup

(regroup clustered-data)

Transform clusterig result into list of clusters as separate maps.

@@ -267,20 +267,20 @@

Regrouping

Representative is always a n-dimensional sequence even if input is a list of numbers.

Empty clusters are skipped.

Examples

Result of clustering with regrouping

(k-means [1 2 3 -1 -1 2 -1 11 111] 7)
 ;;=> #fastmath.clustering/ClusteringResult
-;;=>  {:clustering (5 4 2 0 0 4 0 3 1),
+;;=>  {:clustering (0 5 4 3 3 5 3 2 1),
 ;;=>   :clusters 7,
 ;;=>   :data [1 2 3 -1 -1 2 -1 11 111],
 ;;=>   :info {:distortion 0.0},
 ;;=>   :obj
-;;=>   #object[smile.clustering.KMeans 0x642aa917 "K-Means distortion: 0,00000\r\nClusters of 9 data points of dimension 1:\r\n  0\t    3 (33.3%)\r\n  1\t    1 (11.1%)\r\n  2\t    1 (11.1%)\r\n  3\t    1 (11.1%)\r\n  4\t    2 (22.2%)\r\n  5\t    1 (11.1%)\r\n  6\t    0 ( 0.0%)\r\n"],
-;;=>   :predict #,
-;;=>   :representatives ((-1.0) (111.0) (3.0) (11.0) (2.0) (1.0) (##NaN)),
-;;=>   :sizes (3 1 1 1 2 1 0),
+;;=>   #object[smile.clustering.KMeans 0x2e909445 "K-Means distortion: 0,00000\r\nClusters of 9 data points of dimension 1:\r\n  0\t    1 (11.1%)\r\n  1\t    1 (11.1%)\r\n  2\t    1 (11.1%)\r\n  3\t    3 (33.3%)\r\n  4\t    1 (11.1%)\r\n  5\t    2 (22.2%)\r\n  6\t    0 ( 0.0%)\r\n"],
+;;=>   :predict #,
+;;=>   :representatives ((1.0) (111.0) (11.0) (-1.0) (3.0) (2.0) (##NaN)),
+;;=>   :sizes (1 1 1 3 1 2 0),
 ;;=>   :type :k-means}
 (regroup (k-means [1 2 3 -1 -1 2 -1 11 111] 7))
 ;;=> ({:data (1), :key 4, :outliers? false, :representative (1.0), :size 1}
-;;=>  {:data (2 2), :key 5, :outliers? false, :representative (2.0), :size 2}
-;;=>  {:data (3), :key 3, :outliers? false, :representative (3.0), :size 1}
+;;=>  {:data (2 2), :key 3, :outliers? false, :representative (2.0), :size 2}
+;;=>  {:data (3), :key 5, :outliers? false, :representative (3.0), :size 1}
 ;;=>  {:data (-1 -1 -1),
 ;;=>   :key 0,
 ;;=>   :outliers? false,
@@ -293,7 +293,7 @@ 

Regrouping

;;=> :representative (111.0), ;;=> :size 1}) (count (regroup (k-means [1 2 3 -1 -1 2 -1 11 111] 7))) -;;=> 6

x-means

(x-means data max-clusters)

X-Means algorithm.

+;;=> 6

x-means

(x-means data max-clusters)

X-Means algorithm.

Input:

  • data - sequence of samples
  • @@ -303,4 +303,4 @@

    Regrouping

    (x-means (repeatedly 10000 (fn* [] (r/randval (r/grand) (r/grand 5 1.0)))) 4)) -;;=> [2 (5052 4948) ((0.008075671806555154) (5.014140623620543))]
\ No newline at end of file +;;=> [2 (4995 5005) ((5.005656562406386) (-0.011168320992583245))]
\ No newline at end of file diff --git a/docs/fastmath.complex.html b/docs/fastmath.complex.html index a6552052..19bf8064 100755 --- a/docs/fastmath.complex.html +++ b/docs/fastmath.complex.html @@ -1,6 +1,6 @@ -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.

diff --git a/docs/fastmath.core.html b/docs/fastmath.core.html index b7bf880a..b3488bb0 100755 --- 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-not bit-shift-left bit-shift-right unsigned-bit-shift-right inc dec zero? neg? pos? min max even? odd?

@@ -195,14 +195,14 @@

Other functions

(sample sq 1 5 5) ;;=> (1.0 4.0 9.0 16.0 25.0)

sec

(sec v)

Secant

Examples

Plot of sec

sech

(sech v)

Hyperbolic secant

Examples

Plot of sech

seq->double-array

(seq->double-array vs)

Convert sequence to double-array.

If sequence is double-array do not convert.

Examples

Convert

(seq->double-array [1 2 3])
-;;=> [D@6be9e443
+;;=> [D@7d622313
 (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.

If sequence is double-array of double-arrays do not convert

Examples

Convert

(seq->double-double-array [[1 2] [3 4]])
-;;=> [[D@5f990556
+;;=> [[D@17752474
 (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.

Examples

Examples

(sfrac 0.555)
diff --git a/docs/fastmath.easings.html b/docs/fastmath.easings.html
index 905ba259..d26c49ea 100755
--- 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

Easing functions.

List of all are in easings-list.

Code snippets

Save incanter graph

(defn save-graph
   [f params & opts]
   (let [fname (str "images/e/" (first opts) ".png")]
diff --git a/docs/fastmath.fields.html b/docs/fastmath.fields.html
index cec48b67..716dc5fa 100755
--- 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

@@ -70,7 +70,7 @@

Combinations

  • :angles - vector field from angles
  • See random-configuration for example.

    Examples

    Create random combination

    (let [f (combine)] (f (v/vec2 -0.5 0.5)))
    -;;=> #vec2 [-1.0582525085584098, -0.6653935508251817]

    Create combination for given configuration

    (let [conf {:type :operation,
    +;;=> #vec2 [0.04272272840444622, 0.12590519239639839]

    Create combination for given configuration

    (let [conf {:type :operation,
                 :name :comp,
                 :var1 {:type :variation,
                        :name :blocky,
    @@ -99,22 +99,22 @@ 

    Combinations

    ;;=> 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$make_sinusoidal$fn__30681@457a8955
    +;;=> fastmath.fields$make_sinusoidal$fn__30694@4fb4bccf
     ((field :sinusoidal) (v/vec2 m/HALF_PI m/HALF_PI))
     ;;=> #vec2 [1.0, 1.0]

    Get vector field by name and scale

    (field :sinusoidal 0.5)
    -;;=> fastmath.fields$make_sinusoidal$fn__30681@35a40528
    +;;=> fastmath.fields$make_sinusoidal$fn__30694@2a22e0f3
     ((field :sinusoidal 0.5) (v/vec2 m/HALF_PI m/HALF_PI))
     ;;=> #vec2 [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 {:a 0.2390632902006118,
    -;;=>                    :discrete-spread 0.3409036761239128,
    -;;=>                    :divisor -1.242769534325375,
    -;;=>                    :offset2 1.1598996423386776,
    -;;=>                    :r -1.0267461419631134,
    -;;=>                    :spread 1.4761457093452472,
    -;;=>                    :spread2 1.2783981375938427},
    -;;=>  :value #vec2 [1.1173761044548094, -0.28228041337605625]}

    fields-list

    Examples

    List of all vector field names.

    (sort fields-list)
    +;;=> {:parametrization {:a 1.2936893322653744,
    +;;=>                    :discrete-spread -0.2536334691752896,
    +;;=>                    :divisor -1.9948892988173217,
    +;;=>                    :offset2 1.2125436091635144,
    +;;=>                    :r 0.6709936008753878,
    +;;=>                    :spread -0.7578949299360351,
    +;;=>                    :spread2 -0.6251667925228239},
    +;;=>  :value #vec2 [1.1168973437573764, 0.011149383419789733]}

    fields-list

    Examples

    List of all vector field names.

    (sort fields-list)
     ;;=> (:arch
     ;;=>  :asteria
     ;;=>  :atan :auger
    @@ -277,68 +277,54 @@ 

    Combinations

    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 0.996038265527873,
    -;;=>  :scale 1.5614922602882713,
    -;;=>  :sym -1.7897302163543403,
    -;;=>  :weight 0.4304604009686175}

    Add lacking fields

    (parametrization :auger {:scale 1.0, :freq 1.0})
    +;;=> {:freq 3.8333914573980934,
    +;;=>  :scale -1.6793051288069232,
    +;;=>  :sym -0.6076386109834693,
    +;;=>  :weight -0.42212616248182844}

    Add lacking fields

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

    Returns empty map when field doesn’t have parametrization

    (parametrization :sinusoidal)
    +;;=>  :sym 1.5928500334721458,
    +;;=>  :weight -0.9713306336457626}

    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 {}, :name :spherical, :type :variation}

    One node configuration

    (random-configuration 0)
     ;;=> {:amount 1.0,
    -;;=>  :name :comp,
    -;;=>  :type :operation,
    -;;=>  :var1
    -;;=>  {:amount 1.0,
    -;;=>   :name :comp,
    -;;=>   :type :operation,
    -;;=>   :var1
    -;;=>   {:amount 1.0,
    -;;=>    :name :comp,
    -;;=>    :type :operation,
    -;;=>    :var1 {:amount 1.0, :config {}, :name :besselj, :type :variation},
    -;;=>    :var2 {:amount 1.0, :config {}, :name :horseshoe, :type :variation}},
    -;;=>   :var2 {:amount 1.0, :config {}, :name :swirl, :type :variation}},
    -;;=>  :var2 {:amount 1.0,
    -;;=>         :config {:d1 -0.40134533717371834,
    -;;=>                  :d2 -1.0350466082057443,
    -;;=>                  :r1 2.634209728882775,
    -;;=>                  :r2 0.7207839073777886},
    -;;=>         :name :trade,
    -;;=>         :type :variation}}

    One node configuration

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

    Configuration with depth 2

    (random-configuration 2)
    +;;=>  :config {:distance 0.054860550963109045, :radius 1.0872224802992538},
    +;;=>  :name :emod,
    +;;=>  :type :variation}

    Configuration with depth 2

    (random-configuration 2)
     ;;=> {:amount 1.0,
     ;;=>  :name :comp,
     ;;=>  :type :operation,
     ;;=>  :var1 {:amount 1.0,
    -;;=>         :name :comp,
    +;;=>         :name :add,
     ;;=>         :type :operation,
    -;;=>         :var1 {:amount 1.0,
    -;;=>                :config {:coeff10 -0.721136725623662,
    -;;=>                         :coeff11 0.7386087825101102,
    -;;=>                         :coeff20 -0.9275878473253583,
    -;;=>                         :coeff21 1.9624814538837034},
    -;;=>                :name :waves,
    +;;=>         :var1 {:amount -0.6560355477941067,
    +;;=>                :config {:x 1.2532694475908999, :y 0.7377233371677647},
    +;;=>                :name :splits,
     ;;=>                :type :variation},
    -;;=>         :var2
    -;;=>         {:amount 1.0, :config {}, :name :petal, :type :variation}},
    -;;=>  :var2 {:amount 1.0, :config {}, :name :rays2, :type :variation}}

    randomize-configuration

    (randomize-configuration f)

    Randomize values for given configuration. Keeps structure untouched.

    Examples

    Usage

    (let [conf {:type :variation,
    +;;=>         :var2 {:amount -0.03833751806087493,
    +;;=>                :config {},
    +;;=>                :name :miller,
    +;;=>                :type :variation}},
    +;;=>  :var2 {:amount 1.0,
    +;;=>         :config {:xsplit 6.077283447119191, :ysplit -2.160096812677849},
    +;;=>         :name :split,
    +;;=>         :type :variation}}

    randomize-configuration

    (randomize-configuration f)

    Randomize values for given configuration. Keeps structure untouched.

    Examples

    Usage

    (let [conf {:type :variation,
                 :name :blocky,
                 :amount 1.0,
                 :config {:x -1.4, :y 0.9, :mp 2.6}}]
       [(randomize-configuration conf) (randomize-configuration conf)])
     ;;=> [{:amount 1.0,
    -;;=>   :config {:mp -3.7827726391591416,
    -;;=>            :x 1.0026445070840058,
    -;;=>            :y -1.080065811133916},
    +;;=>   :config {:mp 3.688168859670335,
    +;;=>            :x -1.3078135229931176,
    +;;=>            :y -1.0747112047699148},
     ;;=>   :name :blocky,
     ;;=>   :type :variation}
     ;;=>  {:amount 1.0,
    -;;=>   :config
    -;;=>   {:mp 5.082081761267338, :x 1.051189594802358, :y -0.5150452243610762},
    +;;=>   :config {:mp 0.25906353384380704,
    +;;=>            :x 0.569510187094301,
    +;;=>            :y 1.0059823939966894},
     ;;=>   :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.

    Examples

    Usage

    (let [f (scalar->vector-field v/heading (field :sinusoidal))]
       (v/applyf (f (v/vec2 m/HALF_PI m/HALF_PI)) m/degrees))
    diff --git a/docs/fastmath.interpolation.html b/docs/fastmath.interpolation.html
    index 674afd8a..3b72bb07 100755
    --- a/docs/fastmath.interpolation.html
    +++ b/docs/fastmath.interpolation.html
    @@ -1,6 +1,6 @@
     
    -fastmath.interpolation documentation

    fastmath.interpolation

    1d, 2d interpolation functions.

    +fastmath.interpolation documentation

    fastmath.interpolation

    1d, 2d interpolation functions.

    See more:

    Count number of true values with probability 0.15

    (count (filter true? (repeatedly 100000 (fn* [] (brand 0.15)))))
    -;;=> 14969

    default-rng

    Default RNG - JDK

    Examples

    Usage

    (set-seed! default-rng 111)
    -;;=> org.apache.commons.math3.random.JDKRandomGenerator@6fc06ec4
    +;;=> 14698

    default-rng

    Default RNG - JDK

    Examples

    Usage

    (set-seed! default-rng 111)
    +;;=> org.apache.commons.math3.random.JDKRandomGenerator@41614251
     (irandom default-rng)
     ;;=> -1641157356
     (set-seed! default-rng 999)
    -;;=> org.apache.commons.math3.random.JDKRandomGenerator@6fc06ec4
    +;;=> org.apache.commons.math3.random.JDKRandomGenerator@41614251
     (irandom default-rng)
     ;;=> -421961713
     (set-seed! default-rng 111)
    -;;=> org.apache.commons.math3.random.JDKRandomGenerator@6fc06ec4
    +;;=> org.apache.commons.math3.random.JDKRandomGenerator@41614251
     (irandom default-rng)
     ;;=> -1641157356

    discrete-noise

    macro

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

    Discrete noise. Parameters:

      @@ -139,9 +139,9 @@

      Integer di
    • :uniform-int - :lower (default: 0) and :upper (default: Integer/MAX_VALUE)
    • :zipf - :number-of-elements (default: 100) and :exponent (default: 3.0)

    Examples

    Usage

    (distribution :beta)
    -;;=> org.apache.commons.math3.distribution.BetaDistribution@5deb1292
    +;;=> org.apache.commons.math3.distribution.BetaDistribution@6ea1a97b
     (distribution :beta {:alpha 1.0, :beta 1.0})
    -;;=> org.apache.commons.math3.distribution.BetaDistribution@45ef593f

    PDFs of beta

    PDFs of binomial

    PDFs of cauchy

    PDFs of chi-squared

    PDFs of empirical

    PDFs of enumerated-int

    PDFs of enumerated-real

    PDFs of exponential

    PDFs of f

    PDFs of gamma

    PDFs of geometric

    PDFs of gumbel

    PDFs of hypergeometric

    PDFs of laplace

    PDFs of levy

    PDFs of log-normal

    PDFs of logistic

    PDFs of nakagami

    PDFs of normal

    PDFs of pareto

    PDFs of pascal

    PDFs of poisson

    PDFs of t

    PDFs of triangular

    PDFs of uniform-int

    PDFs of uniform-real

    PDFs of weibull

    PDFs of zipf

    DistributionProto

    protocol

    Get information from distributions.

    members

    cdf

    (cdf d v)(cdf d v1 v2)

    Cumulative probability.

    Examples

    Usage

    (cdf (distribution :gamma) 1)
    +;;=> org.apache.commons.math3.distribution.BetaDistribution@3c3b70b7

    PDFs of beta

    PDFs of binomial

    PDFs of cauchy

    PDFs of chi-squared

    PDFs of empirical

    PDFs of enumerated-int

    PDFs of enumerated-real

    PDFs of exponential

    PDFs of f

    PDFs of gamma

    PDFs of geometric

    PDFs of gumbel

    PDFs of hypergeometric

    PDFs of laplace

    PDFs of levy

    PDFs of log-normal

    PDFs of logistic

    PDFs of nakagami

    PDFs of normal

    PDFs of pareto

    PDFs of pascal

    PDFs of poisson

    PDFs of t

    PDFs of triangular

    PDFs of uniform-int

    PDFs of uniform-real

    PDFs of weibull

    PDFs of zipf

    DistributionProto

    protocol

    Get information from distributions.

    members

    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

    icdf

    (icdf d p)

    Inversed cumulative probability

    Examples

    Usage

    (icdf (distribution :gamma) 0.5)
    @@ -191,11 +191,11 @@ 

    Integer di (lrand 10 20) ;;=> 18

    noise

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

    Create improved Perlin Noise.

    6 octaves, quintic interpolation.

    Examples

    Usage

    (noise 3.3)
    -;;=> 0.40129980952380967
    +;;=> 0.7685663492063489
     (noise 3.3 1.1)
    -;;=> 0.5933656291555558
    +;;=> 0.6151081093282538
     (noise 3.3 0.0 -0.1)
    -;;=> 0.42132102590984155

    2d noise

    noise-types

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

    Examples

    List of names (keys)

    (keys noise-types)
    +;;=> 0.47516700281904745

    2d noise

    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)

    random-noise-cfg

    (random-noise-cfg)

    Create random noise configuration.

    Examples

    Random configuration

    (random-noise-cfg)
     ;;=> {:gain 0.4616632689024004,
     ;;=>  :interpolation :hermite,
    @@ -204,9 +204,9 @@ 

    Integer di ;;=> :normalize? true, ;;=> :octaves 5, ;;=> :seed -1927726348}

    Create function

    (random-noise-fn)
    -;;=> fastmath.random$ridgedmulti_noise$fn__9831@467e6dc2
    +;;=> fastmath.random$fbm_noise$fn__9836@cfdfc94
     (random-noise-fn (random-noise-cfg))
    -;;=> fastmath.random$ridgedmulti_noise$fn__9831@3041795b

    One

    Two

    Three

    random-noise-fn

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

    Create random noise function from all possible options.

    +;;=> fastmath.random$billow_noise$fn__9840@3b38c606

    One

    Two

    Three

    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.

    randval

    macro

    (randval v1 v2)(randval prob v1 v2)

    Retrun value with given probability (default 0.5)

    Examples

    Usage

    (randval :val-one :val-two)
     ;;=> :val-two
     (randval 0.001 :low-probability :high-probability)
    @@ -217,9 +217,9 @@ 

    Integer di {:octaves 3, :lacunarity 2.1, :gain 0.7, :noise-type :simplex})] (n 0.5 1.1 -1.3)) ;;=> 0.5497357888943046

    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

    Creating

    (rng :mersenne)
    -;;=> org.apache.commons.math3.random.MersenneTwister@62c3b8ca
    +;;=> org.apache.commons.math3.random.MersenneTwister@5ada7af1
     (rng :isaac 1234)
    -;;=> org.apache.commons.math3.random.ISAACRandom@73cae081

    Using

    (irandom (rng :mersenne 999) 15 25)
    +;;=> org.apache.commons.math3.random.ISAACRandom@728a778c

    Using

    (irandom (rng :mersenne 999) 15 25)
     ;;=> 17

    RNGProto

    protocol

    Defines set of random functions for different RNGs or distributions returning primitive values.

    members

    ->seq

    (->seq t)(->seq t n)

    Returns sequence of random samples limited to optional n values.

    Examples

    Sequence of random values from distribution

    (->seq (distribution :gamma) 5)
     ;;=> (1.3985071121468868
     ;;=>  1.9713574080234095
    @@ -227,28 +227,28 @@ 

    Integer di ;;=> 1.5751629265513674 ;;=> 3.0898296399038285)

    brandom

    (brandom t)(brandom t thr)

    Boolean random. Returns true or false with equal probability. You can set probability for true setting thr (from [0-1] range).

    See brand.

    Examples

    boolean

    (rngproto-snippet brandom ...)
    -;;=> true

    drandom

    (drandom t)(drandom t mx)(drandom t mn mx)

    Random double.

    +;;=> false

    drandom

    (drandom t)(drandom t mx)(drandom t mn mx)

    Random double.

    For RNGs: 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).

    See drand.

    For distributions, just returns random double (call without parameters).

    Examples

    double

    (rngproto-snippet drandom ...)
    -;;=> 0.49840740941644635

    Double random value from distribution

    (drandom (distribution :gamma))
    +;;=> 0.5552654729108655

    Double random value from distribution

    (drandom (distribution :gamma))
     ;;=> 1.7209575348841526

    frandom

    (frandom t)(frandom t mx)(frandom t mn mx)

    Random float.

    For RNGs: 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).

    See frand.

    For distributions, just returns random float (call without parameters).

    Examples

    float

    (rngproto-snippet frandom ...)
    -;;=> 0.7009547

    Float random value from distribution (sample cast to float)

    (frandom (distribution :gamma))
    +;;=> 0.5646241

    Float random value from distribution (sample cast to float)

    (frandom (distribution :gamma))
     ;;=> 3.6556783

    grandom

    (grandom t)(grandom t std)(grandom t mean std)

    Random double from gaussian distribution. 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).

    See grand.

    Examples

    gaussian double

    (rngproto-snippet grandom ...)
    -;;=> -0.10977607811588186

    irandom

    (irandom t)(irandom t mx)(irandom t mn mx)

    Random integer.

    +;;=> 0.009325068798035673

    irandom

    (irandom t)(irandom t mx)(irandom t mn mx)

    Random integer.

    For RNGs: 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).

    See irand.

    For distributions, just returns random integer (call without parameters).

    Examples

    integer

    (rngproto-snippet irandom ...)
    -;;=> -1808761782

    Integer random value from distribution (sample cast to int)

    (irandom (distribution :gamma))
    +;;=> 797977753

    Integer random value from distribution (sample cast to int)

    (irandom (distribution :gamma))
     ;;=> 4

    lrandom

    (lrandom t)(lrandom t mx)(lrandom t mn mx)

    Random long.

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

    See lrand.

    For distributions, just returns random long (call without parameters).

    Examples

    long

    (rngproto-snippet lrandom ...)
    -;;=> -1928603142821632953

    Long random value from distribution (sample cast to long)

    (lrandom (distribution :gamma))
    +;;=> 1852764628919625667

    Long random value from distribution (sample cast to long)

    (lrandom (distribution :gamma))
     ;;=> 0

    set-seed!

    (set-seed! t v)

    Sets seed. Returns RNG or distribution itself.

    Examples

    Set seed for the RNG object

    (let [rng (rng :isaac)]
       (set-seed! rng 1234)
       (irandom rng 10 15))
    @@ -272,15 +272,15 @@ 

    Integer di ;;=> #vec2 [0.125, 0.8888888888888888])

    Usage (1d)

    (let [gen (sequence-generator :sobol 1)] (take 5 (gen)))
     ;;=> (0.0 0.5 0.75 0.25 0.375)

    Halton plot (1000 samples)

    Sobol plot (1000 samples)

    Sphere plot (1000 samples)

    Gaussian plot (1000 samples)

    Default plot (1000 samples)

    sequence-generators-list

    List of random sequence generator. See sequence-generator.

    Examples

    Generator names.

    (sort sequence-generators-list)
     ;;=> (:default :gaussian :halton :sobol :sphere)

    simplex

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

    Create Simplex noise. 6 octaves.

    Examples

    Usage

    (simplex 3.3)
    -;;=> 0.6254018086666667
    +;;=> 0.5705071665447622
     (simplex 3.3 1.1)
    -;;=> 0.37981939206247883
    +;;=> 0.3876737663781137
     (simplex 3.3 0.0 -0.1)
    -;;=> 0.5911461793716118

    2d noise

    single-noise

    Examples

    Usage

    (let [n (single-noise {:interpolation :linear})] (n 0.5 1.1 -1.3))
    +;;=> 0.37839408321902135

    2d noise

    single-noise

    Examples

    Usage

    (let [n (single-noise {:interpolation :linear})] (n 0.5 1.1 -1.3))
     ;;=> 0.627

    2d noise

    vnoise

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

    Value Noise.

    6 octaves, Hermite interpolation (cubic, h01).

    Examples

    Usage

    (vnoise 3.3)
    -;;=> 0.34614236374728513
    +;;=> 0.5946757283025378
     (vnoise 3.3 1.1)
    -;;=> 0.3861433885179107
    +;;=> 0.7503525937304953
     (vnoise 3.3 0.0 -0.1)
    -;;=> 0.4768238162791867

    2d noise

    \ No newline at end of file +;;=> 0.5069293808908999

    2d noise

    \ No newline at end of file diff --git a/docs/fastmath.rbf.html b/docs/fastmath.rbf.html index be405e81..881895d8 100755 --- a/docs/fastmath.rbf.html +++ b/docs/fastmath.rbf.html @@ -1,6 +1,6 @@ -fastmath.rbf documentation

    fastmath.rbf

    Radial Basis Function

    +fastmath.rbf documentation

    fastmath.rbf

    Radial Basis Function

    Create with multifunction rbf.

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

    rbf-obj returns SMILE library object for defined function.

    Categories

    Code snippets

    Save graph

    (defn save-graph
    diff --git a/docs/fastmath.stats.html b/docs/fastmath.stats.html
    index 626b4edb..0defb9a2 100755
    --- 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 for sequence.
    • Correlation / covariance of two sequences.
    • @@ -47,7 +47,7 @@

      Other

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

      -

      histogram to count samples in evenly spaced ranges.

    adjacent-values

    (adjacent-values vs)(adjacent-values vs estimation-strategy)(adjacent-values vs q1 q3)

    adjacent-values

    (adjacent-values vs)(adjacent-values vs estimation-strategy)(adjacent-values vs q1 q3)

    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)).
    • @@ -55,13 +55,25 @@

      Other

    Optional estimation-strategy argument can be set to change quantile calculations estimation type. See estimation-strategies.

    Examples

    [LAV, UAV]

    (adjacent-values [1 2 3 -1 -1 2 -1 11 111])
     ;;=> [-1.0 11.0]

    Gaussian distribution [LAV, UAV]

    (adjacent-values (repeatedly 1000000 r/grand))
    -;;=> [-2.7000857687493234 2.6996610841795916]

    correlation

    (correlation vs1 vs2)

    Correlation of two sequences.

    Examples

    Correlation of uniform and gaussian distribution samples.

    (correlation (repeatedly 100000 (partial r/grand 1.0 10.0))
    +;;=> [-2.7000857687493234 2.6996610841795916]

    correlation

    (correlation vs1 vs2)

    Correlation of two sequences.

    Examples

    Correlation of uniform and gaussian distribution samples.

    (correlation (repeatedly 100000 (partial r/grand 1.0 10.0))
                  (repeatedly 100000 (partial r/drand -10.0 -5.0)))
    -;;=> 0.00678949591847233

    covariance

    (covariance vs1 vs2)

    Covariance of two sequences.

    Examples

    Covariance of uniform and gaussian distribution samples.

    (covariance (repeatedly 100000 (partial r/grand 1.0 10.0))
    +;;=> 0.00678949591847233

    covariance

    (covariance vs1 vs2)

    Covariance of two sequences.

    Examples

    Covariance of uniform and gaussian distribution samples.

    (covariance (repeatedly 100000 (partial r/grand 1.0 10.0))
                 (repeatedly 100000 (partial r/drand -10.0 -5.0)))
    -;;=> -0.0019254850635683056

    estimation-strategies-list

    Examples

    List of estimation strategies for percentile

    (keys estimation-strategies-list)
    -;;=> (:r7 :r6 :r8 :r2 :r9 :r3 :r1 :legacy :r4 :r5)

    extent

    (extent vs)

    Return extent (min, max) values from sequence

    Examples

    min/max from gaussian distribution

    (extent (repeatedly 100000 r/grand))
    -;;=> [-4.284832010490651 4.5215900810413405]

    histogram

    (histogram vs bins)(histogram vs bins [mn mx])

    Calculate histogram.

    +;;=> -0.0019254850635683056

    estimate-bins

    (estimate-bins vs)(estimate-bins vs method)

    Estimate number of bins for histogram.

    +

    Possible methods are: :sqrt :sturges :rice :doane :scott :freedman-diaconis (default).

    Examples

    Estimate number of bins for various methods. vs contains 1000 random samples from Log-Normal distribution.

    (estimate-bins vs :sqrt)
    +;;=> 31
    +(estimate-bins vs :sturges)
    +;;=> 11
    +(estimate-bins vs :rice)
    +;;=> 20
    +(estimate-bins vs :doane)
    +;;=> 17
    +(estimate-bins vs :scott)
    +;;=> 53
    +(estimate-bins vs :freedman-diaconis)
    +;;=> 170

    estimation-strategies-list

    Examples

    List of estimation strategies for percentile

    (sort (keys estimation-strategies-list))
    +;;=> (:legacy :r1 :r2 :r3 :r4 :r5 :r6 :r7 :r8 :r9)

    extent

    (extent vs)

    Return extent (min, max) values from sequence

    Examples

    min/max from gaussian distribution

    (extent (repeatedly 100000 r/grand))
    +;;=> [-4.284832010490651 4.5215900810413405]

    histogram

    (histogram vs)(histogram vs bins-or-estimate-method)(histogram vs bins [mn mx])

    Calculate histogram.

    Returns map with keys:

    • :size - number of bins
    • @@ -70,54 +82,79 @@

      Other

    • :min - min value
    • :max - max value
    • :samples - number of used samples
    • -

    Examples

    3 bins from uniform distribution.

    (histogram (repeatedly 1000 rand) 3)
    -;;=> {:bins ([6.63270885468914E-4 366 0.366]
    -;;=>         [0.33351091479992095 311 0.311]
    -;;=>         [0.666358558714373 323 0.323]),
    -;;=>  :max 0.999206202628825,
    -;;=>  :min 6.63270885468914E-4,
    +
    +

    For estimation methods check estimate-bins.

    Examples

    3 bins from uniform distribution.

    (histogram (repeatedly 1000 rand) 3)
    +;;=> {:bins ([0.0011006204362501437 329 0.329]
    +;;=>         [0.33367985012268747 316 0.316]
    +;;=>         [0.6662590798091248 355 0.355]),
    +;;=>  :max 0.9988383094955621,
    +;;=>  :min 0.0011006204362501437,
     ;;=>  :samples 1000,
     ;;=>  :size 3,
    -;;=>  :step 0.33284764391445204}

    3 bins from uniform distribution for given range.

    (histogram (repeatedly 10000 rand) 3 [0.1 0.5])
    -;;=> {:bins ([0.1 1310 0.3315616299670969]
    -;;=>         [0.23333333333333334 1333 0.337382941027588]
    -;;=>         [0.3666666666666667 1308 0.3310554290053151]),
    +;;=>  :step 0.3325792296864373}

    3 bins from uniform distribution for given range.

    (histogram (repeatedly 10000 rand) 3 [0.1 0.5])
    +;;=> {:bins ([0.1 1360 0.33308841538084744]
    +;;=>         [0.23333333333333334 1335 0.32696546656869946]
    +;;=>         [0.3666666666666667 1388 0.3399461180504531]),
     ;;=>  :max 0.5,
     ;;=>  :min 0.1,
    -;;=>  :samples 3951,
    +;;=>  :samples 4083,
     ;;=>  :size 3,
     ;;=>  :step 0.13333333333333333}

    5 bins from normal distribution.

    (histogram (repeatedly 10000 r/grand) 5)
    -;;=> {:bins ([-3.8255442971705595 104 0.0104]
    -;;=>         [-2.3194795153248613 1970 0.197]
    -;;=>         [-0.8134147334791635 5407 0.5407]
    -;;=>         [0.6926500483665348 2369 0.2369]
    -;;=>         [2.1987148302122326 150 0.015]),
    +;;=> {:bins ([-3.8255442971705595 103 0.0103]
    +;;=>         [-2.3194795153248613 1973 0.1973]
    +;;=>         [-0.8134147334791635 5453 0.5453]
    +;;=>         [0.6926500483665348 2325 0.2325]
    +;;=>         [2.1987148302122326 146 0.0146]),
     ;;=>  :max 3.7047796120579304,
     ;;=>  :min -3.8255442971705595,
     ;;=>  :samples 10000,
     ;;=>  :size 5,
    -;;=>  :step 1.506064781845698}

    jensen-shannon-divergence

    (jensen-shannon-divergence vs1 vs2)

    Jensen-Shannon divergence of two sequences.

    Examples

    Jensen-Shannon divergence

    (jensen-shannon-divergence (repeatedly 100 (fn* [] (r/irand 100)))
    +;;=>  :step 1.506064781845698}

    Estimate number of bins

    (:size (histogram (repeatedly 10000 r/grand)))
    +;;=> 60

    Estimate number of bins, Rice rule

    (:size (histogram (repeatedly 10000 r/grand) :rice))
    +;;=> 44

    iqr

    (iqr vs)(iqr vs estimation-strategy)

    Interquartile range.

    Examples

    IQR

    (iqr (repeatedly 100000 r/grand))
    +;;=> 1.3507989631201418

    jensen-shannon-divergence

    (jensen-shannon-divergence vs1 vs2)

    Jensen-Shannon divergence of two sequences.

    Examples

    Jensen-Shannon divergence

    (jensen-shannon-divergence (repeatedly 100 (fn* [] (r/irand 100)))
                                (repeatedly 100 (fn* [] (r/irand 100))))
    -;;=> 498.62287946302877

    kendall-correlation

    (kendall-correlation vs1 vs2)

    Kendall’s correlation of two sequences.

    Examples

    Kendall’s correlation of uniform and gaussian distribution samples.

    (kendall-correlation (repeatedly 100000 (partial r/grand 1.0 10.0))
    +;;=> 507.81767699492116

    kendall-correlation

    (kendall-correlation vs1 vs2)

    Kendall’s correlation of two sequences.

    Examples

    Kendall’s correlation of uniform and gaussian distribution samples.

    (kendall-correlation (repeatedly 100000 (partial r/grand 1.0 10.0))
                          (repeatedly 100000 (partial r/drand -10.0 -5.0)))
    -;;=> 8.147273472734727E-4

    kullback-leibler-divergence

    (kullback-leibler-divergence vs1 vs2)

    Kullback-Leibler divergence of two sequences.

    Examples

    Kullback-Leibler divergence.

    (kullback-leibler-divergence (repeatedly 100 (fn* [] (r/irand 100)))
    +;;=> -7.405886058860589E-4

    kernel-density

    (kernel-density vs h)(kernel-density vs)

    Creates kernel density function for given series vs and optional bandwidth h.

    Examples

    Usage

    (let [kd (kernel-density [0 10 10 10 10 10 10 10 10 0 0 0 0 1 1 1] 1)]
    +  (map (comp m/approx kd) (range -5 15)))
    +;;=> (0.0
    +;;=>  0.0
    +;;=>  0.0
    +;;=>  0.02
    +;;=>  0.09
    +;;=>  0.17
    +;;=>  0.15
    +;;=>  0.06
    +;;=>  0.01
    +;;=>  0.0
    +;;=>  0.0
    +;;=>  0.0
    +;;=>  0.0
    +;;=>  0.03
    +;;=>  0.12
    +;;=>  0.2
    +;;=>  0.12
    +;;=>  0.03
    +;;=>  0.0
    +;;=>  0.0)

    kullback-leibler-divergence

    (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))))
    -;;=> 2025.8557601936284

    kurtosis

    (kurtosis vs)

    Calculate kurtosis from sequence.

    Examples

    Kurtosis

    (kurtosis [1 2 3 -1 -1 2 -1 11 111])
    -;;=> 8.732515263272099

    maximum

    (maximum vs)

    Maximum value from sequence.

    Examples

    Maximum value

    (maximum [1 2 3 -1 -1 2 -1 11 111])
    -;;=> 111.0

    mean

    (mean vs)

    Calculate mean of vs

    Examples

    Mean (average value)

    (mean [1 2 3 -1 -1 2 -1 11 111])
    -;;=> 14.111111111111109

    median

    (median vs)

    Calculate median of vs. See median-3.

    Examples

    Median (percentile 50%).

    (median [1 2 3 -1 -1 2 -1 11 111])
    +;;=> 2199.662874529706

    kurtosis

    (kurtosis vs)

    Calculate kurtosis from sequence.

    Examples

    Kurtosis

    (kurtosis [1 2 3 -1 -1 2 -1 11 111])
    +;;=> 8.732515263272099

    maximum

    (maximum vs)

    Maximum value from sequence.

    Examples

    Maximum value

    (maximum [1 2 3 -1 -1 2 -1 11 111])
    +;;=> 111.0

    mean

    (mean vs)

    Calculate mean of vs

    Examples

    Mean (average value)

    (mean [1 2 3 -1 -1 2 -1 11 111])
    +;;=> 14.111111111111109

    median

    (median vs)

    Calculate median of vs. See median-3.

    Examples

    Median (percentile 50%).

    (median [1 2 3 -1 -1 2 -1 11 111])
     ;;=> 2.0

    For three elements use faster median-3.

    (median [7 1 4])
    -;;=> 4.0

    median-3

    (median-3 a b c)

    Median of three values. See median.

    Examples

    Median of [7 1 4]

    (median-3 7 1 4)
    -;;=> 4.0

    median-absolute-deviation

    (median-absolute-deviation vs)

    Calculate MAD

    Examples

    MAD

    (median-absolute-deviation [1 2 3 -1 -1 2 -1 11 111])
    -;;=> 3.0

    minimum

    (minimum vs)

    Minimum value from sequence.

    Examples

    Minimum value

    (minimum [1 2 3 -1 -1 2 -1 11 111])
    -;;=> -1.0

    mode

    (mode vs)

    Find the value that appears most often in a dataset vs.

    +;;=> 4.0

    median-3

    (median-3 a b c)

    Median of three values. See median.

    Examples

    Median of [7 1 4]

    (median-3 7 1 4)
    +;;=> 4.0

    median-absolute-deviation

    (median-absolute-deviation vs)

    Calculate MAD

    Examples

    MAD

    (median-absolute-deviation [1 2 3 -1 -1 2 -1 11 111])
    +;;=> 3.0

    minimum

    (minimum vs)

    Minimum value from sequence.

    Examples

    Minimum value

    (minimum [1 2 3 -1 -1 2 -1 11 111])
    +;;=> -1.0

    mode

    (mode vs)

    Find the value that appears most often in a dataset vs.

    See also modes.

    Examples

    Example

    (mode [1 2 3 -1 -1 2 -1 11 111])
     ;;=> -1.0

    Returns lowest value when every element appears equally.

    (mode [5 1 2 3 4])
    -;;=> 1.0

    modes

    (modes vs)

    Find the values that appears most often in a dataset vs.

    +;;=> 1.0

    modes

    (modes vs)

    Find the values that appears most often in a dataset vs.

    Returns sequence with all most appearing values in increasing order.

    See also mode.

    Examples

    Example

    (modes [1 2 3 -1 -1 2 -1 11 111])
     ;;=> (-1.0)

    Returns lowest value when every element appears equally.

    (modes [5 5 1 1 2 3 4 4])
    -;;=> (1.0 4.0 5.0)

    outliers

    (outliers vs)(outliers vs estimation-strategy)(outliers vs q1 q3)

    Find outliers defined as values outside outer fences.

    +;;=> (1.0 4.0 5.0)

    outliers

    (outliers vs)(outliers vs estimation-strategy)(outliers vs q1 q3)

    Find outliers defined as values outside outer fences.

    Let Q1 is 25-percentile and Q3 is 75-percentile. IQR is (- Q3 Q1).

    • LOF (Lower Outer Fence) equals (- Q1 (* 3.0 IQR)).
    • @@ -134,9 +171,9 @@

      Other

      ;;=> 4.747383207352102 ;;=> 4.769288560936935 ;;=> 4.909931823383421 -;;=> 5.043073126955698)

    pearson-correlation

    (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))
    +;;=>  5.043073126955698)

    pearson-correlation

    (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)))
    -;;=> -0.005570841963401116

    percentile

    (percentile vs p)(percentile vs p estimation-strategy)

    Calculate percentile of a vs.

    +;;=> 0.007076444050676723

    percentile

    (percentile vs p)(percentile vs p estimation-strategy)

    Calculate percentile of a vs.

    Percentile p is from range 0-100.

    See docs.

    Optionally you can provide estimation-strategy to change interpolation methods for selecting values. Default is :legacy. See more here

    @@ -163,11 +200,11 @@

    Other

    (percentile [1 2 3 -1 -1 2 -1 11 111] 85.0 :r8) ;;=> 37.66666666666675 (percentile [1 2 3 -1 -1 2 -1 11 111] 85.0 :r9) -;;=> 34.75000000000007

    population-stddev

    (population-stddev vs)(population-stddev vs u)

    Calculate population standard deviation of vs.

    +;;=> 34.75000000000007

    population-stddev

    (population-stddev vs)(population-stddev vs u)

    Calculate population standard deviation of vs.

    See stddev.

    Examples

    Population standard deviation.

    (population-stddev [1 2 3 -1 -1 2 -1 11 111])
    -;;=> 34.4333315406403

    population-variance

    (population-variance vs)(population-variance vs u)

    Calculate population variance of vs.

    +;;=> 34.4333315406403

    population-variance

    (population-variance vs)(population-variance vs u)

    Calculate population variance of vs.

    See variance.

    Examples

    Population variance

    (population-variance [1 2 3 -1 -1 2 -1 11 111])
    -;;=> 1185.6543209876543

    quantile

    (quantile vs p)(quantile vs p estimation-strategy)

    Calculate quantile of a vs.

    +;;=> 1185.6543209876543

    quantile

    (quantile vs p)(quantile vs p estimation-strategy)

    Calculate quantile of a vs.

    Percentile p is from range 0.0-1.0.

    See docs for interpolation strategy.

    Optionally you can provide estimation-strategy to change interpolation methods for selecting values. Default is :legacy. See more here

    @@ -194,12 +231,12 @@

    Other

    (quantile [1 11 111 1111] 0.7 :r8) ;;=> 477.66666666666623 (quantile [1 11 111 1111] 0.7 :r9) -;;=> 460.99999999999966

    second-moment

    (second-moment vs)

    Calculate second moment from sequence.

    +;;=> 460.99999999999966

    second-moment

    (second-moment vs)

    Calculate second moment from sequence.

    It’s a sum of squared deviations from the sample mean

    Examples

    Second Moment

    (second-moment [1 2 3 -1 -1 2 -1 11 111])
    -;;=> 10670.888888888889

    skewness

    (skewness vs)

    Calculate kurtosis from sequence.

    Examples

    Skewness

    (skewness [1 2 3 -1 -1 2 -1 11 111])
    -;;=> 2.94268445417954

    spearman-correlation

    (spearman-correlation vs1 vs2)

    Spearman’s correlation of two sequences.

    Examples

    Spearsman’s correlation of uniform and gaussian distribution samples.

    (spearman-correlation (repeatedly 100000 (partial r/grand 1.0 10.0))
    +;;=> 10670.888888888889

    skewness

    (skewness vs)

    Calculate kurtosis from sequence.

    Examples

    Skewness

    (skewness [1 2 3 -1 -1 2 -1 11 111])
    +;;=> 2.94268445417954

    spearman-correlation

    (spearman-correlation vs1 vs2)

    Spearman’s correlation of two sequences.

    Examples

    Spearsman’s correlation of uniform and gaussian distribution samples.

    (spearman-correlation (repeatedly 100000 (partial r/grand 1.0 10.0))
                           (repeatedly 100000 (partial r/drand -10.0 -5.0)))
    -;;=> -0.002944189590700948

    standardize

    (standardize vs)

    Normalize samples to have mean = 0 and stddev = 1.

    Examples

    Standardize

    (standardize [1 2 3 -1 -1 2 -1 11 111])
    +;;=> 6.338276569602102E-4

    standardize

    (standardize vs)

    Normalize samples to have mean = 0 and stddev = 1.

    Examples

    Standardize

    (standardize [1 2 3 -1 -1 2 -1 11 111])
     ;;=> (-0.3589915220998317
     ;;=>  -0.33161081278713267
     ;;=>  -0.30423010347443363
    @@ -208,11 +245,11 @@ 

    Other

    ;;=> -0.33161081278713267 ;;=> -0.4137529407252298 ;;=> -0.08518442897284138 -;;=> 2.652886502297062)

    stats-map

    (stats-map vs)(stats-map vs estimation-strategy)

    Calculate several statistics of vs and return as map.

    +;;=> 2.652886502297062)

    stats-map

    (stats-map vs)(stats-map vs estimation-strategy)

    Calculate several statistics of vs and return as map.

    Optional estimation-strategy argument can be set to change quantile calculations estimation type. See estimation-strategies.

    Examples

    Stats

    (stats-map [1 2 3 -1 -1 2 -1 11 111])
     ;;=> {:IQR 8.0,
    -;;=>  :Kurtosis 8.732515263272099,
    -;;=>  :LAV -1.0,
    +;;=>  :Kurtosis 8.846742084858873,
    +;;=>  :LAV 0.0,
     ;;=>  :LIF -13.0,
     ;;=>  :LOF -25.0,
     ;;=>  :MAD 3.0,
    @@ -220,21 +257,21 @@ 

    Other

    ;;=> :Mean 14.11111111111111, ;;=> :Median 2.0, ;;=> :Min -1.0, -;;=> :Mode -1.0, +;;=> :Mode 3.0, ;;=> :Outliers 1, ;;=> :Q1 -1.0, ;;=> :Q3 7.0, ;;=> :SD 34.4333315406403, ;;=> :SEM 11.477777180213435, -;;=> :SecMoment 10670.888888888889, +;;=> :SecMoment 10142.0, ;;=> :Size 9, -;;=> :Skewness 2.94268445417954, +;;=> :Skewness 2.9666775258488958, ;;=> :Total 127.0, -;;=> :UAV 11.0, +;;=> :UAV 9.0, ;;=> :UIF 19.0, -;;=> :UOF 31.0}

    stddev

    (stddev vs)(stddev vs u)

    Calculate standard deviation of vs.

    +;;=> :UOF 31.0}

    stddev

    (stddev vs)(stddev vs u)

    Calculate standard deviation of vs.

    See population-stddev.

    Examples

    Standard deviation.

    (stddev [1 2 3 -1 -1 2 -1 11 111])
    -;;=> 36.522063346847084

    sum

    (sum vs)

    Sum of all vs values.

    Examples

    Sum

    (sum [1 2 3 -1 -1 2 -1 11 111])
    -;;=> 127.0

    variance

    (variance vs)(variance vs u)

    Calculate variance of vs.

    +;;=> 36.522063346847084

    sum

    (sum vs)

    Sum of all vs values.

    Examples

    Sum

    (sum [1 2 3 -1 -1 2 -1 11 111])
    +;;=> 127.0

    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])
    -;;=> 1333.861111111111
    \ No newline at end of file +;;=> 1333.861111111111
    \ No newline at end of file diff --git a/docs/fastmath.transform.html b/docs/fastmath.transform.html index 6fcaa7f7..31a83983 100755 --- 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.

    @@ -47,7 +47,7 @@

    Fourier

    • :standard :dft - 1d Discrete Fourier Transform - returns double-array where even elements are real part, odd elements are imaginary part.

    Examples

    Usage

    (transformer :packet :discrete-mayer)
    -;;=> jwave.transforms.WaveletPacketTransform@3bdefdf

    TransformProto

    protocol

    Transformer functions.

    members

    forward-1d

    (forward-1d t xs)

    Forward transform of sequence or array. Returns double array.

    Examples

    Usage

    (seq (forward-1d (transformer :packet :haar-orthogonal) [-1 8 7 6]))
    +;;=> jwave.transforms.WaveletPacketTransform@5b72fe6b

    TransformProto

    protocol

    Transformer functions.

    members

    forward-1d

    (forward-1d t xs)

    Forward transform of sequence or array. Returns double array.

    Examples

    Usage

    (seq (forward-1d (transformer :packet :haar-orthogonal) [-1 8 7 6]))
     ;;=> (20.0 -6.0 -8.0 -10.0)
     (seq (forward-1d (transformer :fast :haar-orthogonal) [-1 8 7 6]))
     ;;=> (20.0 -6.0 -9.0 1.0)
    diff --git a/docs/fastmath.vector.html b/docs/fastmath.vector.html
    index 39e9821b..6be156ed 100755
    --- a/docs/fastmath.vector.html
    +++ b/docs/fastmath.vector.html
    @@ -1,6 +1,6 @@
     
    -fastmath.vector documentation

    array->vec2

    (array->vec2 a)

    Doubles array to Vec2

    Examples

    Usage

    (array->vec2 (double-array [11 22 33 44 55]))
    +;;=> 42.27217043819732

    array->vec2

    (array->vec2 a)

    Doubles array to Vec2

    Examples

    Usage

    (array->vec2 (double-array [11 22 33 44 55]))
     ;;=> #vec2 [11.0, 22.0]

    array->vec3

    (array->vec3 a)

    Doubles array to Vec3

    Examples

    Usage

    (array->vec3 (double-array [11 22 33 44 55]))
     ;;=> #vec3 [11.0, 22.0, 33.0]

    array->vec4

    (array->vec4 a)

    Doubles array to Vec4

    Examples

    Usage

    (array->vec4 (double-array [11 22 33 44 55]))
     ;;=> #vec4 [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])
    @@ -80,13 +80,13 @@ 

    Types

    ;;=> #vec2 [1.0, 1.0]

    generate-vec2

    (generate-vec2 f1 f2)(generate-vec2 f)

    Generate Vec2 with fn(s)

    Examples

    Usage

    (generate-vec2 (constantly 2))
     ;;=> #vec2 [2.0, 2.0]
     (generate-vec2 rand (constantly 1))
    -;;=> #vec2 [0.697630937175877, 1.0]

    generate-vec3

    (generate-vec3 f1 f2 f3)(generate-vec3 f)

    Generate Vec3 with fn(s)

    Examples

    Usage

    (generate-vec3 rand)
    -;;=> #vec3 [0.7647454284518005, 0.5842367293138117, 0.265160233333921]
    +;;=> #vec2 [0.9006300387271936, 1.0]

    generate-vec3

    (generate-vec3 f1 f2 f3)(generate-vec3 f)

    Generate Vec3 with fn(s)

    Examples

    Usage

    (generate-vec3 rand)
    +;;=> #vec3 [0.030144161080652543, 0.059255914586241465, 0.89380903296393]
     (generate-vec3 rand (constantly 1) (constantly 2))
    -;;=> #vec3 [0.19307355930574954, 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)
    -;;=> #vec4 [0.6069732943238529, 0.2876383248893867, 0.17534206875108982, 0.735895590853345]
    +;;=> #vec3 [0.2081951824989845, 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)
    +;;=> #vec4 [0.5878877644919115, 0.06193511007129027, 0.7031884054540936, 0.188540688148369]
     (generate-vec4 rand rand (constantly 1) (constantly 2))
    -;;=> #vec4 [0.27615015939034804, 0.35372506403915827, 1.0, 2.0]

    limit

    (limit v len)

    Limit length of the vector by given value

    Examples

    Usage

    (limit (vec3 1.0 1.0 1.0) 1.0)
    +;;=> #vec4 [0.44951589005643056, 0.32708007210697687, 1.0, 2.0]

    limit

    (limit v len)

    Limit length of the vector by given value

    Examples

    Usage

    (limit (vec3 1.0 1.0 1.0) 1.0)
     ;;=> #vec3 [0.5773502691896258, 0.5773502691896258, 0.5773502691896258]
     (limit (vec3 1.0 1.0 1.0) 2.0)
     ;;=> #vec3 [1.0, 1.0, 1.0]

    normalize

    (normalize v)

    Normalize vector (set length = 1.0)

    Examples

    Usage

    (normalize (vec2 1.0 -1.0))
    @@ -96,13 +96,13 @@ 

    Types

    ;;=> 90.0 (m/degrees (relative-angle-between (vec (repeatedly 50 rand)) (vec (repeatedly 50 rand)))) -;;=> 3.594635633914216

    set-mag

    (set-mag v len)

    Set length of the vector

    Examples

    Usage

    (set-mag (vec2 0.22 0.22) (m/sqrt 2.0))
    +;;=> -4.320893748739714

    set-mag

    (set-mag v len)

    Set length of the vector

    Examples

    Usage

    (set-mag (vec2 0.22 0.22) (m/sqrt 2.0))
     ;;=> #vec2 [1.0000000000000002, 1.0000000000000002]
     (set-mag (vec2 1.0 1.0) 0.0)
     ;;=> #vec2 [0.0, 0.0]

    TOLERANCE

    const

    ;;=> 1.0E-6

    Tolerance used in is-near-zero?. Values less than this value are treated as zero.

    vec2

    (vec2 x y)

    Make 2d vector

    Examples

    Usage

    (vec2 0.5 -0.5)
     ;;=> #vec2 [0.5, -0.5]

    Destructuring

    (let [[x y] (vec2 4.3 2.2)] (+ x y))
     ;;=> 6.5

    As function

    [((vec2 11 22) 0) ((vec2 11 22) 1)]
    -;;=> [11.0 22.0]

    As sequence

    (map (fn* [p1__32512#] (* 2.0 p1__32512#)) (vec2 1 2))
    +;;=> [11.0 22.0]

    As sequence

    (map (fn* [p1__32553#] (* 2.0 p1__32553#)) (vec2 1 2))
     ;;=> (2.0 4.0)
     (reduce clojure.core/+ (vec2 6 4))
     ;;=> 10.0
    @@ -191,12 +191,12 @@ 

    Types

    ;; Test: ok.

    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)])
    -;;=> [26 98]
    +;;=> [0 99]
     (maxdim (vec3 1 2 3))
     ;;=> 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)])
    -;;=> [48 -83]
    +;;=> [62 -99]
     (mindim (vec3 1 2 3))
     ;;=> 0

    mn

    (mn v1)

    Minimum value of vector elements

    Examples

    Usage

    (mn (vec4 -1 -2 3 4))
     ;;=> -2.0

    mult

    (mult v1 v)

    Multiply vector by number v.

    Examples

    Usage

    (mult (vec4 5 4 3 5) 4.0)
    diff --git a/docs/images/i/1f8ee3a5402be0b14ee9916aecd6074b.png b/docs/images/i/1f8ee3a5402be0b14ee9916aecd6074b.png
    index 2e98743f..7fd54b17 100755
    Binary files a/docs/images/i/1f8ee3a5402be0b14ee9916aecd6074b.png and b/docs/images/i/1f8ee3a5402be0b14ee9916aecd6074b.png differ
    diff --git a/docs/index.html b/docs/index.html
    index 0a5e4263..c660c802 100755
    --- a/docs/index.html
    +++ b/docs/index.html
    @@ -1,3 +1,3 @@
     
    -Fastmath 1.1.1

    Fastmath 1.1.1

    Released under the Unlicence

    Fast and primitive math library.

    Installation

    To install, add the following dependency to your project or build file:

    [generateme/fastmath "1.1.1"]

    Namespaces

    fastmath.complex

    Complex numbers functions.

    Categories

    Other vars: abs add arg complex conjugate div mult neg reciprocal sq sqrt sqrt1z sub

    fastmath.rbf

    Radial Basis Function

    Categories

    \ No newline at end of file +Fastmath 1.1.2

    Fastmath 1.1.2

    Released under the Unlicence

    Fast and primitive math library.

    Installation

    To install, add the following dependency to your project or build file:

    [generateme/fastmath "1.1.2"]

    Namespaces

    fastmath.complex

    Complex numbers functions.

    Categories

    Other vars: abs add arg complex conjugate div mult neg reciprocal sq sqrt sqrt1z sub

    fastmath.rbf

    Radial Basis Function

    Categories

    \ No newline at end of file diff --git a/example/fastmath/stats_examples.clj b/example/fastmath/stats_examples.clj index 1c8f55cd..2fa5d837 100644 --- a/example/fastmath/stats_examples.clj +++ b/example/fastmath/stats_examples.clj @@ -1,7 +1,8 @@ (ns fastmath.stats-examples (:require [metadoc.examples :refer :all] [fastmath.stats :refer :all] - [fastmath.random :as r])) + [fastmath.random :as r] + [fastmath.core :as m])) (add-examples mode (example "Example" (mode [1 2 3 -1 -1 2 -1 11 111])) @@ -12,7 +13,7 @@ (example "Returns lowest value when every element appears equally." (modes [5 5 1 1 2 3 4 4]))) (add-examples estimation-strategies-list - (example "List of estimation strategies for percentile" (keys estimation-strategies-list))) + (example "List of estimation strategies for percentile" (sort (keys estimation-strategies-list)))) (add-examples percentile (example "Percentile 25%" (percentile [1 2 3 -1 -1 2 -1 11 111] 25.0)) @@ -64,6 +65,9 @@ (example "[LAV, UAV]" (adjacent-values [1 2 3 -1 -1 2 -1 11 111])) (example "Gaussian distribution [LAV, UAV]" (adjacent-values (repeatedly 1000000 r/grand)))) +(add-examples iqr + (example "IQR" (iqr (repeatedly 100000 r/grand)))) + (add-examples outliers (example "Outliers" (outliers [1 2 3 -1 -1 2 -1 11 111])) (example "Gaussian distribution outliers" (outliers (repeatedly 3000000 r/grand)))) @@ -90,7 +94,24 @@ (add-examples kullback-leibler-divergence (example "Kullback-Leibler divergence." (kullback-leibler-divergence (repeatedly 100 #(r/irand 100)) (repeatedly 100 #(r/irand 100))))) (add-examples jensen-shannon-divergence (example "Jensen-Shannon divergence" (jensen-shannon-divergence (repeatedly 100 #(r/irand 100)) (repeatedly 100 #(r/irand 100))))) +(add-examples estimate-bins + (let [d (r/distribution :log-normal) + vs (repeatedly 1000 #(r/drandom d))] + (example-session "Estimate number of bins for various methods. `vs` contains 1000 random samples from Log-Normal distribution." + (estimate-bins vs :sqrt) + (estimate-bins vs :sturges) + (estimate-bins vs :rice) + (estimate-bins vs :doane) + (estimate-bins vs :scott) + (estimate-bins vs :freedman-diaconis)))) + (add-examples histogram (example "3 bins from uniform distribution." (histogram (repeatedly 1000 rand) 3)) (example "3 bins from uniform distribution for given range." (histogram (repeatedly 10000 rand) 3 [0.1 0.5])) - (example "5 bins from normal distribution." (histogram (repeatedly 10000 r/grand) 5))) + (example "5 bins from normal distribution." (histogram (repeatedly 10000 r/grand) 5)) + (example "Estimate number of bins" (:size (histogram (repeatedly 10000 r/grand)))) + (example "Estimate number of bins, Rice rule" (:size (histogram (repeatedly 10000 r/grand) :rice)))) + +(add-examples kernel-density + (example (let [kd (kernel-density [0 10 10 10 10 10 10 10 10 0 0 0 0 1 1 1] 1)] + (map (comp m/approx kd) (range -5 15))))) diff --git a/project.clj b/project.clj index b3d9219c..641d185d 100755 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject generateme/fastmath "1.1.1" +(defproject generateme/fastmath "1.1.2" :description "Fast and primitive math library" :url "https://github.com/generateme/fastmath" :license {:name "The Unlicence" diff --git a/src/fastmath/stats.clj b/src/fastmath/stats.clj index d7d9df59..544dd596 100644 --- a/src/fastmath/stats.clj +++ b/src/fastmath/stats.clj @@ -58,7 +58,8 @@ (:import [org.apache.commons.math3.stat StatUtils] [org.apache.commons.math3.stat.descriptive.rank Percentile Percentile$EstimationType] [org.apache.commons.math3.stat.descriptive.moment Kurtosis SecondMoment Skewness] - [org.apache.commons.math3.stat.correlation KendallsCorrelation SpearmansCorrelation PearsonsCorrelation])) + [org.apache.commons.math3.stat.correlation KendallsCorrelation SpearmansCorrelation PearsonsCorrelation] + [smile.stat.distribution KernelDensity])) (set! *warn-on-reflection* true) (set! *unchecked-math* :warn-on-boxed) @@ -191,7 +192,17 @@ "Calculate MAD" {:metadoc/categories #{:stat}} ^double [vs] - (smile.math.Math/mad (double-array vs))) + (smile.math.Math/mad (m/seq->double-array vs))) + +(defn iqr + "Interquartile range." + {:metadoc/categories #{:stat}} + (^double [vs] (iqr vs :legacy)) + (^double [vs estimation-strategy] + (let [avs (m/seq->double-array vs) + q1 (percentile avs 25.0 estimation-strategy) + q3 (percentile avs 75.0 estimation-strategy)] + (- q3 q1)))) (defn adjacent-values "Lower and upper adjacent values (LAV and UAV). @@ -211,7 +222,7 @@ q3 (percentile avs 75.0 estimation-strategy)] (adjacent-values avs q1 q3))) ([vs ^double q1 ^double q3] - (let [avs (double-array vs) + (let [avs (m/seq->double-array vs) iqr (* 1.5 (- q3 q1)) lav-thr (- q1 iqr) uav-thr (+ q3 iqr)] @@ -239,7 +250,7 @@ q3 (percentile avs 75.0 estimation-strategy)] (outliers avs q1 q3))) ([vs ^double q1 ^double q3] - (let [avs (double-array vs) + (let [avs (m/seq->double-array vs) iqr (* 3.0 (- q3 q1)) lof-thr (- q1 iqr) uof-thr (+ q3 iqr)] @@ -397,6 +408,40 @@ ;; +(defn- scott-fd-helper + "Calculate number of bins based on width of the bin." + ^double [vvs ^double h] + (let [h (if (< h m/EPSILON) (median-absolute-deviation vvs) h)] + (if (pos? h) + (let [[^double mn ^double mx] (extent vvs)] + (m/ceil (/ (- mx mn) h))) + 1.0))) + +(defn estimate-bins + "Estimate number of bins for histogram. + + Possible methods are: `:sqrt` `:sturges` `:rice` `:doane` `:scott` `:freedman-diaconis` (default)." + {:metadoc/categories #{:stat}} + ([vs] (estimate-bins vs :freedman-diaconis)) + ([vs method] + (let [n (count vs)] + (int (condp = method + :sqrt (m/sqrt n) + :sturges (inc (m/ceil (m/log2 n))) + :rice (m/ceil (* 2.0 (m/cbrt n))) + :doane (+ (inc (m/log2 n)) + (m/log2 (inc (/ (m/abs (skewness vs)) + (m/sqrt (/ (* 6.0 (- n 2.0)) + (* (inc n) (+ n 3.0)))))))) + :scott (let [vvs (m/seq->double-array vs) + h (/ (* 3.5 (stddev vs)) + (m/cbrt n))] + (scott-fd-helper vvs h)) + :freedman-diaconis (let [vvs (m/seq->double-array vs) + h (/ (* 2.0 (iqr vvs)) + (m/cbrt n))] + (scott-fd-helper vvs h))))))) + (defn histogram "Calculate histogram. @@ -407,9 +452,14 @@ * `:bins` - list of triples of range lower value, number of hits and ratio of used samples * `:min` - min value * `:max` - max value - * `:samples` - number of used samples" + * `:samples` - number of used samples + + For estimation methods check [[estimate-bins]]." {:metadoc/categories #{:stat}} - ([vs bins] (histogram vs bins (extent vs))) + ([vs] (histogram vs :freedman-diaconis)) + ([vs bins-or-estimate-method] (histogram vs (if (keyword? bins-or-estimate-method) + (estimate-bins vs bins-or-estimate-method) + bins-or-estimate-method) (extent vs))) ([vs ^long bins [^double mn ^double mx]] (let [diff (- mx mn) step (/ diff bins) @@ -421,10 +471,9 @@ samplesd (double samples)] (doseq [^double v vs-] - (when (<= mn v mx+) - (let [b (java.util.Arrays/binarySearch ^doubles search-array v) - ^int pos (if (neg? b) (m/abs (+ b 2)) b)] - (fastmath.java.Array/inc ^longs buff pos)))) + (let [b (java.util.Arrays/binarySearch ^doubles search-array v) + ^int pos (if (neg? b) (m/abs (+ b 2)) b)] + (fastmath.java.Array/inc ^longs buff pos))) {:size bins :step step @@ -432,3 +481,15 @@ :min mn :max mx :bins (map #(vector %1 %2 (/ ^long %2 samplesd)) search-array buff)}))) + +;; + +(defn kernel-density + "Creates kernel density function for given series `vs` and optional bandwidth `h`." + {:metadoc/categories #{:stat}} + ([vs ^double h] + (let [^KernelDensity k (KernelDensity. (m/seq->double-array vs) h)] + (fn [x] (.p k x)))) + ([vs] + (let [^KernelDensity k (KernelDensity. (m/seq->double-array vs))] + (fn [x] (.p k x)))))