Skip to content
Tiny Java utility to incrementally calculate Mean and Standard Deviation with a numerically stable algorithm.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore Updated .gitignore; fixed copy/paste error in javadoc of MeanVariance… Nov 15, 2018
.travis.yml removed oracleJdk7 as it is no longer supported by travis CI Dec 31, 2017
LICENSE prepare for release in maven central Apr 11, 2018
README.md Update README.md Aug 17, 2018
build.gradle Fix copy/paste typo in name attribute of staging pom file Apr 23, 2018

README.md

Build Status Coverage Status Maven Central Javadocs

tools4j-meanvar

Tiny Java utility to incrementally calculate Mean and Standard Deviation with a numerically stable algorithm. Contains a simple utility class to incrementally calculate moving average and moving standard deviation of a data series.

The implementation is based on Welford’s Algorithm given in Knuth Vol 2, p 232.

Examples

MeanVarianceSampler
final MeanVarianceSampler sampler = new MeanVarianceSampler();

double mean, var, stdDev;

sampler.add(1);
sampler.add(2.5);
sampler.add(3.22);
sampler.add(-6.72);
mean = sampler.getMean();
var = sampler.getVariance();
stdDev = sampler.getStdDev();

sampler.remove(2.5);
mean = sampler.getMean();
var = sampler.getVariance();
stdDev = sampler.getStdDev();

sampler.replace(3.22, 4.22);
mean = sampler.getMean();
var = sampler.getVariance();
stdDev = sampler.getStdDev();
MeanVarianceSlidingWindow
final int windowSize = 3;
final MeanVarianceSlidingWindow win = new MeanVarianceSlidingWindow(windowSize);

double mean, var, stdDev;

win.update(1);
win.update(2);
win.update(3);
mean = win.getMean();
var = win.getVariance();
stdDev = win.getStdDev();

//1 drops out now
win.update(4);
mean = win.getMean();
var = win.getVariance();
stdDev = win.getStdDev();

//2 drops out now
win.update(5);
mean = win.getMean();
var = win.getVariance();
stdDev = win.getStdDev();

Maven

Add the following dependency to your maven pom.xml file:

<dependency>
    <groupId>org.tools4j</groupId>
    <artifactId>tools4j-meanvar</artifactId>
    <version>1.1</version>
</dependency>

Gradle

Add the following entry to the dependencies section in your build.gradle file:

dependencies {
    compile 'org.tools4j:tools4j-meanvar:1.1'
}

Download

Sources and binaries can be downloaded from maven central:

API Javadoc

Javadocs

More Information

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.