# Bin Smoothing

The process of spreading or normalizing the values stored in a Visit Count Stats bin.

With VCS, the full range of firing angles is split up into a number of discrete bins. When recording a visit (gun) or bullet hit (movement), the bin covering the firing angle is incremented. Bin Smoothing means also incrementing some or all of the rest of the bins to a lesser degree - i.e., creating a smooth graph across all the bins, instead of a single spike in the visited bin.

It's debatable if this actually improves performance, especially in guns. Nevertheless, it is a common practice.

## Bin Smoothing formulas

### Inverse square

A common method is to increase the visited bin by 1 and all other bins by `(1 / square(abs(binIndex - visitIndex) + 1))`. The pattern of values added to the visited bin and its neighbors would be: 1, 1/4, 1/9, 1/16.

```    public static void logHit(double[] bins, int index) {
for (int x = 0; x < bins.length; x++) {
bins[x] += 1 / Math.pow(Math.abs(x - index) + 1, 2);
}
}```

### From Pugilist

This smooths the bin values as they are read from the visits array, using all the other bin values weighted by distance:

```    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

This also smooths the bin values as they are read, using only the two closest neighbor bins:

```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;
}```

### Other ways

`Math.pow(0.5, Math.abs(index - count))` - This pattern would be: 1, 0.5, 0.25, 0.125.

`Math.pow(0.1, Math.abs(index - count))` - This pattern would be: 1, 0.1, 0.01, 0.001.