// Compute uncertainty (stddev) of mu estimates, which is sqrt((H^-1)_ii),
// where H is the Hessian (see construct_hessian()).
-void compute_mu_uncertainty(const float *mu, int num_players)
+void compute_mu_uncertainty(const float *mu, const vector<string> &players)
{
// FIXME: Use pseudoinverse if applicable.
Matrix<float, Dynamic, Dynamic> ih = hessian.inverse();
- for (int i = 0; i < num_players; ++i) {
+ for (unsigned i = 0; i < players.size(); ++i) {
mu_stddev[i] = sqrt(ih(i, i));
}
+
+ for (unsigned i = 0; i < players.size(); ++i) {
+ for (unsigned j = 0; j < players.size(); ++j) {
+ printf("covariance %s %s %f\n",
+ players[i].c_str(),
+ players[j].c_str(),
+ ih(i, j));
+ }
+ }
}
int main(int argc, char **argv)
dump_raw(mu, num_players);
#else
construct_hessian(mu, num_players);
- compute_mu_uncertainty(mu, num_players);
+ 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));
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
+$dbh->do('SET client_min_messages TO WARNING');
+
# Find last completely done season
my $ref = $dbh->selectrow_hashref('SELECT sesong FROM fotballserier GROUP BY sesong HAVING COUNT(*)=COUNT(avgjort=1 OR NULL) ORDER BY sesong DESC LIMIT 1');
my $last_season = $ref->{'sesong'};
}
close DATA;
-$dbh->do('DELETE FROM ratings');
-my $iq = $dbh->prepare('INSERT INTO ratings ( id, rating, rating_stddev ) VALUES (?, ?, ?)');
+my @ratings = ();
+my @covariances = ();
open RATINGS, "$config::base_dir/bayeswf < $tmpnam |"
or die "bayeswf: $!";
while (<RATINGS>) {
- /(.*) (.*) (.*)/ or next;
- $iq->execute($3, $1, $2);
+ chomp;
+ my @x = split;
+ if ($x[0] eq 'covariance') {
+ push @covariances, (join("\t", @x[1..3]));
+ } else {
+ push @ratings, ($x[2] . "\t" . $x[0] . "\t" . $x[1]);
+ }
}
+$dbh->do('TRUNCATE ratings');
+$dbh->do('COPY ratings ( id, rating, rating_stddev ) FROM STDIN');
+$dbh->pg_putcopydata(join("\n", @ratings));
+$dbh->pg_putcopyend();
+
+$dbh->do('CREATE TABLE new_covariance ( player1 smallint NOT NULL, player2 smallint NOT NULL, cov float NOT NULL )');
+$dbh->do('COPY new_covariance ( player1, player2, cov ) FROM STDIN');
+$dbh->pg_putcopydata(join("\n", @covariances));
+$dbh->pg_putcopyend();
+$dbh->do('ALTER TABLE new_covariance ADD PRIMARY KEY ( player1, player2 );');
+$dbh->do('DROP TABLE IF EXISTS covariance');
+$dbh->do('ALTER TABLE new_covariance RENAME TO covariance');
+
$dbh->commit;
unlink($tmpnam);