Difference between revisions of "Rolling Averages"
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 | + | 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 | + | 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 14: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.