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. |
boolean |
sameState(DoubleMomentStatistics other)
Compares the state of two
DoubleMomentStatistics objects. |
static <T> Collector<T,?,DoubleMomentStatistics> |
toDoubleMomentStatistics(ToDoubleFunction<? super T> mapper)
Return a
Collector which applies an double-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 boolean sameState(DoubleMomentStatistics other)
DoubleMomentStatistics
objects. This is
a replacement for the Object.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);
}
other
- the other object for the testtrue
the this
and the other
objects have
the same state, false
otherwisepublic static <T> Collector<T,?,DoubleMomentStatistics> toDoubleMomentStatistics(ToDoubleFunction<? super T> mapper)
Collector
which 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()));
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-2017 Franz Wilhelmstötter (2017-04-28 16:50)