Interface QuantilesGenericAPI<T>
-
- Type Parameters:
T
- The given item type
- All Superinterfaces:
PartitioningFeature<T>
,QuantilesAPI
,SketchPartitionLimits
- All Known Implementing Classes:
ItemsSketch
,KllItemsSketch
public interface QuantilesGenericAPI<T> extends QuantilesAPI, PartitioningFeature<T>, SketchPartitionLimits
The Quantiles API for item type generic.- Author:
- Lee Rhodes
- See Also:
QuantilesAPI
-
-
Field Summary
-
Fields inherited from interface org.apache.datasketches.quantilescommon.QuantilesAPI
EMPTY_MSG, MEM_REQ_SVR_NULL_MSG, NOT_SINGLE_ITEM_MSG, SELF_MERGE_MSG, TGT_IS_READ_ONLY_MSG, UNSUPPORTED_MSG
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default double[]
getCDF(T[] splitPoints)
This is equivalent togetCDF(splitPoints, INCLUSIVE)
double[]
getCDF(T[] splitPoints, QuantileSearchCriteria searchCrit)
Returns an approximation to the Cumulative Distribution Function (CDF) of the input stream as a monotonically increasing array of double ranks (or cumulative probabilities) on the interval [0.0, 1.0], given a set of splitPoints.Class<T>
getClassOfT()
Comparator<? super T>
getComparator()
Returns the Comparator of TT
getMaxItem()
Returns the maximum item of the stream.default int
getMaxPartitions()
Gets the maximum number of partitions this sketch will support based on the configured size K and the number of retained values of this sketch.T
getMinItem()
Returns the minimum item of the stream.default double[]
getPMF(T[] splitPoints)
This is equivalent togetPMF(splitPoints, INCLUSIVE)
double[]
getPMF(T[] splitPoints, QuantileSearchCriteria searchCrit)
Returns an approximation to the Probability Mass Function (PMF) of the input stream as an array of probability masses as doubles on the interval [0.0, 1.0], given a set of splitPoints.default T
getQuantile(double rank)
This is equivalent togetQuantile(rank, INCLUSIVE)
T
getQuantile(double rank, QuantileSearchCriteria searchCrit)
Gets the approximate quantile of the given normalized rank and the given search criterion.T
getQuantileLowerBound(double rank)
Gets the lower bound of the quantile confidence interval in which the quantile of the given rank exists.default T[]
getQuantiles(double[] ranks)
This is equivalent togetQuantiles(ranks, INCLUSIVE)
T[]
getQuantiles(double[] ranks, QuantileSearchCriteria searchCrit)
Gets an array of quantiles from the given array of normalized ranks.T
getQuantileUpperBound(double rank)
Gets the upper bound of the quantile confidence interval in which the true quantile of the given rank exists.default double
getRank(T quantile)
This is equivalent togetRank(T quantile, INCLUSIVE)
double
getRank(T quantile, QuantileSearchCriteria searchCrit)
Gets the normalized rank corresponding to the given a quantile.default double[]
getRanks(T[] quantiles)
This is equivalent togetRanks(quantiles, INCLUSIVE)
double[]
getRanks(T[] quantiles, QuantileSearchCriteria searchCrit)
Gets an array of normalized ranks corresponding to the given array of quantiles and the given search criterion.GenericSortedView<T>
getSortedView()
Gets the sorted view of this sketchQuantilesGenericSketchIterator<T>
iterator()
Gets the iterator for this sketch, which is not sorted.void
update(T item)
Updates this sketch with the given item.-
Methods inherited from interface org.apache.datasketches.quantilescommon.PartitioningFeature
getPartitionBoundariesFromNumParts, getPartitionBoundariesFromNumParts, getPartitionBoundariesFromPartSize, getPartitionBoundariesFromPartSize
-
Methods inherited from interface org.apache.datasketches.quantilescommon.QuantilesAPI
getK, getN, getNormalizedRankError, getNumRetained, getRankLowerBound, getRankUpperBound, hasMemory, isDirect, isEmpty, isEstimationMode, isReadOnly, reset, toString
-
Methods inherited from interface org.apache.datasketches.quantilescommon.SketchPartitionLimits
getMinPartitionSizeItems, getN
-
-
-
-
Method Detail
-
getCDF
default double[] getCDF(T[] splitPoints)
This is equivalent togetCDF(splitPoints, INCLUSIVE)
- Parameters:
splitPoints
- an array of m unique, monotonically increasing items.- Returns:
- a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
- Throws:
IllegalArgumentException
- if sketch is empty.
-
getCDF
double[] getCDF(T[] splitPoints, QuantileSearchCriteria searchCrit)
Returns an approximation to the Cumulative Distribution Function (CDF) of the input stream as a monotonically increasing array of double ranks (or cumulative probabilities) on the interval [0.0, 1.0], given a set of splitPoints.The resulting approximations have a probabilistic guarantee that can be obtained from the getNormalizedRankError(false) function.
- Parameters:
splitPoints
- an array of m unique, monotonically increasing items (of the same type as the input items) that divide the item input domain into m+1 overlapping intervals.The start of each interval is below the lowest item retained by the sketch corresponding to a zero rank or zero probability, and the end of the interval is the rank or cumulative probability corresponding to the split point.
The (m+1)th interval represents 100% of the distribution represented by the sketch and consistent with the definition of a cumulative probability distribution, thus the (m+1)th rank or probability in the returned array is always 1.0.
If a split point exactly equals a retained item of the sketch and the search criterion is:
- INCLUSIVE, the resulting cumulative probability will include that item.
- EXCLUSIVE, the resulting cumulative probability will not include the weight of that split point.
It is not recommended to include either the minimum or maximum items of the input stream.
searchCrit
- the desired search criteria.- Returns:
- a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
- Throws:
IllegalArgumentException
- if sketch is empty.
-
getComparator
Comparator<? super T> getComparator()
Returns the Comparator of T- Returns:
- Comparator of the sketch
-
getMaxItem
T getMaxItem()
Returns the maximum item of the stream. This may be distinct from the largest item retained by the sketch algorithm.- Returns:
- the maximum item of the stream
- Throws:
IllegalArgumentException
- if sketch is empty.
-
getMaxPartitions
default int getMaxPartitions()
Description copied from interface:SketchPartitionLimits
Gets the maximum number of partitions this sketch will support based on the configured size K and the number of retained values of this sketch.- Specified by:
getMaxPartitions
in interfaceSketchPartitionLimits
- Returns:
- the maximum number of partitions this sketch will support.
-
getMinItem
T getMinItem()
Returns the minimum item of the stream. This may be distinct from the smallest item retained by the sketch algorithm.- Returns:
- the minimum item of the stream
- Throws:
IllegalArgumentException
- if sketch is empty.
-
getPMF
default double[] getPMF(T[] splitPoints)
This is equivalent togetPMF(splitPoints, INCLUSIVE)
- Parameters:
splitPoints
- an array of m unique, monotonically increasing items.- Returns:
- a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
- Throws:
IllegalArgumentException
- if sketch is empty.
-
getPMF
double[] getPMF(T[] splitPoints, QuantileSearchCriteria searchCrit)
Returns an approximation to the Probability Mass Function (PMF) of the input stream as an array of probability masses as doubles on the interval [0.0, 1.0], given a set of splitPoints.The resulting approximations have a probabilistic guarantee that can be obtained from the getNormalizedRankError(true) function.
- Parameters:
splitPoints
- an array of m unique, monotonically increasing items (of the same type as the input items) that divide the item input domain into m+1 consecutive, non-overlapping intervals.Each interval except for the end intervals starts with a split point and ends with the next split point in sequence.
The first interval starts below the lowest item retained by the sketch corresponding to a zero rank or zero probability, and ends with the first split point
The last (m+1)th interval starts with the last split point and ends after the last item retained by the sketch corresponding to a rank or probability of 1.0.
The sum of the probability masses of all (m+1) intervals is 1.0.
If the search criterion is:
- INCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval will include that item. If the lower split point equals an item retained by the sketch, the interval will exclude that item.
- EXCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval will exclude that item. If the lower split point equals an item retained by the sketch, the interval will include that item.
It is not recommended to include either the minimum or maximum items of the input stream.
searchCrit
- the desired search criteria.- Returns:
- a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
- Throws:
IllegalArgumentException
- if sketch is empty.
-
getQuantile
default T getQuantile(double rank)
This is equivalent togetQuantile(rank, INCLUSIVE)
- Parameters:
rank
- the given normalized rank, a double in the range [0.0, 1.0].- Returns:
- the approximate quantile given the normalized rank.
- Throws:
IllegalArgumentException
- if sketch is empty.
-
getQuantile
T getQuantile(double rank, QuantileSearchCriteria searchCrit)
Gets the approximate quantile of the given normalized rank and the given search criterion.- Parameters:
rank
- the given normalized rank, a double in the range [0.0, 1.0].searchCrit
- If INCLUSIVE, the given rank includes all quantiles ≤ the quantile directly corresponding to the given rank. If EXCLUSIVE, he given rank includes all quantiles < the quantile directly corresponding to the given rank.- Returns:
- the approximate quantile given the normalized rank.
- Throws:
IllegalArgumentException
- if sketch is empty.- See Also:
QuantileSearchCriteria
-
getQuantileLowerBound
T getQuantileLowerBound(double rank)
Gets the lower bound of the quantile confidence interval in which the quantile of the given rank exists.Although it is possible to estimate the probability that the true quantile exists within the quantile confidence interval specified by the upper and lower quantile bounds, it is not possible to guarantee the width of the quantile confidence interval as an additive or multiplicative percent of the true quantile.
- Parameters:
rank
- the given normalized rank- Returns:
- the lower bound of the quantile confidence interval in which the quantile of the given rank exists.
- Throws:
IllegalArgumentException
- if sketch is empty.
-
getQuantileUpperBound
T getQuantileUpperBound(double rank)
Gets the upper bound of the quantile confidence interval in which the true quantile of the given rank exists.Although it is possible to estimate the probability that the true quantile exists within the quantile confidence interval specified by the upper and lower quantile bounds, it is not possible to guarantee the width of the quantile interval as an additive or multiplicative percent of the true quantile.
- Parameters:
rank
- the given normalized rank- Returns:
- the upper bound of the quantile confidence interval in which the true quantile of the given rank exists.
- Throws:
IllegalArgumentException
- if sketch is empty.
-
getQuantiles
default T[] getQuantiles(double[] ranks)
This is equivalent togetQuantiles(ranks, INCLUSIVE)
- Parameters:
ranks
- the given array of normalized ranks, each of which must be in the interval [0.0,1.0].- Returns:
- an array of quantiles corresponding to the given array of normalized ranks.
- Throws:
IllegalArgumentException
- if sketch is empty.
-
getQuantiles
T[] getQuantiles(double[] ranks, QuantileSearchCriteria searchCrit)
Gets an array of quantiles from the given array of normalized ranks.- Parameters:
ranks
- the given array of normalized ranks, each of which must be in the interval [0.0,1.0].searchCrit
- if INCLUSIVE, the given ranks include all quantiles ≤ the quantile directly corresponding to each rank.- Returns:
- an array of quantiles corresponding to the given array of normalized ranks.
- Throws:
IllegalArgumentException
- if sketch is empty.- See Also:
QuantileSearchCriteria
-
getRank
default double getRank(T quantile)
This is equivalent togetRank(T quantile, INCLUSIVE)
- Parameters:
quantile
- the given quantile- Returns:
- the normalized rank corresponding to the given quantile.
- Throws:
IllegalArgumentException
- if sketch is empty.
-
getRank
double getRank(T quantile, QuantileSearchCriteria searchCrit)
Gets the normalized rank corresponding to the given a quantile.- Parameters:
quantile
- the given quantilesearchCrit
- if INCLUSIVE the given quantile is included into the rank.- Returns:
- the normalized rank corresponding to the given quantile.
- Throws:
IllegalArgumentException
- if sketch is empty.- See Also:
QuantileSearchCriteria
-
getRanks
default double[] getRanks(T[] quantiles)
This is equivalent togetRanks(quantiles, INCLUSIVE)
- Parameters:
quantiles
- the given array of quantiles- Returns:
- an array of normalized ranks corresponding to the given array of quantiles.
- Throws:
IllegalArgumentException
- if sketch is empty.
-
getRanks
double[] getRanks(T[] quantiles, QuantileSearchCriteria searchCrit)
Gets an array of normalized ranks corresponding to the given array of quantiles and the given search criterion.- Parameters:
quantiles
- the given array of quantilessearchCrit
- if INCLUSIVE, the given quantiles include the rank directly corresponding to each quantile.- Returns:
- an array of normalized ranks corresponding to the given array of quantiles.
- Throws:
IllegalArgumentException
- if sketch is empty.- See Also:
QuantileSearchCriteria
-
getSortedView
GenericSortedView<T> getSortedView()
Gets the sorted view of this sketch- Returns:
- the sorted view of this sketch
-
iterator
QuantilesGenericSketchIterator<T> iterator()
Gets the iterator for this sketch, which is not sorted.- Returns:
- the iterator for this sketch
-
update
void update(T item)
Updates this sketch with the given item.- Parameters:
item
- from a stream of items. Nulls are ignored.
-
-