public class IntMomentStatistics extends Object implements IntConsumer
IntSummaryStatistics
class.
This class is designed to work with (though does not require) streams. For example, you can compute moments-statistics on a stream of ints with:
final IntStream stream = ...
final IntMomentStatistics statistics = stream.collect(
IntMomentStatistics::new,
IntMomentStatistics::accept,
IntMomentStatistics::combine
);
final Stream<SomeObject> stream = ...
final IntMomentStatistics statistics = stream
.collect(toIntMomentStatistics(v -> v.intValue()));
Implementation note:
This implementation is not thread safe. However, it is safe to use
toIntMomentStatistics(ToIntFunction)
on a parallel stream, because the parallel
implementation of Stream.collect()
provides the necessary partitioning, isolation, and merging of results for
safe and efficient parallel execution.
IntSummaryStatistics
,
IntMoments
,
Computing Higher-Order Moments OnlineConstructor and Description |
---|
IntMomentStatistics()
Create an empty moments object.
|
Modifier and Type | Method and Description |
---|---|
void |
accept(int value)
Records a new value into the moments information
|
IntMomentStatistics |
combine(IntMomentStatistics other)
Combine two
IntMoments statistic objects. |
long |
getCount()
Returns the count of values recorded.
|
double |
getKurtosis()
Return the kurtosis of values recorded, or
Double.NaN if less
than four values have been recorded. |
int |
getMax()
Return the maximum value recorded, or
Integer.MIN_VALUE if no
values have been recorded. |
double |
getMean()
Return the arithmetic mean of values recorded, or
Double.NaN if
no values have been recorded. |
int |
getMin()
Return the minimum value recorded, or
Integer.MAX_VALUE if no
values have been recorded. |
double |
getSkewness()
Return the skewness of values recorded, or
Double.NaN if less
than two values have been recorded. |
long |
getSum()
Return the sum of values recorded, or zero if no values have been
recorded.
|
double |
getVariance()
Return the variance of values recorded, or
Double.NaN if no
values have been recorded. |
static <T> Collector<T,?,IntMomentStatistics> |
toIntMomentStatistics(ToIntFunction<? super T> mapper)
Return a
Collector which applies an int-producing mapping
function to each input element, and returns moments-statistics for the
resulting values. |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
andThen
public IntMomentStatistics()
public void accept(int value)
accept
in interface IntConsumer
value
- the input value
public IntMomentStatistics combine(IntMomentStatistics other)
IntMoments
statistic objects.other
- the other IntMoments
statistics to combine with
this
one.this
statistics objectNullPointerException
- if the other statistical summary
is null
.public int getMin()
Integer.MAX_VALUE
if no
values have been recorded.Integer.MAX_VALUE
if nonepublic int getMax()
Integer.MIN_VALUE
if no
values have been recorded.Integer.MIN_VALUE
if nonepublic long getSum()
public static <T> Collector<T,?,IntMomentStatistics> toIntMomentStatistics(ToIntFunction<? super T> mapper)
Collector
which applies an int-producing mapping
function to each input element, and returns moments-statistics for the
resulting values.
final Stream<SomeObject> stream = ...
final IntMomentStatistics statistics = stream
.collect(toIntMomentStatistics(v -> v.intValue()));
T
- the type of the input elementsmapper
- a mapping function to apply to each elementCollector
implementing the moments-statistics reductionNullPointerException
- if the given mapper
is
null
public long getCount()
public double getMean()
Double.NaN
if
no values have been recorded.public double getVariance()
Double.NaN
if no
values have been recorded.NaN
if nonepublic double getSkewness()
Double.NaN
if less
than two values have been recorded.NaN
if less than two values
have been recordedpublic double getKurtosis()
Double.NaN
if less
than four values have been recorded.NaN
if less than four values
have been recorded© 2007-2016 Franz Wilhelmstötter (2016-04-24 10:25)