Rolling Averages
Revision as of 11:22, 16 February 2009 by Nat (talk | contribs) (New page: Rolling Averages, also know as Moving Average, was brought to robocode comunity by Paul Evans. This kind of average allow you to kept only recent data on averaging. Here are the first ...)
Rolling Averages, also know as Moving Average, was brought to robocode comunity by Paul Evans. This kind of average allow you to kept only recent data on averaging. Here are the first code publish by Paul and continue using among top bot in rumble.
public static double rollingAvg(double value, double newEntry, double n, double weighting ) { return (value * n + newEntry * weighting)/(n + weighting); }
Here are the same implementation use by SpareParts. It more clear to understand but it slower.
class Averager { private ArrayList<Double> data = new ArrayList(); public void add(double v) { data.add(0, (Double)v); } public void get(int dept) { int i = 0; double d; for (Double v : data) { i++; if (i > depth) break; d += (double)v; } return d/i; } }
Note that code above is untested.