Class TDigestDouble


  • public final class TDigestDouble
    extends Object
    t-Digest for estimating quantiles and ranks. This implementation is based on the following paper: Ted Dunning, Otmar Ertl. Extremely Accurate Quantiles Using t-Digests and the following implementation: https://github.com/tdunning/t-digest This implementation is similar to MergingDigest in the above implementation
    • Field Detail

      • DEFAULT_K

        public static final short DEFAULT_K
        the default value of K if one is not specified
        See Also:
        Constant Field Values
    • Constructor Detail

      • TDigestDouble

        public TDigestDouble()
        Constructor with the default K
      • TDigestDouble

        public TDigestDouble​(short k)
        Constructor
        Parameters:
        k - affects the size of TDigest and its estimation error
    • Method Detail

      • getK

        public short getK()
        Returns:
        parameter k (compression) that was used to configure this TDigest
      • update

        public void update​(double value)
        Update this TDigest with the given value
        Parameters:
        value - to update the TDigest with
      • merge

        public void merge​(TDigestDouble other)
        Merge the given TDigest into this one
        Parameters:
        other - TDigest to merge
      • compress

        public void compress()
        Process buffered values and merge centroids if needed
      • isEmpty

        public boolean isEmpty()
        Returns:
        true if TDigest has not seen any data
      • getMinValue

        public double getMinValue()
        Returns:
        minimum value seen by TDigest
      • getMaxValue

        public double getMaxValue()
        Returns:
        maximum value seen by TDigest
      • getTotalWeight

        public long getTotalWeight()
        Returns:
        total weight
      • getRank

        public double getRank​(double value)
        Compute approximate normalized rank of the given value.
        Parameters:
        value - to be ranked
        Returns:
        normalized rank (from 0 to 1 inclusive)
      • getQuantile

        public double getQuantile​(double rank)
        Compute approximate quantile value corresponding to the given normalized rank
        Parameters:
        rank - normalized rank (from 0 to 1 inclusive)
        Returns:
        quantile value corresponding to the given rank
      • toByteArray

        public byte[] toByteArray()
        Serialize this TDigest to a byte array form.
        Returns:
        byte array
      • heapify

        public static TDigestDouble heapify​(org.apache.datasketches.memory.Memory mem)
        Deserialize TDigest from a given memory. Supports reading format of the reference implementation (autodetected).
        Parameters:
        mem - instance of Memory
        Returns:
        an instance of TDigest
      • heapify

        public static TDigestDouble heapify​(org.apache.datasketches.memory.Memory mem,
                                            boolean isFloat)
        Deserialize TDigest from a given memory. Supports reading compact format with (float, int) centroids as opposed to (double, long) to represent (mean, weight). Supports reading format of the reference implementation (autodetected).
        Parameters:
        mem - instance of Memory
        isFloat - if true the input represents (float, int) format
        Returns:
        an instance of TDigest
      • toString

        public String toString()
        Human-readable summary of this TDigest as a string
        Overrides:
        toString in class Object
        Returns:
        summary of this TDigest
      • toString

        public String toString​(boolean printCentroids)
        Human-readable summary of this TDigest as a string
        Parameters:
        printCentroids - if true append the list of centroids with weights
        Returns:
        summary of this TDigest