public class DoubleMomentStatistics extends Object implements DoubleConsumer
DoubleSummaryStatistics
class.
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:
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()));
Implementation note:
This implementation is not thread safe. However, it is safe to use
toDoubleMomentStatistics(ToDoubleFunction)
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.
DoubleSummaryStatistics
,
DoubleMoments
,
Computing Higher-Order Moments OnlineConstructor and Description |
---|
DoubleMomentStatistics()
Create an empty moments object.
|
Modifier and Type | Method and Description |
---|---|
void |
accept(double value)
Records a new value into the moments information
|
DoubleMomentStatistics |
combine(DoubleMomentStatistics other)
Combine two
DoubleMoments 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. |
double |
getMax()
Return the maximum value recorded, or
Double.NEGATIVE_INFINITY if
no values have been recorded. |
double |
getMean()
Return the arithmetic mean of values recorded, or
Double.NaN if
no values have been recorded. |
double |
getMin()
Return the minimum value recorded, or
Double.POSITIVE_INFINITY 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. |
double |
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,?,DoubleMomentStatistics> |
toDoubleMomentStatistics(ToDoubleFunction<? super T> mapper)
Return a
Collector which applies an long-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 DoubleMomentStatistics()
public void accept(double value)
accept
in interface DoubleConsumer
value
- the input value
public DoubleMomentStatistics combine(DoubleMomentStatistics other)
DoubleMoments
statistic objects.other
- the other DoubleMoments
statistics to combine with
this
one.this
statistics objectNullPointerException
- if the other statistical summary
is null
.public double getMin()
Double.POSITIVE_INFINITY
if
no values have been recorded.Double.POSITIVE_INFINITY
if nonepublic double getMax()
Double.NEGATIVE_INFINITY
if
no values have been recorded.Double.NEGATIVE_INFINITY
if nonepublic double getSum()
public static <T> Collector<T,?,DoubleMomentStatistics> toDoubleMomentStatistics(ToDoubleFunction<? super T> mapper)
Collector
which applies an long-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()));
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-2014 Franz Wilhelmstötter (2014-12-28 10:45)