Difference between revisions of "Rolling Averages"

From Robowiki
Jump to navigation Jump to search
(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 ...)
 
m (Grammar correction)
Line 1: Line 1:
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 Evans|Paul]] and continue using among top bot in rumble.
+
Rolling Averages, also known as Moving Averages, were brought to the robocode community by [[Paul Evans]]. This kind of average allows you to keep only recent data upon averaging. Here is the first code published by [[Paul Evans|Paul]] and still used among top bots in the rumble.
  
 
<pre>
 
<pre>
Line 7: Line 7:
 
</pre>
 
</pre>
  
Here are the same implementation use by SpareParts. It more clear to understand but it slower.
+
Here is the same implementation as used by SpareParts. It is easier to understand but slower.
 
<pre>
 
<pre>
 
class Averager {
 
class Averager {

Revision as of 15:24, 16 February 2009

Rolling Averages, also known as Moving Averages, were brought to the robocode community by Paul Evans. This kind of average allows you to keep only recent data upon averaging. Here is the first code published by Paul and still used among top bots in the rumble.

public static double rollingAvg(double value, double newEntry, double n, double weighting ) {
    return (value * n + newEntry * weighting)/(n + weighting);
} 

Here is the same implementation as used by SpareParts. It is easier to understand but 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.