Download scripts/evaluate.py from lukehola/koehandel: direct link, hf CLI and curl.
- Browser
- Download file 1.94 kB
-
https://huggingface.co/spaces/lukehola/koehandel/resolve/main/scripts/evaluate.py
- Command line
-
hf download hf://spaces/lukehola/koehandel/scripts/evaluate.py
-
curl -L -o evaluate.py https://huggingface.co/spaces/lukehola/koehandel/resolve/main/scripts/evaluate.py
1.94 kB
| #!/usr/bin/env python3 | |
| """Evaluate agents in an Elo tournament: baselines plus any checkpoints you pass. | |
| python scripts/evaluate.py --checkpoints runs/v1/checkpoints/latest.pt --games 400 | |
| python scripts/evaluate.py --checkpoints runs/v1/checkpoints/ckpt_00050.pt runs/v1/checkpoints/latest.pt | |
| """ | |
| import argparse | |
| import os | |
| import sys | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from koehandel.agents import HeuristicAgent, RandomAgent # noqa: E402 | |
| from koehandel.agents.neural_agent import NeuralAgent # noqa: E402 | |
| from koehandel.evaluation import elo_tournament # noqa: E402 | |
| def main(): | |
| p = argparse.ArgumentParser(description=__doc__) | |
| p.add_argument("--checkpoints", nargs="*", default=[]) | |
| p.add_argument("--games", type=int, default=300) | |
| p.add_argument("--num-players", type=int, default=4) | |
| p.add_argument("--seed", type=int, default=0) | |
| args = p.parse_args() | |
| agents = { | |
| "random": RandomAgent(seed=1), | |
| "random2": RandomAgent(seed=11), | |
| "heuristic": HeuristicAgent(seed=2), | |
| "heuristic2": HeuristicAgent(seed=22), | |
| } | |
| for path in args.checkpoints: | |
| name = os.path.basename(os.path.dirname(os.path.dirname(path))) + ":" + os.path.basename(path) | |
| agents[name] = NeuralAgent.from_checkpoint(path, deterministic=True, name=name) | |
| res = elo_tournament(agents, games=args.games, num_players=args.num_players, seed=args.seed) | |
| print(f"\nElo tournament — {res['games']} games, {args.num_players} players/table\n") | |
| order = sorted(res["elo"], key=lambda n: res["elo"][n], reverse=True) | |
| print(f"{'agent':<28} {'elo':>7} {'win%':>7} {'avg_score':>10} {'games':>6}") | |
| print("-" * 62) | |
| for n in order: | |
| print(f"{n:<28} {res['elo'][n]:>7.0f} {res['win_rate'][n]*100:>6.1f}% " | |
| f"{res['avg_score'][n]:>10.0f} {res['appearances'][n]:>6}") | |
| if __name__ == "__main__": | |
| main() | |