Package io.jenetics.stat
Class DoubleMomentStatistics
- java.lang.Object
-
- io.jenetics.stat.DoubleMomentStatistics
-
- All Implemented Interfaces:
DoubleConsumer
public class DoubleMomentStatistics extends Object implements DoubleConsumer
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 theDoubleSummaryStatisticsclass.This class is designed to work with (though does not require) streams. For example, you can compute moments-statistics on a stream of doubles with:
For a non double stream, you can use a collector:final DoubleStream stream = ... final DoubleMomentStatistics statistics = stream.collect( DoubleMomentStatistics::new, DoubleMomentStatistics::accept, DoubleMomentStatistics::combine );final Stream<SomeObject> stream = ... final DoubleMomentStatistics statistics = stream .collect(toDoubleMomentStatistics(v -> v.doubleValue()));- Since:
- 3.0
- Version:
- 6.0
- Author:
- Franz Wilhelmstötter
- See Also:
DoubleSummaryStatistics,DoubleMoments, Computing Higher-Order Moments Online- Implementation Note:
- This implementation is not thread safe. However, it is safe to use
toDoubleMomentStatistics(ToDoubleFunction)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 Constructor Description DoubleMomentStatistics()Create an empty moments object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaccept(double value)Records a new value into the moments informationDoubleMomentStatisticscombine(DoubleMomentStatistics other)Combine twoDoubleMomentsstatistic objects.longcount()Returns the count of values recorded.doublekurtosis()Return the kurtosis of values recorded, orDouble.NaNif less than four values have been recorded.doublemax()Return the maximum value recorded, orDouble.NEGATIVE_INFINITYif no values have been recorded.doublemean()Return the arithmetic mean of values recorded, orDouble.NaNif no values have been recorded.doublemin()Return the minimum value recorded, orDouble.POSITIVE_INFINITYif no values have been recorded.booleansameState(DoubleMomentStatistics other)Compares the state of twoDoubleMomentStatisticsobjects.doubleskewness()Return the skewness of values recorded, orDouble.NaNif less than two values have been recorded.doublesum()Return the sum of values recorded, or zero if no values have been recorded.DoubleMomentstoDoubleMoments()Return aDoubleMomentsobject from the current statistics,static <T> Collector<T,?,DoubleMomentStatistics>toDoubleMomentStatistics(ToDoubleFunction<? super T> mapper)Return aCollectorwhich applies an double-producing mapping function to each input element, and returns moments-statistics for the resulting values.StringtoString()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, wait
-
Methods inherited from interface java.util.function.DoubleConsumer
andThen
-
-
-
-
Constructor Detail
-
DoubleMomentStatistics
public DoubleMomentStatistics()
Create an empty moments object.
-
-
Method Detail
-
accept
public void accept(double value)
Records a new value into the moments information- Specified by:
acceptin interfaceDoubleConsumer- Parameters:
value- the inputvalue
-
combine
public DoubleMomentStatistics combine(DoubleMomentStatistics other)
Combine twoDoubleMomentsstatistic objects.- Parameters:
other- the otherDoubleMomentsstatistics to combine withthisone.- Returns:
thisstatistics object- Throws:
NullPointerException- if the other statistical summary isnull.
-
min
public double min()
Return the minimum value recorded, orDouble.POSITIVE_INFINITYif no values have been recorded.- Returns:
- the minimum value, or
Double.POSITIVE_INFINITYif none
-
max
public double max()
Return the maximum value recorded, orDouble.NEGATIVE_INFINITYif no values have been recorded.- Returns:
- the maximum value, or
Double.NEGATIVE_INFINITYif none
-
sum
public double 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
public boolean sameState(DoubleMomentStatistics other)
Compares the state of twoDoubleMomentStatisticsobjects. This is a replacement for theObject.equals(Object)which is not advisable to implement for this mutable object. If two object have the same state, it has still the same state when updated with the same value.final DoubleMomentStatistics ds1 = ...; final DoubleMomentStatistics ds2 = ...; if (ds1.sameState(ds2)) { final double value = random.nextDouble(); ds1.accept(value); ds2.accept(value); assert ds1.sameState(ds2); assert ds2.sameState(ds1); assert ds1.sameState(ds1); }- Parameters:
other- the other object for the test- Returns:
truethethisand theotherobjects have the same state,falseotherwise- Since:
- 3.7
-
toDoubleMoments
public DoubleMoments toDoubleMoments()
Return aDoubleMomentsobject from the current statistics,- Returns:
- a
DoubleMomentsobject from the current statistics - Since:
- 3.9
-
toDoubleMomentStatistics
public static <T> Collector<T,?,DoubleMomentStatistics> toDoubleMomentStatistics(ToDoubleFunction<? super T> mapper)
Return aCollectorwhich applies an double-producing mapping function to each input element, and returns moments-statistics for the resulting values.final Stream<SomeObject> stream = ... final DoubleMomentStatistics statistics = stream .collect(toDoubleMomentStatistics(v -> v.doubleValue()));- 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:
- Skewness
-
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:
- Kurtosis
-
-