 ### Normalize the noise

```In the early stages of the game, a pure perceptron will have a very
slim amplitude for the predictions, because anything can happen.
However, the noise will still be between -100 and 100.

By this trick, all predictions have a mean of 0 and a standard
deviation of 1.```
parent 74e2c5e6
 ... ... @@ -169,13 +169,55 @@ ai_barycenter_2_eval (void *state, const TarotGame * base, size_t i; struct ai_barycenter_2 *couple = (struct ai_barycenter_2 *) state; double *s1, *s2; double sum_1 = 0, sum_2 = 0, ssq_1 = 0, ssq_2 = 0; double mean_1, var_1, mean_2, var_2, n = 0; double sd_1, sd_2; s1 = xcalloc (max, sizeof (double)); s2 = xcalloc (max, sizeof (double)); ai_eval (&(couple->ai1), base, n_candidates, candidates, start, max, s1); ai_eval (&(couple->ai2), base, n_candidates, candidates, start, max, s2); for (i = 0; i < max && i + start < n_candidates; i++) { double val_1 = s1[i]; double val_2 = s2[i]; double sq_1 = val_1 * val_1; double sq_2 = val_2 * val_2; sum_1 += val_1; sum_2 += val_2; ssq_1 += sq_1; ssq_2 += sq_2; n++; } mean_1 = sum_1 / n; mean_2 = sum_2 / n; var_1 = ssq_1 / n - (mean_1 * mean_1); var_2 = ssq_2 / n - (mean_2 * mean_2); /* Something like -1e-16 */ if (var_1 < 0) { var_1 = 0; } if (var_2 < 0) { var_2 = 0; } sd_1 = sqrt (var_1); sd_2 = sqrt (var_2); /* If we get NaNs in the pure AI, the result will be NaN, and it * should be that of the random player. */ if (sd_1 == 0) { sd_1 = 1; } if (sd_2 == 0) { sd_2 = 1; } for (i = 0; i < max; i++) { scores[i] = couple->w1 * s1[i] + couple->w2 * s2[i]; double s1_i = (s1[i] - mean_1) / sd_1; double s2_i = (s2[i] - mean_2) / sd_2; scores[i] = couple->w1 * s1_i + couple->w2 * s2_i; } free (s1); free (s2); ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!