]> git.sesse.net Git - wloh/commitdiff
Add an option to dump out the raw scores, for observation/curve-fitting.
authorSteinar H. Gunderson <Steinar H. Gunderson sesse@debian.org>
Sun, 18 Mar 2012 10:59:20 +0000 (11:59 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 18 Mar 2012 12:02:06 +0000 (13:02 +0100)
bayeswf.cpp

index 2dfc85bab1c7663361681ca5f7afe5eee351cf2f..c54f72ab03d82cb7edc5c18f209e7620a3490ca1 100644 (file)
@@ -12,6 +12,7 @@ using namespace std;
 
 #define PRIOR_MU 1500
 #define MAX_PLAYERS 4096
+#define DUMP_RAW 0
 
 float mu[MAX_PLAYERS];
 float sigma[MAX_PLAYERS];
@@ -90,6 +91,31 @@ void update_mu(float *mu, float *sigma, int player_num, const vector<match> &mat
        mu[player_num] = nom / denom;
 }
 
+void dump_raw(const float *mu, const float *sigma, int num_players)
+{
+       for (int i = 0; i < num_players; ++i) {
+               for (unsigned j = 0; j < matches_for_player[i].size(); ++j) {
+                       const match& m = matches_for_player[i][j];
+
+                       // Only count each match once.
+                       if (m.other_player <= i) {
+                               continue;
+                       }
+
+                       float mu1 = mu[i];
+                       float mu2 = mu[m.other_player];
+                       float sigma1 = sigma[i];
+                       float sigma2 = sigma[m.other_player];
+                       float sigma = sqrt(sigma1 * sigma1 + sigma2 * sigma2);
+                       float mu = mu1 - mu2;
+                       float x = m.margin;
+                       float w = m.weight;
+
+                       printf("%f %f\n", (x - mu) / sigma, w);
+               }
+       }
+}
+
 /*
  * diff(logL, sigma1) = sigma1 (-sigma1² - sigma2² + (x - mu)²) / sigma_c²
  * maximizer for sigma1 is given by: sum_i[ (1/sigma_c_i)² sigma1 ((x - mu)² - (sigma1² + sigma2²) ] = 0
@@ -323,10 +349,15 @@ int main(int argc, char **argv)
                        break;
                }
        }
+
+#if DUMP_RAW
+       dump_raw(mu, sigma, num_players);
+#else
        dump_scores(players, mu, sigma, num_players);
        //fprintf(stderr, "Optimal sigma: %f (two-player: %f)\n", sigma[0], sigma[0] * sqrt(2.0f));
        printf("%f -2\n", sigma[0]);
        printf("%f -3\n", prior_sigma);
 
 //     construct_hessian(mu, sigma, num_players);
+#endif
 }