Visit Count Stats

From Robowiki
Revision as of 10:45, 18 September 2008 by Nfwu (talk | contribs) (8 links to uncreated page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Visit counts is a way to keep track of statistics. Typically this is implemented with an array or a List where each bucket contains a count on how many times it has been visited. Each element in the array is referred to as a bucket or a bin.

VisitCountStats and GuessFactorTargeting

See also: Talk:Visit Count Stats

Don't confuse visit counts and GuessFactorTargeting. They are not the same. VisitCountStats is an implementation detail, while GuessFactors is a targeting strategy.

You could have a GuessFactor gun without VisitCountStats, as in the DynamicClustering gun of Lukious; you could also have a VisitCountStats gun without GuessFactors, like using bearing offsets instead. The majority of GuessFactor guns, like the one in GFTargetingBot or the GuessFactorTargeting/Tutorial, are using VisitCountStats, but they're different things for sure.

Limit File Size

From VisitCountStats/LimitFileSize on the old wiki.

Visit count stats is simple and powerful. But if you save stats between battles you might find that the files tend to grow quite large as you fight more battles aginst an enemy. Here's a way to limit the size of your saved data files

    public void registerFactorVisit(int[] factors, int index) {
        if (factors[index] < MAX_FACTOR_VISITS) {
            factors[index]++;
        }
        else {
            decrementTheOtherFactors(factors, index);
        }
    }

    void decrementTheOtherFactors(int[] factors, int index) {
        for (int i = 0, numFactors = factors.length; i < numFactors; i++) {
            if (i != index && factors[i] > 0) {
                factors[i]--;
            }
        }
    }

What happens here is that visit counts never will exceed MAX_FACTOR_VISITS. When we are about to increment a visit count that has reached this maximum we instead decrement the surrounding visit counts.

If you set MAX_FACTOR_VISITS to 255 the visit count buckets will never grow above byte size and this sets a much lower limit on how big the files get.

An added benefit with this approach is that it offers some StatsDecay. Rolling averages is very effective for this though not always applicable VisitCountStats designs.

The trick is of course to set the max value correctly since it's not as easily figured as with rolling averages. You'll have to experiment some to get it right I guess. And what's right against one enemy might be wrong against some others. I guess that if you add VirtualGuns to this you can use some different maximums and let the VG array figure out what works or not against a given enemy.

Dynamic

From VisitCountStats/Dynamic on the old wiki.

Dynamic visit counts means you create a different number of visit buckets for different enemy distances. The point is that so that you shouldn't need smoothing the curve or calculate kernel densities or whatever before acting on the data in your stat buffers. It also keeps your stat files no bigger than necessary. Here's how it is implemented in GloomyDark. It assumes you are segmenting on distance, but that is a good segmentation in most cases:

...
    public static final double BOT_WIDTH = 36;
...

    int numFactors(double distance) {
        int n = (int)(1.25 * (distance / bulletVelocity(DEFAULT_BULLET_POWER) * MAX_VELOCITY / BOT_WIDTH));
        return n + 1 - n % 2;
    }

    int[][][][][] makeAimFactorVisits() {
        int[][][][][] factors = new int[ACCEL_SEGMENTS][AIM_VELOCITY_SEGMENTS][AIM_DISTANCE_SEGMENTS][1][];
        for (int a = 0; a < ACCEL_SEGMENTS; a++) {
            for (int v = 0; v < AIM_VELOCITY_SEGMENTS; v++) {
                for (int d = 0; d < AIM_DISTANCE_SEGMENTS; d++) {
                    factors[a][v][d][0] = new int[numFactors((d + 1) * MAX_DISTANCE / AIM_DISTANCE_SEGMENTS)];
                }
            }
        }
        return factors;
    }

Examples

Strategies

VisitCountStats can be used to store statistics for many strategies, including:

See Also