gxm.wrappers.RecordEpisodeStatistics#

class RecordEpisodeStatistics(wrapped, unwrap=True, gamma=1.0, n_episodes=1)#

Bases: EnvironmentWrapper[RecordEpisodeStatisticsState]

A wrapper that records the episode length \(T\) , episodic return \(J(\tau) = \sum_{t=0}^{T} r_t\) , and discounted episodic return \(G(\tau) = \sum_{t=0}^{T} \gamma^t r_t\) at the end of each episode. The statistics can be accessed from the info field of the Timestep returned by the environment. It will contain the stats of the most recent finished episode. By default , the discount factor \(\gamma\) is set to 1.0, meaning that the episodic return and discounted episodic return are the same.

__init__(wrapped, unwrap=True, gamma=1.0, n_episodes=1)#

Methods

__init__(wrapped[, unwrap, gamma, n_episodes])

get_averaged_stats(episode_stats)

get_wrapper(wrapper_type)

Retrieve the first wrapper of a specific type from the dynamics.

has_wrapper(wrapper_type)

Check if the dynamics or any of its wrappers is of a specific type.

init(key)

Initialize the dynamics and return the initial state.

reset(key, state)

Reset the dynamics to an initial state.

step(key, state, action)

Advance the dynamics by one step given an action.

Attributes

unwrap

unwrapped

Retrieve the base dynamics by unwrapping all wrappers.

gamma

The discount factor \(\gamma\) for calculating the discounted episodic return.

n_episodes

The number of past episodes to record statistics for.

wrapped

id

The unique identifier of the dynamics.

action_space

The action space of the dynamics.

observation_space

The observation space of the dynamics.

action_space: Space#

The action space of the dynamics.

gamma: float#

The discount factor \(\gamma\) for calculating the discounted episodic return.

static get_averaged_stats(episode_stats)#
Return type:

dict[str, Array]

id: str#

The unique identifier of the dynamics.

init(key)#

Initialize the dynamics and return the initial state.

Parameters:

key (Array) – A JAX random key for any stochastic initialization.

Return type:

tuple[RecordEpisodeStatisticsState, Timestep]

Returns:

A tuple of the initial state and the initial step output.

n_episodes: int#

The number of past episodes to record statistics for.

observation_space: Space#

The observation space of the dynamics.

reset(key, state)#

Reset the dynamics to an initial state.

Parameters:
  • key (Array) – A JAX random key for any stochasticity.

  • state (RecordEpisodeStatisticsState) – The current state.

Return type:

tuple[RecordEpisodeStatisticsState, Timestep]

Returns:

A tuple of the reset state and the initial step output.

step(key, state, action)#

Advance the dynamics by one step given an action.

Parameters:
  • key (Array) – A JAX random key for any stochasticity.

  • state (RecordEpisodeStatisticsState) – The current state.

  • action (Any) – The action to apply.

Return type:

tuple[RecordEpisodeStatisticsState, Timestep]

Returns:

A tuple of the new state and the resulting step output.

wrapped: Environment#