From 3755fe5fbb4bafc3a0b32de691b7c287af91886a Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 19 Mar 2012 02:15:26 +0100 Subject: [PATCH] Take prior into account when computing Hessian. --- bayeswf.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bayeswf.cpp b/bayeswf.cpp index 7ee0120..71686c9 100644 --- a/bayeswf.cpp +++ b/bayeswf.cpp @@ -201,6 +201,9 @@ void construct_hessian(const float *mu, int num_players) { memset(hessian, 0, sizeof(hessian)); + for (int i = 0; i < num_players; ++i) { + hessian[i][i] += 1.0f / (prior_sigma * prior_sigma); + } for (unsigned i = 0; i < all_matches.size(); ++i) { const match &m = all_matches[i]; @@ -224,6 +227,14 @@ void compute_mu_uncertainty(const float *mu, int num_players) { memset(mu_stddev, 0, sizeof(mu_stddev)); + // Temporarily use mu_stddev to store the diagonal of the Hessian. + + // Prior. + for (int i = 0; i < num_players; ++i) { + mu_stddev[i] += 1.0f / (prior_sigma * prior_sigma); + } + + // Matches. for (unsigned i = 0; i < all_matches.size(); ++i) { const match &m = all_matches[i]; @@ -233,10 +244,11 @@ void compute_mu_uncertainty(const float *mu, int num_players) double sigma_sq = global_sigma * global_sigma; float w = m.weight; - // Temporarily use mu_stddev to store the diagonal of the Hessian. mu_stddev[p1] += w / sigma_sq; mu_stddev[p2] += w / sigma_sq; } + + // Now convert to standard deviation. for (int i = 0; i < num_players; ++i) { mu_stddev[i] = 1.0f / sqrt(mu_stddev[i]); } -- 2.39.2