Create line plots showing Elo vs max rounds for each game.
(self, results_by_max_round: dict[int, dict[str, dict[str, float]]])
| 1059 | for game_name, matchups in builder.win_matrix.items(): |
| 1060 | if self.games is not None and game_name not in self.games: |
| 1061 | continue |
| 1062 | |
| 1063 | fitter = BradleyTerryFitter(matchups, regularization=self.regularization, compute_uncertainties=False) |
| 1064 | result = fitter.fit() |
| 1065 | |
| 1066 | results_by_max_round[max_round][game_name] = { |
| 1067 | p: BradleyTerryFitter.bt_to_elo(s) for p, s in zip(result["players"], result["strengths"]) |
| 1068 | } |
| 1069 | |
| 1070 | self._plot_results(results_by_max_round) |
| 1071 | |
| 1072 | def _plot_results(self, results_by_max_round: dict[int, dict[str, dict[str, float]]]) -> None: |
| 1073 | """Create line plots showing Elo vs max rounds for each game.""" |
| 1074 | if self.output_dir is None: |
| 1075 | logger.warning("No output directory specified, skipping plots") |
| 1076 | return |
| 1077 | |
| 1078 | output_dir = self.output_dir / "elo_vs_max_rounds" |
| 1079 | output_dir.mkdir(parents=True, exist_ok=True) |
| 1080 | |
| 1081 | # Get all games |
| 1082 | all_games = set() |
| 1083 | for game_results in results_by_max_round.values(): |
| 1084 | all_games.update(game_results.keys()) |
| 1085 | |
| 1086 | for game_name in sorted(all_games): |
| 1087 | # Collect all players that appear in this game |
| 1088 | all_players = set() |
| 1089 | for round_results in results_by_max_round.values(): |
| 1090 | if game_name in round_results: |
| 1091 | all_players.update(round_results[game_name].keys()) |
| 1092 | |
| 1093 | players = sorted(all_players) |
| 1094 | |
| 1095 | # Create plot |
| 1096 | fig, ax = plt.subplots(figsize=(12, 8)) |
| 1097 | |
| 1098 | for player in players: |
| 1099 | max_rounds_list = [] |
| 1100 | elos_list = [] |
| 1101 | |
| 1102 | for max_round in sorted(results_by_max_round.keys()): |
| 1103 | if game_name in results_by_max_round[max_round]: |
| 1104 | if player in results_by_max_round[max_round][game_name]: |
| 1105 | max_rounds_list.append(max_round) |
| 1106 | elos_list.append(results_by_max_round[max_round][game_name][player]) |
| 1107 | |
| 1108 | if max_rounds_list: |
| 1109 | display_name = MODEL_TO_DISPLAY_NAME.get(player, player) |
| 1110 | ax.plot(max_rounds_list, elos_list, marker="o", label=display_name, linewidth=2, markersize=6) |
| 1111 | |
| 1112 | ax.set_xlabel("Max Round", fontproperties=FONT_BOLD, fontsize=14) |
| 1113 | ax.set_ylabel("Elo Rating", fontproperties=FONT_BOLD, fontsize=14) |
| 1114 | ax.set_title(f"Elo vs Max Rounds: {game_name}", fontproperties=FONT_BOLD, fontsize=16) |
| 1115 | ax.grid(True, alpha=0.3) |
| 1116 | ax.yaxis.set_minor_locator(AutoMinorLocator()) |
| 1117 | |
| 1118 | # Add reference line at ELO_BASE |
no test coverage detected