Class Numerics
java.lang.Object
com.quantfinlib.stats.Numerics
Small array and scalar helpers: clamping, NaN-filled arrays, the
half-life decay factor and an allocation-free paired sort.
Added in 2.4.0 as the home of these helpers from
util.MathUtils (removed in 3.0); behaviour is unchanged.
- Since:
- 2.4.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic doubleclamp(double v, double lo, double hi) max(lo, min(hi, v)); NaN in gives NaN out, andlo > hiis not checked.static doubledecayFactor(long dtNanos, long halfLifeNanos) Exponential decay factor for a half-life over an elapsed interval:exp(-dt·ln2/halfLife); 1.0 for non-positivedt.static double[]nanArray(int n) A new array of lengthnfilled with NaN.static voidpairSort(double[] keys, int[] values) Sortskeysascending while permutingvaluesidentically — the primitive replacement for boxing anInteger[]index array through a comparator sort (no allocation beyond the caller's arrays, no boxed compares).
-
Method Details
-
pairSort
public static void pairSort(double[] keys, int[] values) Sortskeysascending while permutingvaluesidentically — the primitive replacement for boxing anInteger[]index array through a comparator sort (no allocation beyond the caller's arrays, no boxed compares). Quicksort with median-of-three pivots and an insertion cutoff; NaN keys are not supported (callers filter NaN before ranking/selecting). -
clamp
public static double clamp(double v, double lo, double hi) max(lo, min(hi, v)); NaN in gives NaN out, andlo > hiis not checked. -
nanArray
public static double[] nanArray(int n) A new array of lengthnfilled with NaN. -
decayFactor
public static double decayFactor(long dtNanos, long halfLifeNanos) Exponential decay factor for a half-life over an elapsed interval:exp(-dt·ln2/halfLife); 1.0 for non-positivedt. The single home for the half-life→decay conversion the streaming estimators use — the ln2 factor is exactly the constant that goes missing when this is re-spelled per class.
-