]> git.sesse.net Git - wloh/commitdiff
Use sum-of-squares instead absolute-single-greatest-change as metric for convergence.
authorSteinar H. Gunderson <Steinar H. Gunderson sesse@debian.org>
Fri, 16 Mar 2012 23:31:49 +0000 (00:31 +0100)
committerSteinar H. Gunderson <Steinar H. Gunderson sesse@debian.org>
Fri, 16 Mar 2012 23:31:49 +0000 (00:31 +0100)
bayeswf.cpp

index f4f52d2aa6e4d3e649dfd189894f7c03f50ce1c8..952322d39ef96d22ea0ed2a7108b6149471b86de 100644 (file)
@@ -247,15 +247,13 @@ int main(int argc, char **argv)
                        update_sigma(mu, sigma, i, matches_for_player[i]);
                        dump_scores(players, mu, sigma, num_players);
                } */
-               bool any_difference = false;
+
+               float sumdiff = 0.0f;
                for (int i = 0; i < num_players; ++i) {
-                       if (fabs(mu[i] - old_mu[i]) > EPSILON ||
-                           fabs(sigma[i] - old_sigma[i]) > EPSILON) {
-                               any_difference = true;
-                               break;
-                       }
+                       sumdiff += (mu[i] - old_mu[i]) * (mu[i] - old_mu[i]);
+                       sumdiff += (sigma[i] - old_sigma[i]) * (sigma[i] - old_sigma[i]);
                }
-               if (!any_difference) {
+               if (sumdiff < EPSILON) {
                        fprintf(stderr, "Converged after %d iterations. Stopping.\n", j);
                        break;
                }