Liking cljdoc? Tell your friends :D

emmy.algebra.fold

Namespace implementing various aggregation functions using the fold abstraction and combinators for generating new folds from fold primitives.

Contains a number of algorithms for compensated summation of floating-point numbers.

Namespace implementing various aggregation functions using the `fold`
abstraction and combinators for generating new folds from fold primitives.

Contains a number of algorithms for [compensated
summation](https://en.wikipedia.org/wiki/Kahan_summation_algorithm) of
floating-point numbers.
raw docstring

constantclj/s

(constant const)

Given some value const, returns a fold that ignores all input and returns const for a call to any of its arities.

Given some value `const`, returns a fold that ignores all input and returns
`const` for a call to any of its arities.
sourceraw docstring

countclj/s

(count)
(count pred)

Given some predicate pred, returns a fold that counts the number of items it encounters that return true when passed to pred, false otherwise.

Given some predicate `pred`, returns a fold that counts the number of items it
encounters that return true when passed to `pred`, false otherwise.
sourceraw docstring

fold->scan-fnclj/s

(fold->scan-fn fold)
(fold->scan-fn fold present)
(fold->scan-fn init fold present)

Given

  • a 0-argument fn init that returns some "empty" accumulating value

  • a 2-argument fn fold of (accumulator, x) => accumulator responsible for merging some value x into the ongoing accumulation

  • a 1-argument fn present from accumulator => final-result

Returns a function with two arities. The first arity takes a sequence xs and returns a lazy sequence of all intermediate results of the summation. For example, given [0 1 2 3], the return sequence would be equivalent to:

(def sum-fn (fold->sum-fn init fold present))

[(sum-fn [0])
 (sum-fn [0 1])
 (sum-fn [0 1 2])
 (sum-fn [0 1 2 3])]

The second arity takes a transformation function f, an inclusive lower bound low and an exclusive upper bound high and returns a lazy sequence of all intermediate results of accumulating (map f (range low high)).

Other Arities

Given a single argument fold, fold is passed as each of the 0, 1 and 2 arity arguments.

Given fold and present, fold is used for the 0 and 2 arity arguments, present for the 1-arity argument.

Given

- a 0-argument fn `init` that returns some "empty" accumulating value

- a 2-argument fn `fold` of `(accumulator, x) => accumulator` responsible for
  merging some value `x` into the ongoing accumulation

- a 1-argument fn `present` from `accumulator => final-result`

Returns a function with two arities. The first arity takes a sequence `xs` and
returns a lazy sequence of all intermediate results of the summation. For
example, given [0 1 2 3], the return sequence would be equivalent to:

```clj
(def sum-fn (fold->sum-fn init fold present))

[(sum-fn [0])
 (sum-fn [0 1])
 (sum-fn [0 1 2])
 (sum-fn [0 1 2 3])]
```

The second arity takes a transformation function `f`, an inclusive lower bound
`low` and an exclusive upper bound `high` and returns a lazy sequence of all
intermediate results of accumulating `(map f (range low high))`.

## Other Arities

Given a single argument `fold`, `fold` is passed as each of the 0, 1 and 2
arity arguments.

Given `fold` and `present`, `fold` is used for the 0 and 2 arity arguments,
`present` for the 1-arity argument.
sourceraw docstring

fold->sum-fnclj/s

(fold->sum-fn fold)
(fold->sum-fn fold present)
(fold->sum-fn init fold present)

Given

  • a 0-argument fn init that returns some "empty" accumulating value

  • a 2-argument fn fold of (accumulator, x) => accumulator responsible for merging some value x into the ongoing accumulation

  • a 1-argument fn present from accumulator => final-result

Returns a function with two arities. The first arity takes a sequence xs and returns the result of accumulating all elements in xs using the functions above, then presenting the result.

The second arity takes a transformation function f, an inclusive lower bound low and an exclusive upper bound high and returns the result of accumulating (map f (range low high)).

Other Arities

Given a single argument fold, fold is passed as each of the 0, 1 and 2 arity arguments.

Given fold and present, fold is used for the 0 and 2 arity arguments, present for the 1-arity argument.

Given

- a 0-argument fn `init` that returns some "empty" accumulating value

- a 2-argument fn `fold` of `(accumulator, x) => accumulator` responsible for
  merging some value `x` into the ongoing accumulation

- a 1-argument fn `present` from `accumulator => final-result`

Returns a function with two arities. The first arity takes a sequence `xs` and
returns the result of accumulating all elements in `xs` using the functions
above, then `present`ing the result.

The second arity takes a transformation function `f`, an inclusive lower bound
`low` and an exclusive upper bound `high` and returns the result of
accumulating `(map f (range low high))`.

## Other Arities

Given a single argument `fold`, `fold` is passed as each of the 0, 1 and 2
arity arguments.

Given `fold` and `present`, `fold` is used for the 0 and 2 arity arguments,
`present` for the 1-arity argument.
sourceraw docstring

generic-sum-foldclj/s

(generic-sum-fold)
(generic-sum-fold acc)
(generic-sum-fold acc x)

Fold-style function. The 2-arity merge operation adds the value x into the accumulating stating using emmy.generic/+.

  • given 0 arguments, returns an accumulator of 0.0
  • given a single argument acc, acts as identity.
Fold-style function. The 2-arity merge operation adds the value `x` into the
accumulating stating using [[emmy.generic/+]].

- given 0 arguments, returns an accumulator of 0.0
- given a single argument `acc`, acts as identity.
sourceraw docstring

joinclj/s

(join)
(join fold)
(join fold & folds)

Given some number of folds, returns a new fold with the following properties:

  • the accumulator is a vector of the accumulators of each input fold
  • each x is merged into each accumulator using the appropriate fold
  • present is called for every entry in the final vector

Given a single fold, acts as identity.

The no-argument call (join) is equivalent to ([[constant]] []).

Given some number of `folds`, returns a new fold with the following properties:

- the accumulator is a vector of the accumulators of each input fold
- each `x` is merged into each accumulator using the appropriate fold
- `present` is called for every entry in the final vector

Given a single `fold`, acts as identity.

The no-argument call `(join)` is equivalent to `([[constant]] [])`.
sourceraw docstring

kahanclj/s

(kahan)
(kahan [acc _])
(kahan [acc c] x)

Fold that tracks the summation of a sequence of floating point numbers, using the Kahan summation algorithm for maintaining stability in the face of accumulating floating point errors.

Fold that tracks the summation of a sequence of floating point numbers, using
the [Kahan summation
algorithm](https://en.wikipedia.org/wiki/Kahan_summation_algorithm) for
maintaining stability in the face of accumulating floating point errors.
sourceraw docstring

kahan-babushka-kleinclj/s

(kahan-babushka-klein)
(kahan-babushka-klein acc)
(kahan-babushka-klein [acc cs ccs] x)

Implements a fold that tracks the summation of a sequence of floating point numbers, using a second-order variation of kahan-babushka-neumaier.

See this Wikipedia page for more information.

This algorithm was proposed by Klein in 'A Generalized Kahan-Babushka Summation Algorithm', along with the higher-order versions implemented by kbk-n.

Implements a fold that tracks the summation of a sequence of floating point
numbers, using a second-order variation of [[kahan-babushka-neumaier]].

See [this Wikipedia
page](https://en.wikipedia.org/wiki/Kahan_summation_algorithm#Further_enhancements)
for more information.

This algorithm was proposed by Klein in ['A Generalized Kahan-Babushka
Summation
Algorithm'](https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.582.288&rep=rep1&type=pdf),
along with the higher-order versions implemented by [[kbk-n]].
sourceraw docstring

kahan-babushka-neumaierclj/s

(kahan-babushka-neumaier)
(kahan-babushka-neumaier acc)
(kahan-babushka-neumaier [acc c] x)

Implements a fold that tracks the summation of a sequence of floating point numbers, using Neumaier's improvement to kahan.

This algorithm is more efficient than kahan, handles a wider range of cases (adding in numbers larger than the current running sum, for example) and should be preferred.

Implements a fold that tracks the summation of a sequence of floating point
numbers, using Neumaier's improvement to [[kahan]].

This algorithm is more efficient than [[kahan]], handles a wider range of
cases (adding in numbers larger than the current running sum, for example) and
should be preferred.
sourceraw docstring

kbk-nclj/smacro

(kbk-n n)

Given some order n, returns a fold implementing n-th order Kahan-Babushka-Klein summation.

Given n == 0, this is identical to a naive sum. Given n == 1, identical to kahan-babushka-neumaier. Given n == 2, identical to kahan-babushka-klein.

n > 2 represent new compensated summation algorithms.

Given some order `n`, returns a fold implementing `n`-th order
Kahan-Babushka-Klein summation.

Given `n` == 0, this is identical to a naive sum.
Given `n` == 1, identical to [[kahan-babushka-neumaier]].
Given `n` == 2, identical to [[kahan-babushka-klein]].

`n` > 2 represent new compensated summation algorithms.
sourceraw docstring

kbnclj/s

Alias for [[kahan-babushka-neumaier]].
sourceraw docstring

maxclj/s

(max)
(max acc)
(max acc x)

Fold that stores its maximum encountered value in its accumulator, and returns it when called on to present.

Accumulation initializes with nil.

Fold that stores its maximum encountered value in its accumulator, and returns
it when called on to present.

Accumulation initializes with `nil`.
sourceraw docstring

minclj/s

(min)
(min acc)
(min acc x)

Fold that stores its minimum encountered value in its accumulator, and returns it when called on to present.

Accumulation initializes with nil.

Fold that stores its minimum encountered value in its accumulator, and returns
it when called on to present.

Accumulation initializes with `nil`.
sourceraw docstring

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

× close