]> git.sesse.net Git - wloh/commitdiff
Store the aux params in textual form in the database, instead of abusing the rating...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 30 May 2012 19:35:19 +0000 (21:35 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 30 May 2012 19:35:19 +0000 (21:35 +0200)
bayeswf.cpp
common.pm
train.pl

index cab5afcc896cdc9d34be48a96c2037da2ed0d0c8..cc591832a556f023ea6aa364a44ce5422a0b0740 100644 (file)
@@ -340,7 +340,7 @@ int main(int argc, char **argv)
                sumdiff += (global_sigma - old_global_sigma) * (global_sigma - old_global_sigma);
                if (sumdiff < EPSILON) {
                        //fprintf(stderr, "Converged after %d iterations. Stopping.\n", j);
-                       printf("%d 0 -1\n", j + 1);
+                       printf("aux_param num_iterations %d\n", j + 1);
                        break;
                }
        }
@@ -352,10 +352,10 @@ int main(int argc, char **argv)
        compute_mu_uncertainty(mu, players);
        dump_scores(players, mu, mu_stddev, num_players);
        //fprintf(stderr, "Optimal sigma: %f (two-player: %f)\n", sigma[0], sigma[0] * sqrt(2.0f));
-       printf("%f 0 -2\n", global_sigma / sqrt(2.0f));
-       printf("%f 0 -3\n", prior_sigma);
+       printf("aux_param score_stddev %f\n", global_sigma / sqrt(2.0f));
+       printf("aux_param rating_prior_stddev %f\n", prior_sigma);
 
        float total_logl = compute_total_logl(mu, num_players);
-       printf("%f 0 -4\n", total_logl);
+       printf("aux_param total_log_likelihood %f\n", total_logl);
 #endif
 }
index ee38a63937535acbcb112f0fa67a07967e10d722..a5784003f39f2a13a9b73a128b2b44c96624f912 100644 (file)
--- a/common.pm
+++ b/common.pm
@@ -32,20 +32,12 @@ sub get_locale {
 sub get_auxillary_parameters {
        my ($dbh) = @_;
 
-       my %aux_parm_names = {
-               -1 => num_iterations,
-               -2 => score_stddev,
-               -3 => rating_prior_stddev,
-               -4 => total_log_likelihood,
-       };
-
-       my $q = $dbh->prepare('SELECT * FROM ratings WHERE id < 0');
+       my $q = $dbh->prepare('SELECT * FROM aux_params');
        $q->execute;
 
        my $aux_parms = {};
        while (my $ref = $q->fetchrow_hashref) {
-               my $id = $ref->{'id'};
-               $aux_parms->{$aux_parm_names{$id}} = $ref->{'rating'};
+               $aux_parms->{$ref->{'id'}} = $ref->{'value'};
        }
        return $aux_parms;
 }
index daa4d7805055da03d5a83e98a8b1b58f83daea9d..f104b7016191129fb7ba567fde5e00b38f29cbc0 100755 (executable)
--- a/train.pl
+++ b/train.pl
@@ -58,7 +58,7 @@ sub output_to_file {
 }
 
 sub train_model {
-       my ($filename, $ratings, $covariances) = @_;
+       my ($filename, $ratings, $covariances, $aux_params) = @_;
 
        open RATINGS, "$config::base_dir/bayeswf < $filename |"
                or die "bayeswf: $!";
@@ -67,6 +67,8 @@ sub train_model {
                my @x = split;
                if ($x[0] eq 'covariance') {
                        push @$covariances, (join("\t", @x[1..3]));
+               } elsif ($x[0] eq 'aux_param') {
+                       push @$aux_params, ("nb-NO" .  "\t" . $x[1] . "\t" . $x[2]);
                } else {
                        push @$ratings, ($x[2] . "\t" . $x[0] . "\t" . $x[1]);
                }
@@ -90,9 +92,15 @@ my $tmpnam = output_to_file(\@games, \%ids);
 
 my @ratings = ();
 my @covariances = ();
-train_model($tmpnam, \@ratings, \@covariances);
+my @aux_params = ();
+train_model($tmpnam, \@ratings, \@covariances, \@aux_params);
 unlink($tmpnam);
 
+$dbh->do('TRUNCATE aux_params');
+$dbh->do('COPY aux_params ( kultur, id, value ) FROM STDIN');
+$dbh->pg_putcopydata(join("\n", @aux_params));
+$dbh->pg_putcopyend();
+
 $dbh->do('TRUNCATE ratings');
 $dbh->do('COPY ratings ( id, rating, rating_stddev ) FROM STDIN');
 $dbh->pg_putcopydata(join("\n", @ratings));