Create line plots showing Elo vs round for each game.
(self, results_by_round: dict[int, dict[str, dict[str, float]]])
| 1176 | for game_name, matchups in builder.win_matrix.items(): |
| 1177 | if self.games is not None and game_name not in self.games: |
| 1178 | continue |
| 1179 | |
| 1180 | fitter = BradleyTerryFitter(matchups, regularization=self.regularization, compute_uncertainties=False) |
| 1181 | result = fitter.fit() |
| 1182 | |
| 1183 | results_by_round[round_num][game_name] = { |
| 1184 | p: BradleyTerryFitter.bt_to_elo(s) for p, s in zip(result["players"], result["strengths"]) |
| 1185 | } |
| 1186 | |
| 1187 | self._plot_results(results_by_round) |
| 1188 | |
| 1189 | def _plot_results(self, results_by_round: dict[int, dict[str, dict[str, float]]]) -> None: |
| 1190 | """Create line plots showing Elo vs round for each game.""" |
| 1191 | if self.output_dir is None: |
| 1192 | logger.warning("No output directory specified, skipping plots") |
| 1193 | return |
| 1194 | |
| 1195 | output_dir = self.output_dir / "elos_only_at_round" |
| 1196 | output_dir.mkdir(parents=True, exist_ok=True) |
| 1197 | |
| 1198 | # Get all games |
| 1199 | all_games = set() |
| 1200 | for game_results in results_by_round.values(): |
| 1201 | all_games.update(game_results.keys()) |
| 1202 | |
| 1203 | for game_name in sorted(all_games): |
| 1204 | # Collect all players that appear in this game |
| 1205 | all_players = set() |
| 1206 | for round_results in results_by_round.values(): |
| 1207 | if game_name in round_results: |
| 1208 | all_players.update(round_results[game_name].keys()) |
| 1209 | |
| 1210 | players = sorted(all_players) |
| 1211 | |
| 1212 | # Create plot |
| 1213 | fig, ax = plt.subplots(figsize=(12, 8)) |
| 1214 | |
| 1215 | for player in players: |
| 1216 | rounds_list = [] |
| 1217 | elos_list = [] |
| 1218 | |
| 1219 | for round_num in sorted(results_by_round.keys()): |
| 1220 | if game_name in results_by_round[round_num]: |
| 1221 | if player in results_by_round[round_num][game_name]: |
| 1222 | rounds_list.append(round_num) |
| 1223 | elos_list.append(results_by_round[round_num][game_name][player]) |
| 1224 | |
| 1225 | if rounds_list: |
| 1226 | display_name = MODEL_TO_DISPLAY_NAME.get(player, player) |
| 1227 | ax.plot(rounds_list, elos_list, marker="o", label=display_name, linewidth=2, markersize=6) |
| 1228 | |
| 1229 | ax.set_xlabel("Round", fontproperties=FONT_BOLD, fontsize=14) |
| 1230 | ax.set_ylabel("Elo Rating", fontproperties=FONT_BOLD, fontsize=14) |
| 1231 | ax.set_title(f"Elo at Specific Round: {game_name}", fontproperties=FONT_BOLD, fontsize=16) |
| 1232 | ax.grid(True, alpha=0.3) |
| 1233 | ax.yaxis.set_minor_locator(AutoMinorLocator()) |
| 1234 | |
| 1235 | # Add reference line at ELO_BASE |
no test coverage detected