Go implementation of variance’s method for one-pass variance computation with D. H. D. West improved methods.
- Merging of several multiple sets of statistics
- Add weighted values
A method of improved efficiency is given for updating the mean and variance of weighted sampled data when an additional data value is included in the set Evidence is presented that the method is stable and at least as accurate as the best existing updating method.
Updating mean and variance estimates: an improved method - D. H. D. West
go get github.com/axiomhq/variance
git clone https://github.com/axiomhq/variance.git
cd variance
make # Run code generators, linters, sanitizers and test suits
package variance_test
import (
"fmt"
"github.com/axiomhq/variance"
)
func Example() {
stats1 := variance.New()
stats1.Add(1)
stats1.Add(1)
stats1.Add(1)
stats1.Add(0)
stats1.Add(0)
stats1.Add(0)
fmt.Println(
stats1.Mean(),
stats1.Variance(),
stats1.StandardDeviation(),
stats1.VariancePopulation(),
stats1.StandardDeviationPopulation(),
stats1.NumDataValues(),
)
stats2 := variance.New()
stats2.Add(3)
// Merge the values of stats2 into stats1.
stats1.Merge(stats2)
// Reset the values in stats2.
stats2.Clear()
// Output: 0.5 0.3 0.5477225575051661 0.25 0.5 6
}
Feel free to submit PRs or to fill issues. Every kind of help is appreciated. Before committing, make
should run without any issues. Kindly check our Contributing guide on how to propose bug fixes and improvements, and submitting pull requests to the project.
© Axiom, Inc., 2021
Distributed under MIT License (The MIT License
).
See LICENSE for more information.