Class Statistics
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final DoubleConsumerA no-operation double consumer.private static final StringError message for an incompatible statistics.(package private) static final IntConsumerA no-operation int consumer.(package private) static final LongConsumerA 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 thevaluesto thestatistic.(package private) static <T extends DoubleConsumer>
Tadd(T statistic, double[] values, int from, int to) Add the specified range ofvaluesto thestatistic.(package private) static <T extends DoubleConsumer>
Tadd(T statistic, int[] values) Add all thevaluesto thestatistic.(package private) static <T extends IntConsumer>
Tadd(T statistic, int[] values) Add all thevaluesto thestatistic.(package private) static <T extends DoubleConsumer>
Tadd(T statistic, int[] values, int from, int to) Add the specified range ofvaluesto thestatistic.(package private) static <T extends IntConsumer>
Tadd(T statistic, int[] values, int from, int to) Add the specified range ofvaluesto thestatistic.(package private) static <T extends DoubleConsumer>
Tadd(T statistic, long[] values) Add all thevaluesto thestatistic.(package private) static <T extends LongConsumer>
Tadd(T statistic, long[] values) Add all thevaluesto thestatistic.(package private) static <T extends DoubleConsumer>
Tadd(T statistic, long[] values, int from, int to) Add the specified range ofvaluesto thestatistic.(package private) static <T extends LongConsumer>
Tadd(T statistic, long[] values, int from, int to) Add the specified range ofvaluesto thestatistic.(package private) static voidCheck left-hand side argumentaisnullor else the right-hand side argumentbmust be run-time assignable to the same class asaso the statistics can be combined.(package private) static <T extends StatisticResult & StatisticAccumulator<T>>
voidcheckCombineCompatible(T a, T b) Check left-hand side argumentaisnullor else the right-hand side argumentbmust also be non-nullso the statistics can be combined.(package private) static voidcheckFromToIndex(int fromIndex, int toIndex, int length) Checks if the sub-range from fromIndex (inclusive) to toIndex (exclusive) is within the bounds of range from 0 (inclusive) to length (exclusive).(package private) static <T extends StatisticResult & StatisticAccumulator<T>>
voidcombine(T a, T b) If the left-hand side argumentais non-null, combine it with the right-hand side argumentb.(package private) static voidIf the left-hand side argumentais non-null, combine it with the right-hand side argumentb.(package private) static DoubleConsumercomposeDoubleConsumers(DoubleConsumer... consumers) Chain theconsumersinto a single composite consumer.(package private) static IntConsumercomposeIntConsumers(IntConsumer... consumers) Chain theconsumersinto a single composite consumer.(package private) static LongConsumercomposeLongConsumers(LongConsumer... consumers) Chain theconsumersinto a single composite consumer.(package private) static int[]copy(int[] data, int from, int to) Copy the specified range of data.(package private) static StatisticResultGets the statistic result using theBigIntegervalue.(package private) static StatisticResultGets the statistic result using thedoublevalue.(package private) static StatisticResultGets the statistic result using theintvalue.(package private) static StatisticResultGets the statistic result using thelongvalue.private static StringmsgRangeOutOfBounds(int fromIndex, int toIndex, int length) Format a message when range [from, to) is not entirely within the length.(package private) static org.apache.commons.numbers.core.Sumsum(double[] values, int from, int to) Sum the specified range ofvalues.(package private) static booleanzeroVariance(double m1, double m2) Returnstrueif the second central momentm2is 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 thevaluesto thestatistic.- Type Parameters:
T- Type of the statistic- Parameters:
statistic- Statistic.values- Values.- Returns:
- the statistic
-
add
Add the specified range ofvaluesto thestatistic.Warning: No range checks are performed.
- Type Parameters:
T- Type of the statistic- Parameters:
statistic- Statistic.values- Values.from- Inclusive start of the range.to- Exclusive end of the range.- Returns:
- the statistic
-
add
Add all thevaluesto thestatistic.- Type Parameters:
T- Type of the statistic- Parameters:
statistic- Statistic.values- Values.- Returns:
- the statistic
-
add
Add the specified range ofvaluesto thestatistic.Warning: No range checks are performed.
- Type Parameters:
T- Type of the statistic- Parameters:
statistic- Statistic.values- Values.from- Inclusive start of the range.to- Exclusive end of the range.- Returns:
- the statistic
-
add
Add all thevaluesto thestatistic.- Type Parameters:
T- Type of the statistic- Parameters:
statistic- Statistic.values- Values.- Returns:
- the statistic
-
add
Add the specified range ofvaluesto thestatistic.Warning: No range checks are performed.
- Type Parameters:
T- Type of the statistic- Parameters:
statistic- Statistic.values- Values.from- Inclusive start of the range.to- Exclusive end of the range.- Returns:
- the statistic
-
add
Add all thevaluesto thestatistic.- Type Parameters:
T- Type of the statistic- Parameters:
statistic- Statistic.values- Values.- Returns:
- the statistic
-
add
Add the specified range ofvaluesto thestatistic.Warning: No range checks are performed.
- Type Parameters:
T- Type of the statistic- Parameters:
statistic- Statistic.values- Values.from- Inclusive start of the range.to- Exclusive end of the range.- Returns:
- the statistic
-
add
Add all thevaluesto thestatistic.- Type Parameters:
T- Type of the statistic- Parameters:
statistic- Statistic.values- Values.- Returns:
- the statistic
-
add
Add the specified range ofvaluesto thestatistic.Warning: No range checks are performed.
- Type Parameters:
T- Type of the statistic- Parameters:
statistic- Statistic.values- Values.from- Inclusive start of the range.to- Exclusive end of the range.- Returns:
- the statistic
-
zeroVariance
static boolean zeroVariance(double m1, double m2) Returnstrueif the second central momentm2is 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
-
composeDoubleConsumers
Chain theconsumersinto a single composite consumer. Ignore anynullconsumer. Returnsnullif all arguments arenull.- Parameters:
consumers- Consumers.- Returns:
- a composed consumer (or null)
-
composeIntConsumers
Chain theconsumersinto a single composite consumer. Ignore anynullconsumer. Returnsnullif all arguments arenull.- Parameters:
consumers- Consumers.- Returns:
- a composed consumer (or null)
-
composeLongConsumers
Chain theconsumersinto a single composite consumer. Ignore anynullconsumer. Returnsnullif all arguments arenull.- Parameters:
consumers- Consumers.- Returns:
- a composed consumer (or null)
-
getResultAsIntOrNull
Gets the statistic result using theintvalue. Returnnullis the statistic isnull.- Parameters:
s- Statistic.- Returns:
- the result or null
-
getResultAsLongOrNull
Gets the statistic result using thelongvalue. Returnnullis the statistic isnull.- Parameters:
s- Statistic.- Returns:
- the result or null
-
getResultAsDoubleOrNull
Gets the statistic result using thedoublevalue. Returnnullis the statistic isnull.- Parameters:
s- Statistic.- Returns:
- the result or null
-
getResultAsBigIntegerOrNull
Gets the statistic result using theBigIntegervalue. Returnnullis the statistic isnull.- Parameters:
s- Statistic.- Returns:
- the result or null
-
checkCombineCompatible
Check left-hand side argumentaisnullor else the right-hand side argumentbmust also be non-nullso the statistics can be combined.- Type Parameters:
T-StatisticResultbeing accumulated.- Parameters:
a- LHS.b- RHS.- Throws:
IllegalArgumentException- if the objects cannot be combined
-
checkCombineAssignable
Check left-hand side argumentaisnullor else the right-hand side argumentbmust be run-time assignable to the same class asaso the statistics can be combined.- Parameters:
a- LHS.b- RHS.- Throws:
IllegalArgumentException- if the objects cannot be combined
-
combine
If the left-hand side argumentais non-null, combine it with the right-hand side argumentb.- Type Parameters:
T-StatisticResultbeing accumulated.- Parameters:
a- LHS.b- RHS.
-
combineMoment
If the left-hand side argumentais 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:
-
checkFromToIndex
static void checkFromToIndex(int fromIndex, int toIndex, int length) Checks if the sub-range from fromIndex (inclusive) to toIndex (exclusive) is within the bounds of range from 0 (inclusive) to length (exclusive).This function provides the functionality of
java.utils.Objects.checkFromToIndexintroduced in JDK 9. The Objects javadoc has been reproduced for reference. The return value has been changed to void.The sub-range is defined to be out of bounds if any of the following inequalities is true:
fromIndex < 0fromIndex > toIndextoIndex > lengthlength < 0, which is implied from the former inequalities
- Parameters:
fromIndex- Lower-bound (inclusive) of the sub-range.toIndex- Upper-bound (exclusive) of the sub-range.length- Upper-bound (exclusive) of the range.- Throws:
IndexOutOfBoundsException- if the sub-range is out of bounds
-
msgRangeOutOfBounds
Format a message when range [from, to) is not entirely within the length.- Parameters:
fromIndex- Lower-bound (inclusive) of the sub-range.toIndex- Upper-bound (exclusive) of the sub-range.length- Upper-bound (exclusive) of the range.- Returns:
- the message
-
sum
static org.apache.commons.numbers.core.Sum sum(double[] values, int from, int to) Sum the specified range ofvalues.Warning: No range checks are performed.
- Parameters:
values- Values.from- Inclusive start of the range.to- Exclusive end of the range.- Returns:
- the sum
-
copy
static int[] copy(int[] data, int from, int to) Copy the specified range of data.This is a simplification of
and does not support range checks or padding of the original input to a longer output.invalid reference
Arrays#copyOfRange(double[], int, int)- Parameters:
data- Values.from- Inclusive start of the range.to- Exclusive end of the range.- Returns:
- the copy
-