Liking cljdoc? Tell your friends :D

datajure.math

Low-level numeric primitives shared across datajure namespaces.

Leaf namespace — depends only on tech.v3.datatype, so expr/core/stat/util can all use it without a require cycle (expr already requires stat, which rules out homing these in expr).

Quantiles use R's default type-7 estimator everywhere in datajure, chosen to match R's quantile(..., type = 7) / median exactly (the reference implementation for the finance workloads datajure is built against). This differs from tech.ml.dataset's dfn/percentiles / dfn/median (Apache Commons Math, a different estimation type) at the tails AND, for some n, the median.

Low-level numeric primitives shared across datajure namespaces.

Leaf namespace — depends only on tech.v3.datatype, so expr/core/stat/util can
all use it without a require cycle (expr already requires stat, which rules out
homing these in expr).

Quantiles use R's default **type-7** estimator everywhere in datajure, chosen
to match R's `quantile(..., type = 7)` / `median` exactly (the reference
implementation for the finance workloads datajure is built against). This
differs from tech.ml.dataset's `dfn/percentiles` / `dfn/median` (Apache Commons
Math, a different estimation type) at the tails AND, for some n, the median.
raw docstring

asinhclj

(asinh x)

Numerically-stable inverse hyperbolic sine: sign(x)·ln(|x| + sqrt(x²+1)). Returns nil for nil or non-finite input. The textbook ln(x + sqrt(x²+1)) form suffers catastrophic cancellation for large negative x (x + sqrt(x²+1) → 0 → ln → -Inf), which silently turns legitimate large-negative growth into nil; computing on |x| and reapplying the sign is stable everywhere.

Numerically-stable inverse hyperbolic sine: sign(x)·ln(|x| + sqrt(x²+1)).
Returns nil for nil or non-finite input. The textbook ln(x + sqrt(x²+1)) form
suffers catastrophic cancellation for large negative x (x + sqrt(x²+1) → 0 →
ln → -Inf), which silently turns legitimate large-negative growth into nil;
computing on |x| and reapplying the sign is stable everywhere.
sourceraw docstring

finite-double?clj

(finite-double? x)

True for a non-nil, finite number — not nil, NaN, or ±Inf (R's is.finite).

True for a non-nil, finite number — not nil, NaN, or ±Inf (R's `is.finite`).
sourceraw docstring

quantile-type7clj

(quantile-type7 coll p)
(quantile-type7 coll p min-n)

R type-7 quantile of the finite values in coll at probability p (a fraction in [0,1]).

Drops nil and non-finite (NaN/±Inf) values, sorts ascending, and linearly interpolates at h = (n-1)p (0-indexed): for sorted x, lo = floor(h), result = x[lo] + (h-lo)·(x[lo+1] - x[lo]). Matches quantile(x, p, type = 7, na.rm = TRUE) in R.

Returns nil when no finite values remain, or — when min-n is supplied — when fewer than min-n finite values remain (R's if (length(x) < k) NA). min-n is floor-free by default; pass it only for rules like the peer-bands n>=11.

R type-7 quantile of the finite values in `coll` at probability `p` (a
fraction in [0,1]).

Drops nil and non-finite (NaN/±Inf) values, sorts ascending, and linearly
interpolates at h = (n-1)p (0-indexed): for sorted x, lo = floor(h),
result = x[lo] + (h-lo)·(x[lo+1] - x[lo]). Matches `quantile(x, p, type = 7,
na.rm = TRUE)` in R.

Returns nil when no finite values remain, or — when `min-n` is supplied — when
fewer than `min-n` finite values remain (R's `if (length(x) < k) NA`). `min-n`
is floor-free by default; pass it only for rules like the peer-bands n>=11.
sourceraw docstring

quantiles-of-doublesclj

(quantiles-of-doubles buf ps)
(quantiles-of-doubles buf ps min-n)

Type-7 quantiles of a primitive double-array, the allocation-light form for the group-by hot path: compacts the finite values (drops NaN/±Inf) to the front of buf in place, sorts that prefix, and reads each probability in ps off the one sort — no boxing, no intermediate collection. Mutates buf (it must be scratch the caller owns). ps may be a single number or a vector; returns a scalar or vector to match. nil under the empty / min-n rules of quantile-type7.

Type-7 quantiles of a primitive `double-array`, the allocation-light form for
the group-by hot path: compacts the finite values (drops NaN/±Inf) to the front
of `buf` in place, sorts that prefix, and reads each probability in `ps` off the
one sort — no boxing, no intermediate collection. **Mutates `buf`** (it must be
scratch the caller owns). `ps` may be a single number or a vector; returns a
scalar or vector to match. nil under the empty / `min-n` rules of quantile-type7.
sourceraw docstring

quantiles-type7clj

(quantiles-type7 coll ps)
(quantiles-type7 coll ps min-n)

Type-7 quantiles at several probabilities ps, sorting the finite values of coll once. Returns a vector aligned with ps (each element nil under the same empty / min-n rules as quantile-type7). This is the efficient form for the q20/median/q80 band idiom — one sort instead of three.

Type-7 quantiles at several probabilities `ps`, sorting the finite values of
`coll` **once**. Returns a vector aligned with `ps` (each element nil under the
same empty / `min-n` rules as `quantile-type7`). This is the efficient form for
the q20/median/q80 band idiom — one sort instead of three.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close