Skip to content

EpisodeMetrics ​

python
EpisodeMetrics(metrics: MetricsTracker, prefix: AgentRole, outcome_window_size: int) -> None

Owns 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.

Source

Properties ​

total_episodes ​

python
total_episodes: int

Get the total number of episodes completed.

Returns:

  • int – The total episode count.

Source

total_losses ​

python
total_losses: int

Get the total number of losses.

Returns:

  • int – The total loss count.

Source

total_truncated ​

python
total_truncated: int

Get the total number of truncated episodes.

Returns:

  • int – The total truncated count.

Source

total_wins ​

python
total_wins: int

Get the total number of wins.

Returns:

  • int – The total win count.

Source

Methods ​

log_action_frequencies ​

python
log_action_frequencies(action_names: Sequence[str], action_counts: Sequence[int] | np.ndarray, episode_length: int, *, step: int) -> None

Log executed per-episode action percentages for one completed episode.

Parameters:

  • action_names (Sequence[str]) – The game's action names, index-aligned with action_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.

Source

log_episode_outcome ​

python
log_episode_outcome(*, outcome: EpisodeOutcome, episode_reward: float, episode_length: int, episode_data: dict[str, float], step: int) -> EpisodeOutcome

Log 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).

Source

restore_state ​

python
restore_state(*, total_episodes: int, total_wins: int, total_losses: int, total_truncated: int) -> None

Restore 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.

Source