diff --git a/CHANGELOG.md b/CHANGELOG.md index 97cd665e..a72efd7e 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.0.3] + +### Fixed + +* `norm` when domain is a point, returns range start when value is less or equal domain, range end otherwise +* small fix in one field + ## [1.0.2] ### Added diff --git a/README.md b/README.md index 96b4c9bf..6c8e8250 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.0.1"] +[generateme/fastmath "1.0.3"] ``` ## Documentation diff --git a/docs/fastmath.complex.html b/docs/fastmath.complex.html index 12f299d6..02cd2249 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 12cbdfe9..0bbe9472 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,13 +195,13 @@

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@14a26264
+;;=> [D@7773054a
 (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)

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@26a1abb8
+;;=> [[D@22f144b1
 (double-double-array->seq (seq->double-double-array [[1 2] [3 4]]))
 ;;=> ((1.0 2.0) (3.0 4.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
diff --git a/docs/fastmath.easings.html b/docs/fastmath.easings.html
index fb617c95..cdca3054 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 1fc1144f..81b02189 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 [0.25226799258548965, 2.356194490192345]

    Create combination for given configuration

    (let [conf {:type :operation,
    +;;=> #vec2 [0.5290833818481148, -1.1001869390540726]

    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__10993@5ee513d8
    +;;=> fastmath.fields$make_sinusoidal$fn__10993@c790b46
     ((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__10993@26c1a18b
    +;;=> fastmath.fields$make_sinusoidal$fn__10993@4e10067d
     ((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.877730466661685,
    -;;=>                    :discrete-spread -0.6751139162748264,
    -;;=>                    :divisor 1.6282784739768301,
    -;;=>                    :offset2 -0.12427543265341123,
    -;;=>                    :r -1.83188652741072,
    -;;=>                    :spread 1.7702045622260916,
    -;;=>                    :spread2 0.7296746975817108},
    -;;=>  :value #vec2 [21.658436333042918, -1.7278951230767694]}

    fields-list

    Examples

    List of all vector field names.

    (sort fields-list)
    +;;=> {:parametrization {:a -1.027883317179492,
    +;;=>                    :discrete-spread 0.7910279968110224,
    +;;=>                    :divisor 0.28827117514856804,
    +;;=>                    :offset2 -1.855418094213078,
    +;;=>                    :r 1.3910205700392493,
    +;;=>                    :spread -0.6958560972015344,
    +;;=>                    :spread2 -1.6226069692931797},
    +;;=>  :value #vec2 [-83948.09092212954, -95296.9692904463]}

    fields-list

    Examples

    List of all vector field names.

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

    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 -2.7963897275940797,
    -;;=>  :scale -1.8254607490837687,
    -;;=>  :sym 0.9478132587969266,
    -;;=>  :weight 0.3262945909299366}

    Add lacking fields

    (parametrization :auger {:scale 1.0, :freq 1.0})
    +;;=> {:freq -3.0859586681349525,
    +;;=>  :scale -0.9587085563264008,
    +;;=>  :sym 1.834501264037586,
    +;;=>  :weight -0.005060306756689448}

    Add lacking fields

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

    Returns empty map when field doesn’t have parametrization

    (parametrization :sinusoidal)
    +;;=>  :sym -0.0010320305160465004,
    +;;=>  :weight 0.3690021900469187}

    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 :cylinder, :type :variation}

    One node configuration

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

    Configuration with depth 2

    (random-configuration 2)
     ;;=> {:amount 1.0,
    -;;=>  :config {:xamp 1.585288842930357,
    -;;=>           :xlength 0.8874362068373256,
    -;;=>           :yamp 0.4064734081806104,
    -;;=>           :ylength 1.0439800784233881},
    -;;=>  :name :curve,
    -;;=>  :type :variation}

    One node configuration

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

    Configuration with depth 2

    (random-configuration 2)
    -;;=> {:amount 0.5718363734154245,
    -;;=>  :name :add,
    +;;=>  :name :comp,
     ;;=>  :type :operation,
    -;;=>  :var1 {:amount -1.4534161565102903,
    -;;=>         :name :comp,
    +;;=>  :var1 {:amount 1.0,
    +;;=>         :name :add,
     ;;=>         :type :operation,
    -;;=>         :var1 {:amount 1.0,
    -;;=>                :config {:mode 2, :stretch -0.6146859450575325},
    -;;=>                :name :atan,
    +;;=>         :var1 {:amount -0.38896511052921534,
    +;;=>                :config {},
    +;;=>                :name :loonie,
     ;;=>                :type :variation},
    -;;=>         :var2 {:amount 1.0,
    -;;=>                :config {:area-x -1.6063717689830512,
    -;;=>                         :area-y 0.7733506321629653,
    -;;=>                         :center-x -0.2527242495654958,
    -;;=>                         :center-y -0.7566682275873315,
    -;;=>                         :delta-x 0.6402431582768227,
    -;;=>                         :delta-y 4.4322315820727844,
    -;;=>                         :gamma -0.3753560672495446,
    -;;=>                         :square
    -;;=>                         #},
    -;;=>                :name :gdoffs,
    +;;=>         :var2 {:amount -1.978326319628585,
    +;;=>                :config {},
    +;;=>                :name :noise,
     ;;=>                :type :variation}},
    -;;=>  :var2 {:amount -0.295335840546612,
    -;;=>         :config {:dist -3.6279688266716104, :power -1.0189539608781648},
    -;;=>         :name :julian,
    -;;=>         :type :variation}}

    randomize-configuration

    (randomize-configuration f)

    Randomize values for given configuration. Keeps structure untouched.

    Examples

    Usage

    (let [conf {:type :variation,
    +;;=>  :var2 {:amount 1.0,
    +;;=>         :config {:correctd -0.10570874404742536,
    +;;=>                  :correctn -1.49107210788639,
    +;;=>                  :denominator -16.870277795143114,
    +;;=>                  :numerator 3.1738725224288515,
    +;;=>                  :root -3.790084551225446},
    +;;=>         :name :powblock,
    +;;=>         :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 -1.9355369636115565,
    -;;=>            :x -0.7877026802140837,
    -;;=>            :y 1.3961935636733043},
    +;;=>   :config {:mp -5.319779837039107,
    +;;=>            :x 1.192112272968585,
    +;;=>            :y -0.5659895082838441},
     ;;=>   :name :blocky,
     ;;=>   :type :variation}
     ;;=>  {:amount 1.0,
    -;;=>   :config {:mp -5.268221345301132,
    -;;=>            :x -1.3191898076247768,
    -;;=>            :y 1.455043874367882},
    +;;=>   :config {:mp -3.1133839905285705,
    +;;=>            :x 0.781652073973997,
    +;;=>            :y 1.2051764264026015},
     ;;=>   :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))
    @@ -343,7 +333,7 @@ 

    Combinations

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

    sum

    (sum f1 f2 amount)(sum f1 f2)

    Add two vector fields.

    Examples

    Usage

    (let [field-1 (field :sinusoidal)
    +;;=> #vec2 [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)))
    diff --git a/docs/fastmath.interpolation.html b/docs/fastmath.interpolation.html
    index e34fcc6d..c73a274a 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)))))
    -;;=> 14725

    default-rng

    Default RNG - JDK

    Examples

    Usage

    (set-seed! default-rng 111)
    -;;=> org.apache.commons.math3.random.JDKRandomGenerator@5092d376
    +;;=> 14789

    default-rng

    Default RNG - JDK

    Examples

    Usage

    (set-seed! default-rng 111)
    +;;=> org.apache.commons.math3.random.JDKRandomGenerator@1d694d9a
     (irandom default-rng)
     ;;=> -1641157356
     (set-seed! default-rng 999)
    -;;=> org.apache.commons.math3.random.JDKRandomGenerator@5092d376
    +;;=> org.apache.commons.math3.random.JDKRandomGenerator@1d694d9a
     (irandom default-rng)
     ;;=> -421961713
     (set-seed! default-rng 111)
    -;;=> org.apache.commons.math3.random.JDKRandomGenerator@5092d376
    +;;=> org.apache.commons.math3.random.JDKRandomGenerator@1d694d9a
     (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@3bad9493
    +;;=> org.apache.commons.math3.distribution.BetaDistribution@315d19f1
     (distribution :beta {:alpha 1.0, :beta 1.0})
    -;;=> org.apache.commons.math3.distribution.BetaDistribution@20953adc

    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@4a5b9e6b

    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,22 +191,22 @@ 

    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.3132195555555555
    +;;=> 0.4835205079365082
     (noise 3.3 1.1)
    -;;=> 0.6016812851200001
    +;;=> 0.47710401682285736
     (noise 3.3 0.0 -0.1)
    -;;=> 0.4440432329549207

    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.6260293888000001

    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,
     ;;=>  :lacunarity 2.012690835375836,
    -;;=>  :noise-type :simplex,
    +;;=>  :noise-type :gradient,
     ;;=>  :normalize? true,
     ;;=>  :octaves 5,
     ;;=>  :seed -1927726348}

    Create function

    (random-noise-fn)
    -;;=> fastmath.random$billow_noise$fn__8951@700a2863
    +;;=> fastmath.random$ridgedmulti_noise$fn__8955@4b2b9e36
     (random-noise-fn (random-noise-cfg))
    -;;=> fastmath.random$ridgedmulti_noise$fn__8955@4c12ee12

    One

    Two

    Three

    random-noise-fn

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

    Create random noise function from all possible options.

    +;;=> fastmath.random$fbm_noise$fn__8947@3c066b66

    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@6b0b6001
    +;;=> org.apache.commons.math3.random.MersenneTwister@18f67db4
     (rng :isaac 1234)
    -;;=> org.apache.commons.math3.random.ISAACRandom@72ac14c6

    Using

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

    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
    @@ -231,24 +231,24 @@ 

    Integer di

    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.36674562868038474

    Double random value from distribution

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

    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.25825706

    Float random value from distribution (sample cast to float)

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

    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.7363627630093181

    irandom

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

    Random integer.

    +;;=> 1.071352745701417

    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 ...)
    -;;=> -694585408

    Integer random value from distribution (sample cast to int)

    (irandom (distribution :gamma))
    +;;=> -1779834783

    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 ...)
    -;;=> 3521902208633332220

    Long random value from distribution (sample cast to long)

    (lrandom (distribution :gamma))
    +;;=> -2415189781520483255

    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.6425389382895237
    +;;=> 0.5096442877980952
     (simplex 3.3 1.1)
    -;;=> 0.25222309080589755
    +;;=> 0.5751061746072044
     (simplex 3.3 0.0 -0.1)
    -;;=> 0.21866251355411798

    2d noise

    single-noise

    Examples

    Usage

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

    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.4738883988541735
    +;;=> 0.27846446202769165
     (vnoise 3.3 1.1)
    -;;=> 0.7563771325220159
    +;;=> 0.6497716338792594
     (vnoise 3.3 0.0 -0.1)
    -;;=> 0.697517360154229

    2d noise

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

    2d noise

    \ No newline at end of file diff --git a/docs/fastmath.rbf.html b/docs/fastmath.rbf.html index 84df2ab5..bffa0b58 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 c79bd834..486e6094 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.
    • @@ -68,13 +68,13 @@

      Other

    • :step - distance between bins
    • :bins - list of pairs of range lower value and number of hits

    Examples

    3 bins from uniform distribution.

    (histogram (repeatedly 1000 rand) 3)
    -;;=> {:bins ([1.8883426090510191E-4 348]
    -;;=>         [0.33337054071807026 316]
    -;;=>         [0.6665522471752354 336]),
    +;;=> {:bins ([9.993947203562614E-4 330]
    +;;=>         [0.33322076626006886 323]
    +;;=>         [0.6654421377997815 347]),
     ;;=>  :size 3,
    -;;=>  :step 0.33318170645716516}

    3 bins from uniform distribution for given range.

    (histogram (repeatedly 10000 rand) 3 [0.1 0.5])
    +;;=>  :step 0.3322213715397126}

    3 bins from uniform distribution for given range.

    (histogram (repeatedly 10000 rand) 3 [0.1 0.5])
     ;;=> {:bins
    -;;=>  ([0.1 1317] [0.23333333333333334 1328] [0.3666666666666667 1347]),
    +;;=>  ([0.1 1315] [0.23333333333333334 1370] [0.3666666666666667 1325]),
     ;;=>  :size 3,
     ;;=>  :step 0.13333333333333333}

    5 bins from normal distribution.

    (histogram (repeatedly 10000 r/grand) 5)
     ;;=> {:bins ([-3.8255442971705595 104]
    diff --git a/docs/fastmath.transform.html b/docs/fastmath.transform.html
    index 813276cb..838c7396 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@f2c6d70

    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@1b4f6b6d

    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 3bd7ceba..ff24e19e 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]))
    +;;=> 36.58661276002927

    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 [1.6541731102326374E-4, 1.0]

    generate-vec3

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

    Generate Vec3 with fn(s)

    Examples

    Usage

    (generate-vec3 rand)
    -;;=> #vec3 [0.005517939777284542, 0.6773827021184029, 0.3311837893009125]
    +;;=> #vec2 [0.0630710799613633, 1.0]

    generate-vec3

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

    Generate Vec3 with fn(s)

    Examples

    Usage

    (generate-vec3 rand)
    +;;=> #vec3 [0.4691580762211698, 0.252494638791968, 0.4653813945662143]
     (generate-vec3 rand (constantly 1) (constantly 2))
    -;;=> #vec3 [0.18716476249565084, 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.19168934647004054, 0.11239366841975318, 0.3612597778372615, 0.40333327639900074]
    +;;=> #vec3 [0.010902894119597217, 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.7046959186663563, 0.06544269007247161, 0.7800565032840674, 0.34281544310127676]
     (generate-vec4 rand rand (constantly 1) (constantly 2))
    -;;=> #vec4 [0.5624339225522597, 0.41849786952066026, 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.4745994985798181, 0.159660905804342, 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,7 +96,7 @@ 

    Types

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

    set-mag

    (set-mag v len)

    Set length of the vector

    Examples

    Usage

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

    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)
    @@ -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)])
    -;;=> [13 96]
    +;;=> [39 98]
     (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)])
    -;;=> [12 -100]
    +;;=> [13 -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 b5ffe5de..cb50fdea 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 c1af1991..cc4acf5a 100755
    --- a/docs/index.html
    +++ b/docs/index.html
    @@ -1,3 +1,3 @@
     
    -Fastmath 1.0.2

    Fastmath 1.0.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.0.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 +Fastmath 1.0.3

    Fastmath 1.0.3

    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.0.3"]

    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/project.clj b/project.clj index fa2e8889..e96f0c70 100755 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject generateme/fastmath "1.0.2" +(defproject generateme/fastmath "1.0.3" :description "Fast and primitive math library" :url "https://github.com/generateme/fastmath" :license {:name "The Unlicence" @@ -22,7 +22,7 @@ [lein-codox "0.10.3"]] :source-paths ["example"] :dependencies [[codox-theme-rdash "0.1.2"] - [clojure2d "0.1.0-SNAPSHOT"] + [clojure2d "1.0.0-RC2"] [criterium "0.4.4"] [incanter/incanter-charts "1.9.2"] [incanter/incanter-core "1.9.2"] diff --git a/src/fastmath/fields.clj b/src/fastmath/fields.clj index 1b61a98f..222d577e 100644 --- a/src/fastmath/fields.clj +++ b/src/fastmath/fields.clj @@ -1479,7 +1479,7 @@ :center-x (drand -1 1) :center-y (drand -1 1) :gamma (drand -5 5) - :square brand}) + :square (brand)}) (def ^:const ^:private ^double agdod-- 0.1) (def ^:const ^:private ^double agdoa-- 2.0) diff --git a/src/fastmath/java/PrimitiveMath.java b/src/fastmath/java/PrimitiveMath.java index 78a7e744..cd90efea 100644 --- a/src/fastmath/java/PrimitiveMath.java +++ b/src/fastmath/java/PrimitiveMath.java @@ -114,7 +114,7 @@ public final class PrimitiveMath { public static boolean isOdd(long a) { return (a&1)==1; } public static double norm(double v, double start, double stop) { - return start == stop ? (v < start ? 0.0 : 1.0) : (v - start) / (stop - start); + return start == stop ? (v <= start ? 0.0 : 1.0) : (v - start) / (stop - start); } public static double norm(double v, double start1, double stop1, double start2, double stop2) { return start2 + (stop2 - start2) * norm(v, start1, stop1);