]> git.sesse.net Git - wloh/commitdiff
Take prior into account when computing Hessian.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 19 Mar 2012 01:15:26 +0000 (02:15 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 19 Mar 2012 01:15:26 +0000 (02:15 +0100)
bayeswf.cpp

index 7ee0120a592e23f1075ebef4cfc1a7cb36fbec47..71686c999cb944f2af6226d23b9fcf7e07d9115e 100644 (file)
@@ -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]);
        }