]> git.sesse.net Git - wloh/commitdiff
Make the Hessian calculation use the new all_matches vector.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 18 Mar 2012 22:11:39 +0000 (23:11 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 18 Mar 2012 22:11:39 +0000 (23:11 +0100)
bayeswf.cpp

index 9365a1068ea460efb41e0008ef8543e0e5dd9053..487774ea394cb993c7b5c4499cd64f3fb6c30d55 100644 (file)
@@ -241,20 +241,23 @@ void construct_hessian(const float *mu, const float *sigma, int num_players)
 {
        memset(hessian, 0, sizeof(hessian));
 
-       for (int i = 0; i < num_players; ++i) {
-               double sigma1 = sigma[i];
+       for (unsigned i = 0; i < all_matches.size(); ++i) {
+               const match &m = all_matches[i];
 
-               for (unsigned k = 0; k < matches_for_player[i].size(); ++k) {
-                       int j = matches_for_player[i][k].other_player;
+               int p1 = m.player;
+               int p2 = m.other_player;
 
-                       double sigma2 = sigma[j];
-                       double sigma_sq = sigma1 * sigma1 + sigma2 * sigma2;
+               double sigma1 = sigma[m.player];
+               double sigma2 = sigma[m.other_player];
 
-                       float w = matches_for_player[i][k].weight;
+               double sigma_sq = sigma1 * sigma1 + sigma2 * sigma2;
+               float w = m.weight;
 
-                       hessian[i][j] -= w / sigma_sq;
-                       hessian[i][i] += w / sigma_sq;
-               }
+               hessian[p1][p2] -= w / sigma_sq;
+               hessian[p2][p1] -= w / sigma_sq;
+
+               hessian[p1][p1] += w / sigma_sq;
+               hessian[p2][p2] += w / sigma_sq;
        }
 
        for (int i = 0; i < num_players; ++i) {