Difference between revisions of "Bin Smoothing"

From Robowiki
Jump to navigation Jump to search
m (cleanup)
m (→‎PPP: very minor edit)
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{stub}}
+
The process of spreading or normalizing the values stored in a [[Visit Count Stats]] bin.  
Bin Smoothing is the process of spreading or normalizing the values stored in a Bin for [[Wave Surfing]] or [[Segmentation]]. It's not needed for [[Wave Surfing]] or [[Segmentation]], but can, in theory, improve performance if done right.
 
  
== How Bin Smoothing works ==
+
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.
Bin Smoothing 'flattens' small spikes within it's Bins.
 
  
== Bin Smoothing Formulas ==
+
It's debatable if this actually improves performance, especially in [[:Category:Targeting|guns]]. Nevertheless, it is a common practice.
If you have your own Bin Smoothing Formula, feel free to post it here.
 
  
=== [[Pugilist]]'s ===
+
== Bin Smoothing formulas ==
<pre>
+
=== Inverse square ===
 +
A common method is to increase the visited bin by 1 and all other bins by <code>(1 / square(abs(binIndex - visitIndex) + 1))</code>. The pattern of values added to the visited bin and its neighbors would be: 1, 1/4, 1/9, 1/16.
 +
<syntaxhighlight>
 +
    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);
 +
        }
 +
    }
 +
</syntaxhighlight>
 +
 
 +
=== From [[Pugilist]] ===
 +
This smooths the bin values as they are read from the visits array, using all the other bin values weighted by distance:
 +
<syntaxhighlight>
 
     double smoothedVisits(int index) {
 
     double smoothedVisits(int index) {
 
double smoothed = 0;
 
double smoothed = 0;
Line 19: Line 28:
 
return smoothed / Math.pow(distanceToTarget() / bulletVelocity, 1.3);
 
return smoothed / Math.pow(distanceToTarget() / bulletVelocity, 1.3);
 
     }
 
     }
</pre>
+
</syntaxhighlight>
  
 
=== PPP ===
 
=== PPP ===
<pre>
+
This also smooths the bin values as they are read, using only the two closest neighbor bins:
 +
<syntaxhighlight>
 
double smoothedVisits(int index) {
 
double smoothedVisits(int index) {
 
     double smoothed = 0;
 
     double smoothed = 0;
Line 34: Line 44:
 
     return smoothed;
 
     return smoothed;
 
}
 
}
</pre>
+
</syntaxhighlight>
 +
 
 
=== Other ways ===
 
=== Other ways ===
<pre>Math.pow(0.5, Math.abs(index - count))</pre>
+
<code>Math.pow(0.5, Math.abs(index - count))</code> - This pattern would be: 1, 0.5, 0.25, 0.125.
This does a 50% decrease.
+
 
 +
<code>Math.pow(0.1, Math.abs(index - count))</code> - This pattern would be: 1, 0.1, 0.01, 0.001.
 +
 
 +
== See also ==
 +
* [[Visit Count Stats]]
  
<pre>Math.pow(0.1, Math.abs(index - count))</pre>
+
__NOTOC__
This does a 90% decrease
 
  
<pre>1.0/(double)(1 + (index - count)*(index - count))</pre>
+
[[Category:Terminology]]

Latest revision as of 23:20, 24 December 2013

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.

See also