Skip to content

Tiny Java utility to incrementally calculate Mean and Standard Deviation with a numerically stable algorithm.

License

Notifications You must be signed in to change notification settings

yaomingchen/meanvar

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Tiny Java utility to incrementally calculate Mean and Standard Deviation with a numerically stable algorithm.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.2%
  • HTML 0.8%