EpisodeMetrics
python
EpisodeMetrics(metrics: MetricsTracker, prefix: AgentRole, outcome_window_size: int) -> NoneOwns episode-outcome bookkeeping (win/loss/truncated totals) and metric logging for one agent-like runtime (actor, trainer, or tester).
Initialize the episode-metrics helper.
Parameters:
metrics(MetricsTracker) – The metrics tracker to log to.prefix(AgentRole) – The owning agent's metric-tag namespace prefix.outcome_window_size(int) – The window size for the windowed outcome metric.
Properties
total_episodes
python
total_episodes: intGet the total number of episodes completed.
Returns:
int– The total episode count.
total_losses
python
total_losses: intGet the total number of losses.
Returns:
int– The total loss count.
total_truncated
python
total_truncated: intGet the total number of truncated episodes.
Returns:
int– The total truncated count.
total_wins
python
total_wins: intGet the total number of wins.
Returns:
int– The total win count.
Methods
log_action_frequencies
python
log_action_frequencies(action_names: Sequence[str], action_counts: Sequence[int] | np.ndarray, episode_length: int, *, step: int) -> NoneLog executed per-episode action percentages for one completed episode.
Parameters:
action_names(Sequence[str]) – The game's action names, index-aligned withaction_counts.action_counts(Sequence[int] | ndarray) – Per-action executed counts for the completed episode.episode_length(int) – The episode length in steps; nothing is logged when not positive.step(int) – The global step for metric logging.
log_episode_outcome
python
log_episode_outcome(*, outcome: EpisodeOutcome, episode_reward: float, episode_length: int, episode_data: dict[str, float], step: int) -> EpisodeOutcomeLog episode completion metrics common to both training and testing.
Updates totals and writes windowed percentages, reward/length averages, and episode data metrics for the given outcome.
Parameters:
outcome(EpisodeOutcome) – The completed episode's outcome.episode_reward(float) – The cumulative episode reward.episode_length(int) – The number of steps in the episode.episode_data(dict[str, float]) – Extra per-episode data to log (for example score).step(int) – The global step for metric logging.
Returns:
EpisodeOutcome– The outcome, unchanged (for convenience at call sites).
restore_state
python
restore_state(*, total_episodes: int, total_wins: int, total_losses: int, total_truncated: int) -> NoneRestore the episode counters from checkpointed runtime state.
Parameters:
total_episodes(int) – The total episode count to restore.total_wins(int) – The total win count to restore.total_losses(int) – The total loss count to restore.total_truncated(int) – The total truncated count to restore.