def updated_ratings(self): results = Match() for current_team in self.prior_layer.output_variables_groups: team_results = Team() for current_player, current_player_rating in [(player.key, player.value) for player in current_team]: new_rating = GaussianRating(current_player_rating.mean, current_player_rating.stdev) team_results[current_player] = new_rating results.append(team_results) return results
def updated_ratings(self): results = Match() for current_team in self.prior_layer.output_variables_groups: team_results = Team() for current_player, current_player_rating in [ (player.key, player.value) for player in current_team ]: new_rating = GaussianRating(current_player_rating.mean, current_player_rating.stdev) team_results[current_player] = new_rating results.append(team_results) return results
def new_ratings(self, matches, rating_period=None, game_info=None): game_info = GlickoGameInfo.ensure_game_info(game_info) # get unique list of players and ensure ratings are consistant players = {} opponents = defaultdict(list) player_rd = {} # Step 1: calculate r and RD for onset of rating period # also cache values of g(RDj) and E(s|r, rj, RDj) for each player for match in matches: # ensure winning team is team 0 match.sort() for player, rating in match.player_rating(): if player in players: if rating != players[player]: raise ValueError( "Inconsistant ratings: player %s has rating %s and rating %s" % (player, rating, players[player])) else: # calc new RD from old RD if (self.c_factor is None or rating.last_rating_period is None or rating_period is None): player_rd[player] = rating.stdev else: t = rating_period - rating.last_rating_period if t <= 0: raise ValueError( "Player %s has a last_rating_period equal to the current rating_period" % (player)) player_rd[player] = min( game_info.beta, sqrt(rating.stdev**2 + self.c_factor * t)) players[player] = rating # create opponent lists of players and outcomes player1 = match[0].players()[0] player2 = match[1].players()[0] opponents[player1].append( (player2, GlickoCalculator.score[match.comparison(0, 1)])) opponents[player2].append( (player1, GlickoCalculator.score[match.comparison(1, 0)])) # Step 2: carry out the update calculations for each player separately q = log(10.0) / 400.0 def g(rd): return 1.0 / sqrt(1.0 + 3.0 * q**2.0 * (rd**2.0) / pi**2.0) def E(r, rj, rd_j): return 1.0 / (1.0 + pow(10.0, -g(rd_j) * (r - rj) / 400.0)) def d2(g_rd, e_sr_r_rd): return pow( q**2.0 * sum(g_rd[j]**2.0 * e_sr_r_rd[j] * (1.0 - e_sr_r_rd[j]) for j in range(len(g_rd))), -1.0) new_ratings = Match() for player, rating in players.items(): # cache values of g(RDj) and E(s|r, r, RDj) for each opponent opponent_g_rd = [] opponent_e_sr_r_rd = [] opponent_s = [] for opponent, score in opponents[player]: opponent_g_rd.append(g(player_rd[opponent])) opponent_e_sr_r_rd.append( E(rating.mean, players[opponent].mean, player_rd[opponent])) opponent_s.append(score) # cache value, this form used twice in the paper rd2_d2 = (1.0 / player_rd[player]**2.0 + 1.0 / d2(opponent_g_rd, opponent_e_sr_r_rd)) # new rating value r_new = (rating.mean + q / rd2_d2 * sum(opponent_g_rd[j] * (opponent_s[j] - opponent_e_sr_r_rd[j]) for j in range(len(opponent_s)))) # new rating deviation value rd_new = sqrt(pow(rd2_d2, -1)) new_ratings.append( Team({player: GlickoRating(r_new, rd_new, rating_period)})) return new_ratings
def new_ratings(self, matches, rating_period=None, game_info=None): game_info = GlickoGameInfo.ensure_game_info(game_info) # get unique list of players and ensure ratings are consistant players = {} opponents = defaultdict(list) player_rd = {} # Step 1: calculate r and RD for onset of rating period # also cache values of g(RDj) and E(s|r, rj, RDj) for each player for match in matches: # ensure winning team is team 0 match.sort() for player, rating in match.player_rating(): if player in players: if rating != players[player]: raise ValueError("Inconsistant ratings: player %s has rating %s and rating %s" % (player, rating, players[player])) else: # calc new RD from old RD if (self.c_factor is None or rating.last_rating_period is None or rating_period is None): player_rd[player] = rating.stdev else: t = rating_period - rating.last_rating_period if t <= 0: raise ValueError("Player %s has a last_rating_period equal to the current rating_period" % (player)) player_rd[player] = min(game_info.beta, sqrt(rating.stdev ** 2 + self.c_factor * t)) players[player] = rating # create opponent lists of players and outcomes player1 = match[0].players()[0] player2 = match[1].players()[0] opponents[player1].append((player2, GlickoCalculator.score[match.comparison(0, 1)])) opponents[player2].append((player1, GlickoCalculator.score[match.comparison(1, 0)])) # Step 2: carry out the update calculations for each player separately q = log(10.0) / 400.0 def g(rd): return 1.0 / sqrt(1.0 + 3.0 * q ** 2.0 * (rd ** 2.0) / pi ** 2.0) def E(r, rj, rd_j): return 1.0 / (1.0 + pow(10.0, -g(rd_j) * (r - rj) / 400.0)) def d2(g_rd, e_sr_r_rd): return pow(q ** 2.0 * sum( g_rd[j] ** 2.0 * e_sr_r_rd[j] * (1.0 - e_sr_r_rd[j]) for j in range(len(g_rd)) ), -1.0) new_ratings = Match() for player, rating in players.items(): # cache values of g(RDj) and E(s|r, r, RDj) for each opponent opponent_g_rd = [] opponent_e_sr_r_rd = [] opponent_s = [] for opponent, score in opponents[player]: opponent_g_rd.append(g(player_rd[opponent])) opponent_e_sr_r_rd.append(E(rating.mean, players[opponent].mean, player_rd[opponent])) opponent_s.append(score) # cache value, this form used twice in the paper rd2_d2 = (1.0 / player_rd[player] ** 2.0 + 1.0 / d2(opponent_g_rd, opponent_e_sr_r_rd)) # new rating value r_new = (rating.mean + q / rd2_d2 * sum( opponent_g_rd[j] * (opponent_s[j] - opponent_e_sr_r_rd[j]) for j in range(len(opponent_s)) )) # new rating deviation value rd_new = sqrt(pow(rd2_d2, -1)) new_ratings.append(Team({player: GlickoRating(r_new, rd_new, rating_period)})) return new_ratings