public class RunningSum extends Object implements Serializable
It can also be reset to zero, as needed.
Constructor and Description |
---|
RunningSum() |
RunningSum(double sum,
long count) |
Modifier and Type | Method and Description |
---|---|
void |
add(RunningSum toAdd)
Adds the values of another
RunningSum to the current values. |
RunningSum |
duplicate()
Deep-copy.
|
long |
getCount()
The running count.
|
double |
getSum()
The running sum.
|
void |
increment(double sumIncrement)
Adds a new item to the sum, and increments the count by 1.
|
void |
increment(double sumIncrement,
long countIncrement)
Increments both the sum and count by particular values.
|
void |
increment(RunningSum runningSum)
Increments (adds) an existing
RunningSum to the current. |
double |
mean()
Calculates the mean.
|
double |
mean(double valueIfCountZero)
Calculates the mean.
|
double |
meanAndReset()
Calculate the mean and then reset to zero.
|
void |
reset()
Reset the sum and count to zero.
|
public RunningSum()
public RunningSum(double sum, long count)
public double mean()
NaN
if the count is zero.public double mean(double valueIfCountZero)
valueIfCountZero
- value to use if the count is zero.valueIfCountZero
if the count is zero.public double meanAndReset()
public void reset()
public void increment(double sumIncrement)
sumIncrement
- the value to add to sum.public void increment(double sumIncrement, long countIncrement)
sumIncrement
- increment-value for sum.countIncrement
- increment-value for count.public void increment(RunningSum runningSum)
RunningSum
to the current.runningSum
- the existing sum, which is unmodified.public RunningSum duplicate()
public void add(RunningSum toAdd)
RunningSum
to the current values.toAdd
- the other sum that will be added.public double getSum()
public long getCount()
Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.