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
Modifier and TypeClassDescriptionprotected static interface
An interface that encapsulates abstractions of the P-square algorithm markers as is explained in the original works. -
Constructor Summary
ConstructorDescriptionPSquarePercentile
(double p) Constructs a PSquarePercentile with the specific percentile value.PSquarePercentile
(PSquarePercentile original) Copy constructor, creates a newPSquarePercentile
identical to theoriginal
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the internal state of the Statisticcopy()
Returns a copy of the statistic with the same internal state.boolean
Returns true iffo
is aPSquarePercentile
returning the same values as this forgetResult()
andgetN()
and also having equal markerslong
getN()
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
hashCode()
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 Markersdouble
quantile()
Returns the quantile estimated by this statistic in the range [0.0-1.0]toString()
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
Copy constructor, creates a newPSquarePercentile
identical to theoriginal
.- Parameters:
original
- thePSquarePercentile
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 classAbstractStorelessUnivariateStatistic
- Returns:
- hash code
-
equals
Returns true iffo
is aPSquarePercentile
returning the same values as this forgetResult()
andgetN()
and also having equal markers- Overrides:
equals
in classAbstractStorelessUnivariateStatistic
- Parameters:
o
- object to compare- Returns:
- true if
o
is aPSquarePercentile
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 interfaceStorelessUnivariateStatistic
- Specified by:
increment
in classAbstractStorelessUnivariateStatistic
- Parameters:
observation
- the observation currently being added.
-
toString
Returns a string containing the last observation, the current estimate of the quantile and all markers.- Overrides:
toString
in classAbstractStorelessUnivariateStatistic
- Returns:
- string representation of state data
-
getN
public long getN()Returns the number of values that have been added.- Specified by:
getN
in interfaceStorelessUnivariateStatistic
- Returns:
- the number of values.
-
copy
Returns a copy of the statistic with the same internal state.- Specified by:
copy
in interfaceStorelessUnivariateStatistic
- Specified by:
copy
in interfaceUnivariateStatistic
- Specified by:
copy
in classAbstractStorelessUnivariateStatistic
- 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 interfaceStorelessUnivariateStatistic
- Specified by:
clear
in classAbstractStorelessUnivariateStatistic
-
getResult
public double getResult()Returns the current value of the Statistic.- Specified by:
getResult
in interfaceStorelessUnivariateStatistic
- Specified by:
getResult
in classAbstractStorelessUnivariateStatistic
- 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
A creation method to build Markers- Parameters:
initialFive
- list of initial five elementsp
- the quantile desired- Returns:
- an instance of PSquareMarkers
-