Class PSquarePercentile
java.lang.Object
org.apache.commons.math3.stat.descriptive.AbstractUnivariateStatistic
org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic
org.apache.commons.math3.stat.descriptive.rank.PSquarePercentile
- All Implemented Interfaces:
Serializable,StorelessUnivariateStatistic,UnivariateStatistic,MathArrays.Function
public class PSquarePercentile
extends AbstractStorelessUnivariateStatistic
implements StorelessUnivariateStatistic, Serializable
A
StorelessUnivariateStatistic estimating percentiles using the
invalid input: '<'ahref=http://www.cs.wustl.edu/~jain/papers/ftp/psqr.pdf>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 ClassesModifier and TypeClassDescriptionprivate static classA simple fixed capacity list that has an upper bound to growth.private static classThe class modeling the attributes of the marker of the P-square algorithmprivate static classMarkers is an encapsulation of the five markers/buckets as indicated in the original works.protected static interfaceAn interface that encapsulates abstractions of the P-square algorithm markers as is explained in the original works. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longCounter to count the values/observations accepted into this data setprivate static final DecimalFormatA decimal formatter for print convenienceprivate static final doubleA Default quantile needed in case if user prefers to use default no argument constructor.Initial list of 5 numbers corresponding to 5 markers.private doublelastObservation is the last observation value/input sample.private PSquarePercentile.PSquareMarkersMarkers is the marker collection object which comes to effect only after 5 values are insertedprivate static final intThe maximum array size used for psquare algorithmprivate doubleComputed p value (i,e percentile value of data set hither to received)private final doubleThe quantile needed should be in range of 0-1.private static final longSerial ID -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor that assumes adefault quantileneededPSquarePercentile(double p) Constructs a PSquarePercentile with the specific percentile value. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the internal state of the Statisticcopy()Returns a copy of the statistic with the same internal state.booleanReturns true iffois aPSquarePercentilereturning the same values as this forgetResult()andgetN()and also having equal markerslonggetN()Returns the number of values that have been added.doubleReturns the current value of the Statistic.inthashCode()Returns hash code based on getResult() and getN()voidincrement(double observation) Updates the internal state of the statistic to reflect the addition of the new value.private doublemaximum()private doubleminimum()newMarkers(List<Double> initialFive, double p) A creation method to build Markersdoublequantile()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 org.apache.commons.math3.stat.descriptive.AbstractStorelessUnivariateStatistic
evaluate, evaluate, incrementAll, incrementAllMethods inherited from class org.apache.commons.math3.stat.descriptive.AbstractUnivariateStatistic
evaluate, getData, getDataRef, setData, setData, test, test, test, testMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic
incrementAll, incrementAllMethods inherited from interface org.apache.commons.math3.stat.descriptive.UnivariateStatistic
evaluate, evaluate
-
Field Details
-
PSQUARE_CONSTANT
private static final int PSQUARE_CONSTANTThe maximum array size used for psquare algorithm- See Also:
-
DEFAULT_QUANTILE_DESIRED
private static final double DEFAULT_QUANTILE_DESIREDA Default quantile needed in case if user prefers to use default no argument constructor.- See Also:
-
serialVersionUID
private static final long serialVersionUIDSerial ID- See Also:
-
DECIMAL_FORMAT
A decimal formatter for print convenience -
initialFive
Initial list of 5 numbers corresponding to 5 markers. NOTE:watch out for the add methods that are overloaded -
quantile
private final double quantileThe quantile needed should be in range of 0-1. The constructorPSquarePercentile(double)ensures that passed in percentile is divided by 100. -
lastObservation
private transient double lastObservationlastObservation is the last observation value/input sample. No need to serialize -
markers
Markers is the marker collection object which comes to effect only after 5 values are inserted -
pValue
private double pValueComputed p value (i,e percentile value of data set hither to received) -
countOfObservations
private long countOfObservationsCounter to count the values/observations accepted into this data set
-
-
Constructor Details
-
PSquarePercentile
public PSquarePercentile(double p) Constructs a PSquarePercentile with the specific percentile value.- Parameters:
p- the percentile- Throws:
OutOfRangeException- if p is not greater than 0 and less than or equal to 100
-
PSquarePercentile
PSquarePercentile()Default constructor that assumes adefault quantileneeded
-
-
Method Details
-
hashCode
public int hashCode()Returns hash code based on getResult() and getN()- Overrides:
hashCodein classAbstractStorelessUnivariateStatistic- Returns:
- hash code
-
equals
Returns true iffois aPSquarePercentilereturning the same values as this forgetResult()andgetN()and also having equal markers- Overrides:
equalsin classAbstractStorelessUnivariateStatistic- Parameters:
o- object to compare- Returns:
- true if
ois aPSquarePercentilewith 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:
incrementin interfaceStorelessUnivariateStatistic- Specified by:
incrementin 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. -
getN
public long getN()Returns the number of values that have been added.- Specified by:
getNin interfaceStorelessUnivariateStatistic- Returns:
- the number of values.
-
copy
Returns a copy of the statistic with the same internal state.- Specified by:
copyin interfaceStorelessUnivariateStatistic- Specified by:
copyin interfaceUnivariateStatistic- Specified by:
copyin 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:
clearin interfaceStorelessUnivariateStatistic- Specified by:
clearin classAbstractStorelessUnivariateStatistic
-
getResult
public double getResult()Returns the current value of the Statistic.- Specified by:
getResultin interfaceStorelessUnivariateStatistic- Specified by:
getResultin classAbstractStorelessUnivariateStatistic- Returns:
- value of the statistic,
Double.NaNif it has been cleared or just instantiated.
-
maximum
private double maximum()- Returns:
- maximum in the data set added to this statistic
-
minimum
private double minimum()- Returns:
- minimum in the data set added to this statistic
-
newMarkers
A creation method to build Markers- Parameters:
initialFive- list of initial five elementsp- the quantile desired- Returns:
- an instance of PSquareMarkers
-