java.lang.Object
io.jenetics.stat.LongMomentStatistics
- All Implemented Interfaces:
IntConsumer,LongConsumer
A state object for collecting statistics such as count, min, max, sum, mean,
variance, skewness and kurtosis. The design of this class is similar to the
design of the
For a non-long stream, you can use a collector:
LongSummaryStatistics class.
This class is designed to work with (though does not require) streams. For example, you can compute moments-statistics on a stream of longs with:
final LongStream stream = ...;
final LongMomentStatistics statistics = stream.collect(
LongMomentStatistics::new,
LongMomentStatistics::accept,
LongMomentStatistics::combine
);
final Stream<SomeObject> stream = ...;
final LongMomentStatistics statistics = stream
.collect(toLongMomentStatistics(v -> v.longValue()));
- Since:
- 3.0
- Version:
- 6.0
- See Also:
- Implementation Note:
- This implementation is not thread safe. However, it is safe to use
toLongMomentStatistics(ToLongFunction)on a parallel stream, because the parallel implementation ofStream.collect()provides the necessary partitioning, isolation, and merging of results for safe and efficient parallel execution.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(int value) Records a new value into the moment informationvoidaccept(long value) Records a new value into the moment informationcombine(LongMomentStatistics other) Combine twoLongMomentsstatistic objects.longcount()Returns the count of values recorded.doublekurtosis()Return the kurtosis of values recorded, orDouble.NaNif less than four values have been recorded.longmax()Return the maximum value recorded, orLong.MIN_VALUEif no values have been recorded.doublemean()Return the arithmetic mean of values recorded, orDouble.NaNif no values have been recorded.longmin()Return the minimum value recorded, orLong.MAX_VALUEif no values have been recorded.booleansameState(LongMomentStatistics other) Compares the state of twoLongMomentStatisticsobjects.doubleskewness()Return the skewness of values recorded, orDouble.NaNif less than two values have been recorded.longsum()Return the sum of values recorded, or zero if no values have been recorded.Return aLongMomentsobject from the current statistics,static <T> Collector<T, ?, LongMomentStatistics> toLongMomentStatistics(ToLongFunction<? super T> mapper) Return aCollectorwhich applies a long-producing mapping function to each input element, and returns moments-statistics for the resulting values.toString()doublevariance()Return the variance of values recorded, orDouble.NaNif no values have been recorded.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.function.IntConsumer
andThenMethods inherited from interface java.util.function.LongConsumer
andThen
-
Constructor Details
-
LongMomentStatistics
public LongMomentStatistics()Create an empty moments object.
-
-
Method Details
-
accept
Records a new value into the moment information- Specified by:
acceptin interfaceLongConsumer- Parameters:
value- the inputvalue
-
accept
Records a new value into the moment information- Specified by:
acceptin interfaceIntConsumer- Parameters:
value- the inputvalue
-
combine
Combine twoLongMomentsstatistic objects.- Parameters:
other- the otherLongMomentsstatistics to combine withthisone.- Returns:
thisstatistics object- Throws:
NullPointerException- if the other statistical summary isnull.
-
min
Return the minimum value recorded, orLong.MAX_VALUEif no values have been recorded.- Returns:
- the minimum value, or
Long.MAX_VALUEif none
-
max
Return the maximum value recorded, orLong.MIN_VALUEif no values have been recorded.- Returns:
- the maximum value, or
Long.MIN_VALUEif none
-
sum
Return the sum of values recorded, or zero if no values have been recorded.- Returns:
- the sum of values, or zero if none
-
sameState
Compares the state of twoLongMomentStatisticsobjects. This is a replacement for theObject.equals(Object)which is not advisable to implement for this mutable object. If two objects have the same state, it has still the same state when updated with the same value.final LongMomentStatistics lms1 = ...; final LongMomentStatistics lms2 = ...; if (lms1.sameState(lms2)) { final long value = random.nextInt(1_000_000); lms1.accept(value); lms2.accept(value); assert lms1.sameState(lms2); assert lms2.sameState(lms1); assert lms1.sameState(lms1); }- Parameters:
other- the other object for the test- Returns:
truethethisand theotherobjects have the same state,falseotherwise- Since:
- 3.7
-
toLongMoments
Return aLongMomentsobject from the current statistics,- Returns:
- a
LongMomentsobject from the current statistics - Since:
- 3.9
-
toString
-
toLongMomentStatistics
public static <T> Collector<T,?, toLongMomentStatisticsLongMomentStatistics> (ToLongFunction<? super T> mapper) Return aCollectorwhich applies a long-producing mapping function to each input element, and returns moments-statistics for the resulting values.final Stream<SomeObject> stream = ...; final LongMomentStatistics statistics = stream .collect(toLongMomentStatistics(v -> v.longValue()));- Type Parameters:
T- the type of the input elements- Parameters:
mapper- a mapping function to apply to each element- Returns:
- a
Collectorimplementing the moments-statistics reduction - Throws:
NullPointerException- if the givenmapperisnull
-
count
public long count()Returns the count of values recorded.- Returns:
- the count of recorded values
-
mean
public double mean()Return the arithmetic mean of values recorded, orDouble.NaNif no values have been recorded.- Returns:
- the arithmetic mean of values, or zero if none
-
variance
public double variance()Return the variance of values recorded, orDouble.NaNif no values have been recorded.- Returns:
- the variance of values, or
NaNif none
-
skewness
public double skewness()Return the skewness of values recorded, orDouble.NaNif less than two values have been recorded.- Returns:
- the skewness of values, or
NaNif less than two values have been recorded - See Also:
-
kurtosis
public double kurtosis()Return the kurtosis of values recorded, orDouble.NaNif less than four values have been recorded.- Returns:
- the kurtosis of values, or
NaNif less than four values have been recorded - See Also:
-