def test_Improvement(self): initial_rating = 100 player1 = EloCompetitor(initial_rating=initial_rating) # if player1 beats someone with a high rating, their rating should go up. for _ in range(10): player2 = EloCompetitor(initial_rating=800) player1.beat(player2) self.assertGreater(player1.rating, initial_rating) initial_rating = player1.rating
def test_Decay(self): initial_rating = 800 player1 = EloCompetitor(initial_rating=initial_rating) # if player1 beats someone with a high rating, their rating should go up. for _ in range(10): player2 = EloCompetitor(initial_rating=100) player2.beat(player1) self.assertLess(player1.rating, initial_rating) initial_rating = player1.rating
def _register_player(self, name, player, initial_rating=None): """Add a player """ player_id = len(self.competitors) + 1 elo = EloCompetitor( initial_rating=initial_rating or self.initial_rating ) self.competitors[player_id] = name, player, elo return player_id
def fast_elo_ratings(df): """ creates fast moving elo ratings ... Parameters ---------- df: pd.DataFrame games dataframe Returns ------- df: pd.DataFrame with fast moving elo ratings added """ ratings = {} for x in df.home_team.unique(): ratings[x] = EloCompetitor() for x in df.away_team.unique(): ratings[x] = EloCompetitor() home_team_elo = [] away_team_elo = [] elo_exp = [] df = df.sort_values(by='date').reset_index(drop=True) for i, r in df.iterrows(): # get pre-game ratings elo_exp.append(ratings[r.home_team].expected_score(ratings[r.away_team])) home_team_elo.append(ratings[r.home_team].rating) away_team_elo.append(ratings[r.away_team].rating) # update ratings if r.home_team_win: ratings[r.home_team].beat(ratings[r.away_team]) else: ratings[r.away_team].beat(ratings[r.home_team]) df['elo_exp'] = elo_exp df['home_team_elo'] = home_team_elo df['away_team_elo'] = away_team_elo return df
def __init__(self, strategy, ai_settings, engine_settings=None): self.elo_comp = EloCompetitor(initial_rating=1000) self.strategy = strategy self.ai_settings = ai_settings self.engine_settings = engine_settings or {} fmt_settings = [ f"{k}={v}" for k, v in { **self.ai_settings, **self.engine_settings }.items() if k not in AI.IGNORE_SETTINGS_IN_TAG ] self.name = f"{strategy}({ ','.join(fmt_settings) })" self.fix_settings()
from elote import EloCompetitor good = EloCompetitor() better = EloCompetitor() best = EloCompetitor() print('Starting ratings:') print('%7.2f, %7.2f, %7.2f' % ( good.rating, better.rating, best.rating, )) print('\nAfter matches') for _ in range(10): better.beat(good) best.beat(better) print('%7.2f, %7.2f, %7.2f' % ( good.rating, better.rating, best.rating, ))
from elote import EloCompetitor good = EloCompetitor(initial_rating=400) better = EloCompetitor(initial_rating=500) print('probability of better beating good: %5.2f%%' % (better.expected_score(good) * 100, )) print('probability of good beating better: %5.2f%%' % (good.expected_score(better) * 100, )) good.beat(better) print('probability of better beating good: %5.2f%%' % (better.expected_score(good) * 100, )) print('probability of good beating better: %5.2f%%' % (good.expected_score(better) * 100, ))
from elote import EloCompetitor good = EloCompetitor(initial_rating=500) better = EloCompetitor(initial_rating=450) best = EloCompetitor(initial_rating=400) print('Starting ratings:') print('%7.2f, %7.2f, %7.2f' % ( good.rating, better.rating, best.rating, )) print('\nAfter matches') for _ in range(20): better.beat(good) best.beat(better) print('%7.2f, %7.2f, %7.2f' % ( good.rating, better.rating, best.rating, ))
def test_Exceptions(self): player1 = EloCompetitor(initial_rating=1000) player2 = GlickoCompetitor(initial_rating=100) with self.assertRaises(MissMatchedCompetitorTypesException): player1.verify_competitor_types(player2)
def test_Expectation(self): player1 = EloCompetitor(initial_rating=1000) player2 = EloCompetitor(initial_rating=100) self.assertGreater(player1.expected_score(player2), player2.expected_score(player1))
from elote import EloCompetitor good = EloCompetitor(initial_rating=500) better = EloCompetitor(initial_rating=450) best = EloCompetitor(initial_rating=400) also_best = EloCompetitor(initial_rating=400) print('Starting ratings:') print('%7.2f, %7.2f, %7.2f, %7.2f' % ( good.rating, better.rating, best.rating, also_best.rating, )) print('\nAfter matches') for _ in range(20): better.beat(good) better.lost_to(best) best.tied(also_best) print('%7.2f, %7.2f, %7.2f, %7.2f' % ( good.rating, better.rating, best.rating, also_best.rating, ))