Skip to content

Instantly share code, notes, and snippets.

@digitalex
Created September 24, 2012 12:50
Show Gist options
  • Save digitalex/3775801 to your computer and use it in GitHub Desktop.
Save digitalex/3775801 to your computer and use it in GitHub Desktop.
Cumulative Moving Average
class CumulativeMovingAverage {
int n = 0;
double average = 0.0;
public double add(double x) {
return average += (x - average) / ++n;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment