From 1e27ce64b3bd8574c621f1b7d47f94593d99318b Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 18 Mar 2012 23:11:39 +0100 Subject: [PATCH] Make the Hessian calculation use the new all_matches vector. --- bayeswf.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/bayeswf.cpp b/bayeswf.cpp index 9365a10..487774e 100644 --- a/bayeswf.cpp +++ b/bayeswf.cpp @@ -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) { -- 2.39.2