Class PercentileDigest
java.lang.Object
dev.frostlake.functions.aggregate.PercentileDigest
The percentile digest behind APPROX_PERCENTILE_ACCUMULATE, _COMBINE and _ESTIMATE: a list of
centroids (mean, weight) serialised as
{"state":[mean, weight, mean, weight, …],
"type":"tdigest","version":1}, means ascending, every number in the fifteen-decimal exponent form
a DOUBLE takes inside a VARIANT. The engine never compresses: every input value is its own centroid
of weight 1, exactly what the account returns below roughly a thousand values, where it begins to
merge neighbours.
The estimate, live-verified in both regimes: over centroids that ALL weigh 1 it is the exact
interpolated percentile — position fraction × (n − 1) between the sorted values, the same
number APPROX_PERCENTILE gives — while a state holding any other weight is read as a digest: the
target rank fraction × total weight is placed among the centroids' mean positions
(weight before + weight / 2) and interpolated linearly, extrapolated along the end segments
past the first or last centroid, so [1 ×1, 9 ×3] estimates 3 at 0.25, 0.6 at 0.1 and 13.4
at 0.9. A single centroid is its own mean; an empty digest estimates NULL.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidabsorb(PercentileDigest other) Takes every centroid of another digest.voidadd(double value) Adds one input value as a centroid of weight 1.voidaddCentroid(double mean, double weight) estimate(double fraction) The estimated value at a fraction between 0 and 1, or null over an empty digest.booleanisEmpty()static doublenumericInput(Object value) A value an accumulating call was given, as the double a centroid records — a number by its value, a VARIANT by its member, text by what it spells — or the row-time refusal live gives.static PercentileDigestReads a state, or refuses the argument as live does when it is not one.toState()The state as an OBJECT value, centroids sorted by mean.
-
Field Details
-
STATE_TYPE
Thetypemember a state carries.- See Also:
-
-
Constructor Details
-
PercentileDigest
public PercentileDigest()
-
-
Method Details
-
isEmpty
public boolean isEmpty() -
add
public void add(double value) Adds one input value as a centroid of weight 1. -
addCentroid
public void addCentroid(double mean, double weight) -
absorb
Takes every centroid of another digest. -
parse
Reads a state, or refuses the argument as live does when it is not one.- Parameters:
value- the argument- Returns:
- the digest it holds
-
toState
The state as an OBJECT value, centroids sorted by mean. -
estimate
The estimated value at a fraction between 0 and 1, or null over an empty digest.- Parameters:
fraction- the percentile- Returns:
- the estimate
-
numericInput
A value an accumulating call was given, as the double a centroid records — a number by its value, a VARIANT by its member, text by what it spells — or the row-time refusal live gives.- Parameters:
value- the input, not null- Returns:
- the double
-