public class VarianceCalculatorLong extends Object
long
to store sums
internally.
This is similar to VarianceCalculatorDouble
but is designed for int
values
rather than double
s.
Efficiency occurs by maintaining a running sum, sum-of-squares and count as values are added.
This is useful for calculating variance in sequential order in an online manner.
Constructor and Description |
---|
VarianceCalculatorLong() |
VarianceCalculatorLong(long sum,
long sumSquares,
long count) |
Modifier and Type | Method and Description |
---|---|
void |
add(int value)
Adds a value to the running sum.
|
void |
add(int value,
int instances)
Adds a multiple instances of a value to the running sum.
|
long |
getCount()
The running count of values.
|
double |
mean()
Calculate the mean, based on the current state of running-sums.
|
VarianceCalculatorLong |
subtract(VarianceCalculatorLong toSubtract)
Subtracts the running-sums and count from another
VarianceCalculatorLong from the
current object's state. |
double |
variance()
Calculate the variance, based on the current state of running-sums.
|
public VarianceCalculatorLong(long sum, long sumSquares, long count)
public VarianceCalculatorLong()
public void add(int value)
value
- the value to add.public void add(int value, int instances)
value
- the value to add.instances
- how many instances of value
to add.public VarianceCalculatorLong subtract(VarianceCalculatorLong toSubtract)
VarianceCalculatorLong
from the
current object's state.
This occurs immutably, and the currently object's state is unaffected.
toSubtract
- the other VarianceCalculatorLong
whose state is subtracted.VarianceCalculatorLong
whose state is the current object
minus toSubtract
.public double mean()
public double variance()
public long getCount()
Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.