+float compute_logl(float z)
+{
+ return -0.5 * (log(2.0f / M_PI) + z * z);
+}
+
+float compute_total_logl(float *mu, float *sigma, int num_players)
+{
+ float total_logl = 0.0f;
+
+ // Prior.
+ for (int i = 0; i < num_players; ++i) {
+ total_logl += PRIOR_WEIGHT * compute_logl((mu[i] - PRIOR_MU) / prior_sigma);
+ }
+
+ // Matches.
+ for (unsigned i = 0; i < all_matches.size(); ++i) {
+ const match& m = all_matches[i];
+
+ float mu1 = mu[m.player];
+ float mu2 = mu[m.other_player];
+ float sigma1 = sigma[m.player];
+ 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;
+
+ total_logl += w * compute_logl((x - mu) / sigma);
+ }
+
+ return total_logl;
+}
+