Class PSquarePercentile

java.lang.Object
org.hipparchus.stat.descriptive.AbstractStorelessUnivariateStatistic
org.hipparchus.stat.descriptive.rank.PSquarePercentile
All Implemented Interfaces:
Serializable, DoubleConsumer, StorelessUnivariateStatistic, UnivariateStatistic, MathArrays.Function

public class PSquarePercentile extends AbstractStorelessUnivariateStatistic implements StorelessUnivariateStatistic, Serializable
A StorelessUnivariateStatistic estimating percentiles using the P2 Algorithm as explained by Raj Jain and Imrich Chlamtac in P2 Algorithm for Dynamic Calculation of Quantiles and Histogram Without Storing Observations.

Note: This implementation is not synchronized and produces an approximate result. For small samples, where data can be stored and processed in memory, Percentile should be used.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static interface 
    An interface that encapsulates abstractions of the P-square algorithm markers as is explained in the original works.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a PSquarePercentile with the specific percentile value.
    Copy constructor, creates a new PSquarePercentile identical to the original.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the internal state of the Statistic
    Returns a copy of the statistic with the same internal state.
    boolean
    Returns true iff o is a PSquarePercentile returning the same values as this for getResult() and getN() and also having equal markers
    long
    Returns the number of values that have been added.
    double
    Get quantile estimated by this statistic.
    double
    Returns the current value of the Statistic.
    int
    Returns hash code based on getResult() and getN().
    void
    increment(double observation)
    Updates the internal state of the statistic to reflect the addition of the new value.
    newMarkers(List<Double> initialFive, double p)
    A creation method to build Markers
    double
    Returns the quantile estimated by this statistic in the range [0.0-1.0]
    Returns a string containing the last observation, the current estimate of the quantile and all markers.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.function.DoubleConsumer

    andThen

    Methods inherited from interface org.hipparchus.stat.descriptive.StorelessUnivariateStatistic

    accept, evaluate, incrementAll, incrementAll

    Methods inherited from interface org.hipparchus.stat.descriptive.UnivariateStatistic

    evaluate
  • Constructor Details

    • PSquarePercentile

      public PSquarePercentile(double p)
      Constructs a PSquarePercentile with the specific percentile value.
      Parameters:
      p - the percentile
      Throws:
      MathIllegalArgumentException - if p is not greater than 0 and less than or equal to 100
    • PSquarePercentile

      public PSquarePercentile(PSquarePercentile original)
      Copy constructor, creates a new PSquarePercentile identical to the original.
      Parameters:
      original - the PSquarePercentile instance to copy
      Throws:
      NullArgumentException - if original is null
  • Method Details

    • hashCode

      public int hashCode()
      Returns hash code based on getResult() and getN().
      Overrides:
      hashCode in class AbstractStorelessUnivariateStatistic
      Returns:
      hash code
    • equals

      public boolean equals(Object o)
      Returns true iff o is a PSquarePercentile returning the same values as this for getResult() and getN() and also having equal markers
      Overrides:
      equals in class AbstractStorelessUnivariateStatistic
      Parameters:
      o - object to compare
      Returns:
      true if o is a PSquarePercentile with equivalent internal state
    • increment

      public void increment(double observation)
      Updates the internal state of the statistic to reflect the addition of the new value.The internal state updated due to the new value in this context is basically of the marker positions and computation of the approximate quantile.
      Specified by:
      increment in interface StorelessUnivariateStatistic
      Specified by:
      increment in class AbstractStorelessUnivariateStatistic
      Parameters:
      observation - the observation currently being added.
    • toString

      public String toString()
      Returns a string containing the last observation, the current estimate of the quantile and all markers.
      Overrides:
      toString in class AbstractStorelessUnivariateStatistic
      Returns:
      string representation of state data
    • getN

      public long getN()
      Returns the number of values that have been added.
      Specified by:
      getN in interface StorelessUnivariateStatistic
      Returns:
      the number of values.
    • copy

      public PSquarePercentile copy()
      Returns a copy of the statistic with the same internal state.
      Specified by:
      copy in interface StorelessUnivariateStatistic
      Specified by:
      copy in interface UnivariateStatistic
      Specified by:
      copy in class AbstractStorelessUnivariateStatistic
      Returns:
      a copy of the statistic
    • quantile

      public double quantile()
      Returns the quantile estimated by this statistic in the range [0.0-1.0]
      Returns:
      quantile estimated by getResult()
    • clear

      public void clear()
      Clears the internal state of the Statistic. This basically clears all the markers, the initialFive list and sets countOfObservations to 0.
      Specified by:
      clear in interface StorelessUnivariateStatistic
      Specified by:
      clear in class AbstractStorelessUnivariateStatistic
    • getResult

      public double getResult()
      Returns the current value of the Statistic.
      Specified by:
      getResult in interface StorelessUnivariateStatistic
      Specified by:
      getResult in class AbstractStorelessUnivariateStatistic
      Returns:
      value of the statistic, Double.NaN if it has been cleared or just instantiated.
    • getQuantile

      public double getQuantile()
      Get quantile estimated by this statistic.
      Returns:
      the quantile estimated by this statistic
    • newMarkers

      public static PSquarePercentile.PSquareMarkers newMarkers(List<Double> initialFive, double p)
      A creation method to build Markers
      Parameters:
      initialFive - list of initial five elements
      p - the quantile desired
      Returns:
      an instance of PSquareMarkers