Class Statistics
java.lang.Object
org.apache.commons.statistics.descriptive.Statistics
Utility methods for statistics.
- Since:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final DoubleConsumer
A no-operation double consumer.private static final String
Error message for an incompatible statistics.(package private) static final IntConsumer
A no-operation int consumer.(package private) static final LongConsumer
A no-operation long consumer. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static <T extends DoubleConsumer>
Tadd
(T statistic, double[] values) Add all thevalues
to thestatistic
.(package private) static <T extends DoubleConsumer>
Tadd
(T statistic, int[] values) Add all thevalues
to thestatistic
.(package private) static <T extends DoubleConsumer>
Tadd
(T statistic, long[] values) Add all thevalues
to thestatistic
.(package private) static void
Check left-hand side argumenta
isnull
or else the right-hand side argumentb
must be run-time assignable to the same class asa
so the statistics can be combined.(package private) static <T extends StatisticResult & StatisticAccumulator<T>>
voidcheckCombineCompatible
(T a, T b) Check left-hand side argumenta
isnull
or else the right-hand side argumentb
must also be non-null
so the statistics can be combined.(package private) static <T extends StatisticResult & StatisticAccumulator<T>>
voidcombine
(T a, T b) If the left-hand side argumenta
is non-null
, combine it with the right-hand side argumentb
.(package private) static void
If the left-hand side argumenta
is non-null
, combine it with the right-hand side argumentb
.(package private) static DoubleConsumer
compose
(DoubleConsumer... consumers) Chain theconsumers
into a single composite consumer.(package private) static IntConsumer
compose
(IntConsumer... consumers) Chain theconsumers
into a single composite consumer.(package private) static LongConsumer
compose
(LongConsumer... consumers) Chain theconsumers
into a single composite consumer.(package private) static StatisticResult
Gets the statistic result using theBigInteger
value.(package private) static StatisticResult
Gets the statistic result using thedouble
value.(package private) static StatisticResult
Gets the statistic result using theint
value.(package private) static StatisticResult
Gets the statistic result using thelong
value.(package private) static boolean
zeroVariance
(double m1, double m2) Returnstrue
if the second central momentm2
is effectively zero given the magnitude of the first raw momentm1
.
-
Field Details
-
DOUBLE_NOOP
A no-operation double consumer. This is exposed for testing. -
INT_NOOP
A no-operation int consumer. This is exposed for testing. -
LONG_NOOP
A no-operation long consumer. This is exposed for testing. -
INCOMPATIBLE_STATISTICS
Error message for an incompatible statistics.- See Also:
-
-
Constructor Details
-
Statistics
private Statistics()No instances.
-
-
Method Details
-
add
Add all thevalues
to thestatistic
.- Type Parameters:
T
- Type of the statistic- Parameters:
statistic
- Statistic.values
- Values.- Returns:
- the statistic
-
add
Add all thevalues
to thestatistic
.- Type Parameters:
T
- Type of the statistic- Parameters:
statistic
- Statistic.values
- Values.- Returns:
- the statistic
-
add
Add all thevalues
to thestatistic
.- Type Parameters:
T
- Type of the statistic- Parameters:
statistic
- Statistic.values
- Values.- Returns:
- the statistic
-
add
Add all thevalues
to thestatistic
.- Type Parameters:
T
- Type of the statistic- Parameters:
statistic
- Statistic.values
- Values.- Returns:
- the statistic
-
add
Add all thevalues
to thestatistic
.- Type Parameters:
T
- Type of the statistic- Parameters:
statistic
- Statistic.values
- Values.- Returns:
- the statistic
-
zeroVariance
static boolean zeroVariance(double m1, double m2) Returnstrue
if the second central momentm2
is effectively zero given the magnitude of the first raw momentm1
.This method shares the logic for detecting a zero variance among implementations that divide by the variance (e.g. skewness, kurtosis).
- Parameters:
m1
- First raw moment (mean).m2
- Second central moment (biased variance).- Returns:
- true if the variance is zero
-
compose
Chain theconsumers
into a single composite consumer. Ignore anynull
consumer. Returnsnull
if all arguments arenull
.- Parameters:
consumers
- Consumers.- Returns:
- a composed consumer (or null)
-
compose
Chain theconsumers
into a single composite consumer. Ignore anynull
consumer. Returnsnull
if all arguments arenull
.- Parameters:
consumers
- Consumers.- Returns:
- a composed consumer (or null)
-
compose
Chain theconsumers
into a single composite consumer. Ignore anynull
consumer. Returnsnull
if all arguments arenull
.- Parameters:
consumers
- Consumers.- Returns:
- a composed consumer (or null)
-
getResultAsIntOrNull
Gets the statistic result using theint
value. Returnnull
is the statistic isnull
.- Parameters:
s
- Statistic.- Returns:
- the result or null
-
getResultAsLongOrNull
Gets the statistic result using thelong
value. Returnnull
is the statistic isnull
.- Parameters:
s
- Statistic.- Returns:
- the result or null
-
getResultAsDoubleOrNull
Gets the statistic result using thedouble
value. Returnnull
is the statistic isnull
.- Parameters:
s
- Statistic.- Returns:
- the result or null
-
getResultAsBigIntegerOrNull
Gets the statistic result using theBigInteger
value. Returnnull
is the statistic isnull
.- Parameters:
s
- Statistic.- Returns:
- the result or null
-
checkCombineCompatible
Check left-hand side argumenta
isnull
or else the right-hand side argumentb
must also be non-null
so the statistics can be combined.- Type Parameters:
T
-StatisticResult
being accumulated.- Parameters:
a
- LHS.b
- RHS.- Throws:
IllegalArgumentException
- if the objects cannot be combined
-
checkCombineAssignable
Check left-hand side argumenta
isnull
or else the right-hand side argumentb
must be run-time assignable to the same class asa
so the statistics can be combined.- Parameters:
a
- LHS.b
- RHS.- Throws:
IllegalArgumentException
- if the objects cannot be combined
-
combine
If the left-hand side argumenta
is non-null
, combine it with the right-hand side argumentb
.- Type Parameters:
T
-StatisticResult
being accumulated.- Parameters:
a
- LHS.b
- RHS.
-
combineMoment
If the left-hand side argumenta
is non-null
, combine it with the right-hand side argumentb
. Assumes that the RHS is run-time assignable to the same class as LHS.- Parameters:
a
- LHS.b
- RHS.- See Also:
-