math
Distribution sampling, stream-hash functions, and Cholesky factorization used by statistical models. Vector and matrix storage, arithmetic, and triangular solves live in the separate koblas BLAS library (com.eignex.koblas).
Cholesky factorization
factorCholesky factors the finite lower triangle of a symmetric positive-definite matrix into an owned CholeskyFactor. The factor solves vector and matrix systems, provides a log determinant, and returns an independent lower-triangular copy. Allocating operations preserve inputs. CholeskyFactor.solveInto and CholeskyFactor.solveLowerInto write to supplied destinations, which may alias the right-hand side. Separate calls can reuse a workspace serially; concurrent calls need independent workspaces and destinations. The factor remains unchanged. CholeskyFactor.rankUpdated adds an outer product and CholeskyFactor.extended appends a block, each returning an owned factor. Factorization adds no jitter or regularization; NotPositiveDefinite identifies a failed pivot for callers choosing a retry policy.
Distribution sampling
Convenience extensions on kotlin.random.Random, delegating to util's shared samplers:
nextNormal(mean, std): Gaussian. Used by Thompson-sampling posteriors throughout the bandit and regression layers.nextGamma(alpha): gamma. Building block for Beta / Dirichlet.nextBeta(alpha, beta): beta. Used by Beta-Bernoulli posteriors.nextPoissonOne(): Poisson(1). Used by Oza & Russell online bagging in RandomForestRegressionStat.
These are mostly internal to the library but exposed in case downstream code wants the same well-tested implementations.
Quasi-Monte Carlo integration
SobolSequence generates uniform or standard-normal integration points. A seed applies left linear matrix scrambling and a digital shift; null selects the unscrambled sequence. Use powers-of-two sample blocks from the beginning and independent seeds for error estimates. These points are dependent integration samples, not independent observations for a statistical model.
Coordinate and sample prefixes remain fixed when dimensions grow. dimensionOffset selects a contiguous projection, so a consumer can construct additional normal coordinates while retaining an existing common-sample cache. The engine supports 1,024 global coordinates and 2^52 points; normal samples use 52-bit cell midpoints and an inverse CDF to keep endpoints finite.
val sequence = SobolSequence(dimensions = 4, scrambleSeed = 17L)
val point = DoubleArray(4)
repeat(1024) {
sequence.nextNormal(point)
// Evaluate an integrand at point before reusing this storage.
}Direction numbers are the first 1,024 coordinates of the Joe-Kuo D(6) table. Normal quantiles use Wichura's AS 241 coefficients from John Burkardt's ASA241 distribution. The implementation and its BSD and MIT notices are provided by the util dependency.
Hash functions
The streaming sketches and cardinality estimators (com.eignex.kumulant.stat.cardinality, com.eignex.kumulant.stat.sketch) need their input to carry uniform 64-bit entropy. The JVM's Object.hashCode() only provides 32 bits and tends to be biased for low-cardinality domains, so the hash pre-step is the right way to feed opaque keys into those sketches.
| Function / type | Role |
|---|---|
| hash64 | 64-bit hash of a ByteArray (or String via UTF-8): SplitMix64 over 8-byte chunks, stable across platforms. |
| splitmix64 | Bit-mixing 64-bit integer transform. Used internally and exposed for completeness. |
Note that these are non-cryptographic; passes BigCrush but is not collision-resistant. Use a cryptographic hash function for adversarial input.
Types
An owned lower Cholesky factor L of a symmetric positive-definite matrix A = L Lᵀ.
Typed, serializable reference to a LongHasher by name. Carried by the discrete sketch specs and results in place of a bare string, and resolved to a live mixer via Hashers.resolve. Serializes transparently as its name, so the wire form stays a plain string and needs no custom serializer.
Registry resolving a LongHasher.name back to its live implementation. The sketch families serialize only the mixer's name; resolve reconstructs the function when a spec is materialized or a sketch result is queried. SplitMix64 is pre-registered.
Pluggable Long -> Long mixer used by the discrete sketch family (HyperLogLog, BloomFilter, CountMinSketch) to spread a key's bits across the full 64-bit range before bucketing. Distinct from hash64 (ByteArray -> Long): callers reduce a domain key to a Long first (e.g. via hash64), and the sketch then mixes that Long through here.
A Cholesky factorization failed at pivotIndex with the corrected diagonal value pivot.
Sobol points in Gray-code order using the Joe-Kuo D(6) direction numbers.
Properties
Default LongHasher: the library's splitmix64 mixer. Pre-registered with Hashers.
Functions
Factor the lower triangle of this square symmetric matrix as A = L Lᵀ.
Factor the lower triangle into an owned CholeskyFactor, lending workspace to the numerical kernels.
64-bit hash of bytes for cardinality / sketch families: SplitMix64 over 8-byte little-endian chunks, folding tail bytes in last and seeding with the input length so zero-prefixed inputs of different lengths hash distinctly. Stable byte-for-byte across platforms.
UTF-8 byte hash convenience over hash64.
Knuth's Poisson sampler at lambda=1; returns 0/1/2/... with mass e^{-1} / k!.
SplitMix64 - a fast, high-quality 64-bit mixer suitable for spreading sequential or low-entropy keys into a uniform 64-bit hash before feeding them to cardinality sketches. Output passes BigCrush; not collision-resistant (use a cryptographic hash if adversarial input is a concern).