Rolling Averages

From Robowiki
Revision as of 12: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 ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.