Class Median
- java.lang.Object
-
- org.apache.commons.math3.stat.descriptive.AbstractUnivariateStatistic
-
- org.apache.commons.math3.stat.descriptive.rank.Percentile
-
- org.apache.commons.math3.stat.descriptive.rank.Median
-
- All Implemented Interfaces:
java.io.Serializable
,UnivariateStatistic
,MathArrays.Function
public class Median extends Percentile implements java.io.Serializable
Returns the median of the available values. This is the same as the 50th percentile. SeePercentile
for a description of the algorithm used.Note that this implementation is not synchronized. If multiple threads access an instance of this class concurrently, and at least one of the threads invokes the
increment()
orclear()
method, it must be synchronized externally.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.commons.math3.stat.descriptive.rank.Percentile
Percentile.EstimationType
-
-
Field Summary
Fields Modifier and Type Field Description private static double
FIXED_QUANTILE_50
Fixed quantile.private static long
serialVersionUID
Serializable version identifier
-
Constructor Summary
Constructors Modifier Constructor Description Median()
Default constructor.Median(Median original)
Copy constructor, creates a newMedian
identical to theoriginal
private
Median(Percentile.EstimationType estimationType, NaNStrategy nanStrategy, KthSelector kthSelector)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Median
withEstimationType(Percentile.EstimationType newEstimationType)
Build a new instance similar to the current one except for theestimation type
.Median
withKthSelector(KthSelector newKthSelector)
Build a new instance similar to the current one except for thekthSelector
instance specifically set.Median
withNaNStrategy(NaNStrategy newNaNStrategy)
Build a new instance similar to the current one except for theNaN handling
strategy.-
Methods inherited from class org.apache.commons.math3.stat.descriptive.rank.Percentile
copy, copy, evaluate, evaluate, evaluate, evaluate, getEstimationType, getKthSelector, getNaNStrategy, getPivotingStrategy, getQuantile, getWorkArray, medianOf3, setData, setData, setQuantile
-
Methods inherited from class org.apache.commons.math3.stat.descriptive.AbstractUnivariateStatistic
evaluate, evaluate, getData, getDataRef, test, test, test, test
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serializable version identifier- See Also:
- Constant Field Values
-
FIXED_QUANTILE_50
private static final double FIXED_QUANTILE_50
Fixed quantile.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Median
public Median()
Default constructor.
-
Median
public Median(Median original) throws NullArgumentException
Copy constructor, creates a newMedian
identical to theoriginal
- Parameters:
original
- theMedian
instance to copy- Throws:
NullArgumentException
- if original is null
-
Median
private Median(Percentile.EstimationType estimationType, NaNStrategy nanStrategy, KthSelector kthSelector) throws MathIllegalArgumentException
- Parameters:
estimationType
- one of the percentileestimation types
nanStrategy
- one ofNaNStrategy
to handle with NaNskthSelector
-KthSelector
to use for pivoting during search- Throws:
MathIllegalArgumentException
- if p is not within (0,100]NullArgumentException
- if type or NaNStrategy passed is null
-
-
Method Detail
-
withEstimationType
public Median withEstimationType(Percentile.EstimationType newEstimationType)
Build a new instance similar to the current one except for theestimation type
.This method is intended to be used as part of a fluent-type builder pattern. Building finely tune instances should be done as follows:
Percentile customized = new Percentile(quantile). withEstimationType(estimationType). withNaNStrategy(nanStrategy). withKthSelector(kthSelector);
If any of the
withXxx
method is omitted, the default value for the corresponding customization parameter will be used.- Overrides:
withEstimationType
in classPercentile
- Parameters:
newEstimationType
- estimation type for the new instance- Returns:
- a new instance, with changed estimation type
-
withNaNStrategy
public Median withNaNStrategy(NaNStrategy newNaNStrategy)
Build a new instance similar to the current one except for theNaN handling
strategy.This method is intended to be used as part of a fluent-type builder pattern. Building finely tune instances should be done as follows:
Percentile customized = new Percentile(quantile). withEstimationType(estimationType). withNaNStrategy(nanStrategy). withKthSelector(kthSelector);
If any of the
withXxx
method is omitted, the default value for the corresponding customization parameter will be used.- Overrides:
withNaNStrategy
in classPercentile
- Parameters:
newNaNStrategy
- NaN strategy for the new instance- Returns:
- a new instance, with changed NaN handling strategy
-
withKthSelector
public Median withKthSelector(KthSelector newKthSelector)
Build a new instance similar to the current one except for thekthSelector
instance specifically set.This method is intended to be used as part of a fluent-type builder pattern. Building finely tune instances should be done as follows:
Percentile customized = new Percentile(quantile). withEstimationType(estimationType). withNaNStrategy(nanStrategy). withKthSelector(newKthSelector);
If any of the
withXxx
method is omitted, the default value for the corresponding customization parameter will be used.- Overrides:
withKthSelector
in classPercentile
- Parameters:
newKthSelector
- KthSelector for the new instance- Returns:
- a new instance, with changed KthSelector
-
-