1 package Games
::Ratings
::LogisticElo
;
6 use parent qw
/Exporter Games::Ratings/;
8 our @EXPORT_OK = qw
/multi_elo/;
10 our $VERSION = '0.001';
12 use List
::Util qw
/sum/;
14 sub get_rating_change
{
17 my $own_rating = $self->get_rating;
18 my $K = $self->get_coefficient;
20 my $expected = sum
map {
21 my $exp = ($_->{opponent_rating
} - $own_rating) / 400;
23 } $self->get_all_games;
25 my $actual = sum
map {
26 Games
::Ratings
::_get_numerical_result
($_->{result
})
27 } $self->get_all_games;
29 $K * ($actual - $expected)
34 $self->get_rating + $self->get_rating_change
39 my $K = ref $args[0] ?
15 : shift @args;
41 my @newratings = map {
42 my $player = __PACKAGE__
->new;
43 $player->set_rating($_->[0]);
44 $player->set_coefficient($K);
45 for my $opponent (@args) {
47 opponent_rating
=> $opponent->[0],
49 $_->[1] > $opponent->[1] ?
'win' :
50 $_->[1] < $opponent->[1] ?
'loss' : 'draw'
53 $player->get_new_rating
56 wantarray ?
@newratings : \
@newratings
66 Games::Ratings::LogisticElo - calculate changes to logistic curve Elo ratings
70 use Games::Ratings::LogisticElo;
71 my $player = Games::Ratings::LogisticElo->new;
72 $player->set_rating(2240);
73 $player->set_coefficient(15);
75 opponent_rating => 2114,
76 result => 'win', ## or 'draw' or 'loss'
78 say 'Rating change: ' . $player->get_rating_change;
79 say 'New rating: ' . $player->get_new_rating;
81 use Games::Ratings::LogisticElo qw/multi_elo/;
82 my @results = [2240, 3], [2114, 2], [2300, 1];
83 my @new_ratings = multi_elo 15, @results;
84 say 'Rating changes for this comp: ', join ', ',
85 map { $new_ratings[$_] - $results[$_]->[0] } 0 .. $#results;
89 This module provides methods to calculate Elo rating changes. Unlike
90 L<Games::Ratings::Chess::FIDE>, this Elo implementation uses the
91 logistic distribution instead of the standard distribution.
93 This module can be used both for a single player who played multiple
94 rated games, and for a single competition with an arbitrary number of
99 Games::Ratings::LogisticElo inherits from L<Games::Ratings>, see that
100 module's documentation for information about the inherited methods.
102 Nothing is exported by default, the function B<multi_elo> can be
107 =item B<$self>->I<get_rating_change>
109 Computes and returns how much a player's rating changes after the
112 =item B<$self>->I<get_new_rating>
114 Adds the result of I<get_rating_change> to the old rating of the
115 player and returns this.
117 =item B<multi_elo> [$coefficient], @results
119 Computes the ratings after a competition with an arbitrary number of
122 The first argument is the coefficient. It is optional, with the
123 default coefficient being 15. The next arguments are the results of
124 the players. Each result is a 2-element arrayref, the first element
125 being the Elo rating of the player, and the second element being the
126 score that player obtained. The scores are only used to compare
127 players, their absolute values are irrelevant.
129 The return value is a list (in list context) or arrayref (in scalar
130 context) of ratings of all players after the competition, in the same
131 order as the arguments.
133 This function computes the ratings by considering that each player
134 played a game with every other player, with the winner of every game
135 being the player who got the highest score.
142 L<Games::Ratings::Chess::FIDE>, L<Games::Ratings>
144 L<https://en.wikipedia.org/wiki/Elo_rating>
148 Marius Gavrilescu <marius@ieval.ro>
150 =head1 COPYRIGHT AND LICENSE
152 Copyright (C) 2016 by Marius Gavrilescu
154 This library is free software; you can redistribute it and/or modify
155 it under the same terms as Perl itself, either Perl version 5.22.2 or,
156 at your option, any later version of Perl 5 you may have available.
This page took 0.02528 seconds and 4 git commands to generate.