# Segmentation/Smoothing

A bit of a debated issue, smoothing is the act of weighting each value in your array based on the values surrounding it. This usually takes the shape of adding half of the values to either side, or to add a proportion of all the surrounding values that decays as it gets further away (v/n^2). There is also the concept of windowing, in which data is placed into adjoining bins if the bot width is greater than the size of the bin at that distance. Decay involves weighting more recent data higher than older data, which helps adapt to changes in movement. Decay is typically performed using a type of rolling average.

## Contents |

## Windowing

Hits are registered to all GuessFactors that would have hit, no matter where the robot center is. For example, if the wave registers that the target's center was one unit away from the edge of the bin, it will count for both the bin the center is in and the bin next to it, for both bins would have hit. Logically this would have a greater effect at closer distances.

### Disadvantages

Slow learning speed - chances are that if the enemy ended up in one place, they could just as likely have ended up in nearby spots in similar conditions, given more time, so those spots are also relevant. Even though having a continuous window for each hit in a segment and being able to find the largest real intersection would be optimal over time, trying to guess where the rest of the statistical distribution is that you haven't seen yet would be optimal in the short term.

## One to Side Smoothing

The issue with one to side smoothing is that edge boxes will only get half the addition (lacking information on the other side). Probably the best way to deal with this issue is to count the side that is there twice, thus keeping things even.

### Pugilist

double smoothedVisits(int index) { double smoothed = 0; int i = 0; do { smoothed += (double)visits[i] / Math.sqrt((double)(Math.abs(index - i) + 1.0)); i++; } while (i < Pugilist.FACTORS); return smoothed / Math.pow(distanceToTarget() / bulletVelocity, 1.3); }

### PPP

double smoothedVisits(int index) { double smoothed = 0; if (index > 0) { smoothed += visits[index - 1] / 2; } if (index < FACTORS - 1) { smoothed += visits[index + 1] / 2; } smoothed += visits[index]; return smoothed; }

## Full Range Smoothing

(I have not yet seen an implementation of this, although it has been mentioned)

## Rolling Average

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

## Andrew's Cool Way

void registerVisitsAndrewsCoolWay(double[] buffer, int index) { for (int i = 1; i < FACTORS; i++) { buffer[i] *= 0.98; } buffer[index] += 0.01; if (index + 1 < FACTORS) { buffer[index + 1] += 0.006; } if (index - 1 > 0) { buffer[index - 1] += 0.006; } }