X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=recalc-single-result.pl;fp=recalc-single-result.pl;h=679478791027ecb283f9ea6a88028b9ac8fc3d19;hb=63503a1ac42bc03c97642b1ccbc07b2cfdad7a98;hp=c67be84b36e84a68e3fba5bd596e57b2e4b460a1;hpb=2e45e0e9f8d23adcf88fb89b7fa83a5a7d8d02ec;p=foosball 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;