Games-Go-AGA-BayRate

 view release on metacpan or  search on metacpan

bin/bayrate.pl  view on Meta::CPAN

            }
        }
    }
    $sth->finish;
    return if (not @games);

    my $collection = Games::Go::AGA::BayRate::Collection->new(
            iter_hook         => \&iter_hook,
            tournamentDate    => $tournamentDate,
            strict_compliance => $strict_compliance, # match original bayrate C++ code exactly
            #f_iterations     => 50,
            #fdf_iterations   => 50,
    );

    # enter all the players who were in a game
    my %players_by_id;
    foreach my $id (sort { $a <=> $b } keys %player_seeds_by_id) {
        $players_by_id{$id} = $collection->add_player(
            id     => $id,
            seed   => $player_seeds_by_id{$id},
            sigma  => 6.0,  # will get changed later
        );

lib/Games/Go/AGA/BayRate.pm  view on Meta::CPAN

sub new {
    my ($proto, %args) = @_;

    my $self = {};
    bless($self, ref($proto) || $proto);

    my $collection
    = $self->{collection}
    = Games::Go::AGA::BayRate::Collection->new(
            iter_hook             => \&iter_hook, # called once per f or fdf iteration
        #   fdf_iterations        =>  # number fdf_iterations to perform
        #   fdf_gradient_spec     =>  # fdf gradient to test against
        #   f_iterations          =>  # number f_iterations to perform
        #   f_size                =>  # f size to test against
        #   calc_ratings_failover =>  # force failover to calc_ratings_f
        #   calc_sigma_failover   =>  # force failover to calc_sigma2
        #   strict_compliance     =>  # adnere exactly to original bayrate C++ code
    );

    # enter all the players who were in a game
    my $players = $args{players} || [];
    foreach my $player ( @{$players} ) {
        $self->add_player($player);

lib/Games/Go/AGA/BayRate/Collection.pm  view on Meta::CPAN


sub new {
    my ($proto, %args) = @_;

    # Initialize a random number generator
    # NOTE: we use a different method, see "Populate the storage vector"
    # $self->{rng} = gsl_rng_alloc(gsl_rng_default);

    my $self = {};
    bless($self, ref($proto) || $proto);
    $self->{fdf_iterations}    = 10000;
    $self->{fdf_gradient_spec} = 0.001;
    $self->{f_iterations}      = 1000000;
    $self->{f_size}            = 0.00001;
    foreach my $name (                  # optional arguments
            'iter_hook',                # called once per f or fdf iteration
            'fdf_iterations',           # number fdf_iterations to perform
            'fdf_gradient_spec',        # fdf gradient to test against
            'f_iterations',             # number f_iterations to perform
            'f_size',                   # f size to test against
            'calc_ratings_failover',    # force failover to calc_ratings_f
            'calc_sigma_failover',      # force failover to calc_sigma2
            'strict_compliance',        # adnere exactly to original bayrate C++ code
            'verbose',                  # print lots of info about vectos and matrix assignments
        ) {
        $self->{$name} = delete $args{$name} if (exists $args{$name});
    }
    $self->tournamentDate(delete $args{tournamentDate} || '0000-01-01');
    if (keys %args) {

lib/Games/Go/AGA/BayRate/Collection.pm  view on Meta::CPAN

            $self,     # params  function params passed to f
        # end of gsl_multimin_function_f structure members:
        $raw_x,    # vector containing the player seeds
        $raw_ss,   # step size
    );

    my $iter = 0;
    my $status = $GSL_CONTINUE;
    my $f_size = $self->{f_size};
    while (    $status == $GSL_CONTINUE
           and $iter   <= $self->{f_iterations}) {
        $iter++;
        $status = gsl_multimin_fminimizer_iterate($state);

        last if ($status != $GSL_SUCCESS);  # eh?  why not CONTINUE?

        $status = gsl_multimin_test_size(gsl_multimin_fminimizer_size($state), $f_size);
        if ($self->{iter_hook}) {
            &{$self->{iter_hook}}($self, $state, $iter, $status);     # call user iteration hook
        }

lib/Games/Go/AGA/BayRate/Collection.pm  view on Meta::CPAN

        2.0,       # step size
        0.1,       # accuracy required
    );

    # Main loop.  Continue iterating until the likelihood function hits an extreme, or
    # until an error occurs.
    my $iter = 0;
    my $status = $GSL_CONTINUE;
    my $gradient_spec = $self->{fdf_gradient_spec};
    while (    $status == $GSL_CONTINUE
           and $iter < $self->{fdf_iterations}) {
        $iter++;
        gsl_multimin_fdfminimizer_iterate($state);

        last if ($status != $GSL_CONTINUE);

        my $gradient = raw_gsl_multimin_fdfminimizer_gradient($state);
        $status = gsl_multimin_test_gradient($gradient, $gradient_spec);
        if ($self->{iter_hook}) {
            &{$self->{iter_hook}}($self, $state, $iter, $status);     # call user iteration hook
        }

lib/Games/Go/AGA/BayRate/Collection.pm  view on Meta::CPAN


__END__

=head1 SYNOPSIS

  use Games::Go::AGA::BayRate::Collection;
  my $collection = Games::Go::AGA::BayRate::Collection->new(
          iter_hook      => \&iter_hook,
          tournamentDate => $tournamentDate,
          strict_compliance => $strict_compliance, # match original bayrate C++ code exactly
          #f_iterations   => 50,    # iteration limit for f method
          #fdf_iterations => 50,    # iteration limit for fdf method
          #verbose => 1,            # lots of debugging info (to STDOUT)
  );

    foreach my $player (@players) {
        $collection->add_player(
            id     => $_player->id,
            seed   => $_player->seed,
          # sigma  => 0.0,  # may not need this
        );
    }



( run in 0.775 second using v1.01-cache-2.11-cpan-71847e10f99 )