From 63503a1ac42bc03c97642b1ccbc07b2cfdad7a98 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 2 Dec 2007 12:45:59 +0100 Subject: [PATCH] Make the initial rating/RD constants instead of hard-coded values. --- foosball.pm | 4 ++-- foosrank.cpp | 13 +++++++++++-- recalc-single-result.pl | 12 ++++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/foosball.pm b/foosball.pm index 58e468c..b40b9fd 100644 --- a/foosball.pm +++ b/foosball.pm @@ -75,11 +75,11 @@ sub calc_rating { my ($rating1, $rd1, $rating2, $rd2, $score1, $score2) = @_; my $result = `/srv/foosball.sesse.net/foosrank $rating1 $rd1 $rating2 $rd2 $score1 $score2`; chomp $result; - my ($newr1, $newrd1) = split / /, $result; + my ($newr1, $newrd1, $likelihood) = split / /, $result; $newrd1 = 30.0 if ($newrd1 < 30.0); - return ($newr1, $newrd1); + return ($newr1, $newrd1, $likelihood); } sub calc_rating_double { diff --git a/foosrank.cpp b/foosrank.cpp index 99f88b0..67aee58 100644 --- a/foosrank.cpp +++ b/foosrank.cpp @@ -484,7 +484,11 @@ int main(int argc, char **argv) int score2 = atoi(argv[10]); double mu, sigma; compute_new_double_rating(mu1, sigma1, mu2, sigma2, mu3, sigma3, mu4, sigma4, score1, score2, mu, sigma); - printf("%f %f\n", mu, sigma); + if (score1 > score2) { + printf("%f %f %f\n", mu, sigma, prob_score(score1, score2, mu3+mu4-(mu1+mu2))); + } else { + printf("%f %f %f\n", mu, sigma, prob_score(score2, score1, mu1+mu2-(mu3+mu4))); + } } else if (argc > 8) { double mu3 = atof(argv[5]); double sigma3 = atof(argv[6]); @@ -520,7 +524,12 @@ int main(int argc, char **argv) int score2 = atoi(argv[6]); double mu, sigma; compute_new_rating(mu1, sigma1, mu2, sigma2, score1, score2, mu, sigma); - printf("%f %f\n", mu, sigma); + + if (score1 > score2) { + printf("%f %f %f\n", mu, sigma, prob_score(score1, score2, mu2-mu1)); + } else { + printf("%f %f %f\n", mu, sigma, prob_score(score2, score1, mu1-mu2)); + } } else { int k = atoi(argv[5]); diff --git a/recalc-single-result.pl b/recalc-single-result.pl index c67be84..6794787 100755 --- a/recalc-single-result.pl +++ b/recalc-single-result.pl @@ -15,6 +15,9 @@ my %ratings = (); my $q = $dbh->prepare('select *,extract(epoch from gametime) as eptime from single_results order by gametime'); $q->execute; +# Combined log-likelihood +my $cll = 0.0; + while (my $ref = $q->fetchrow_hashref) { for my $user (($ref->{'username1'}, $ref->{'username2'})) { if (!exists($ratings{$user})) { @@ -36,10 +39,12 @@ while (my $ref = $q->fetchrow_hashref) { $rd1 = foosball::apply_aging($rd1, $age1 / 86400.0); $rd2 = foosball::apply_aging($rd2, $age2 / 86400.0); - my ($newr1, $newrd1) = foosball::calc_rating($rating1, $rd1, $rating2, $rd2, $score1, $score2); + my ($newr1, $newrd1, $likelihood) = foosball::calc_rating($rating1, $rd1, $rating2, $rd2, $score1, $score2); my ($newr2, $newrd2) = foosball::calc_rating($rating2, $rd2, $rating1, $rd1, $score2, $score1); - printf("%-10s - %-10s: %u - %u, new ratings %u/%u %u/%u\n", + $cll += log($likelihood); + + printf("%-10s - %-10s: %u - %u, new ratings %u/%u %u/%u [$likelihood]\n", $ref->{'username1'}, $ref->{'username2'}, $ref->{'score1'}, $ref->{'score2'}, $newr1, $newrd1, $newr2, $newrd2); $dbh->do('insert into single_rating values (?,?,?,?,?)', undef, @@ -53,3 +58,6 @@ while (my $ref = $q->fetchrow_hashref) { $dbh->commit; $dbh->disconnect; + +printf "\nCombined negative log-likelihood (smaller value means a better model): %f\n", + -$cll; -- 2.39.2