]> git.sesse.net Git - wloh/blobdiff - train.pl
Store the aux params in textual form in the database, instead of abusing the rating...
[wloh] / train.pl
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));