Class PercentileDigest

java.lang.Object
dev.frostlake.functions.aggregate.PercentileDigest

public class PercentileDigest extends Object
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
    Modifier and Type
    Field
    Description
    static final String
    The type member a state carries.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Takes every centroid of another digest.
    void
    add(double value)
    Adds one input value as a centroid of weight 1.
    void
    addCentroid(double mean, double weight)
     
    estimate(double fraction)
    The estimated value at a fraction between 0 and 1, or null over an empty digest.
    boolean
     
    static double
    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.
    parse(Object value)
    Reads a state, or refuses the argument as live does when it is not one.
    The state as an OBJECT value, centroids sorted by mean.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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

      public void absorb(PercentileDigest other)
      Takes every centroid of another digest.
    • parse

      public static PercentileDigest parse(Object value)
      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

      public VariantValue toState()
      The state as an OBJECT value, centroids sorted by mean.
    • estimate

      public Double estimate(double fraction)
      The estimated value at a fraction between 0 and 1, or null over an empty digest.
      Parameters:
      fraction - the percentile
      Returns:
      the estimate
    • numericInput

      public static double numericInput(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.
      Parameters:
      value - the input, not null
      Returns:
      the double