Class RecordEpisodeStatistics<TObs, TAct>
Records each episode's return, length and duration: the step that ends an episode gets
info["episode"] = {"r": return, "l": length, "t": seconds}, and the last buffer_length episodes stay
in ReturnQueue, LengthQueue and TimeQueue.
public class RecordEpisodeStatistics<TObs, TAct> : Wrapper<TObs, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs
Type Parameters
TObsThe observation type, passed through.
TActThe action type, passed through.
- Inheritance
-
Env<TObs, TAct>Wrapper<TObs, TAct, TObs, TAct>Wrapper<TObs, TAct>RecordEpisodeStatistics<TObs, TAct>
- Implements
- Inherited Members
- Extension Methods
Remarks
The statistics go into the info the env returned, which is edited in place. The time is wall-clock seconds since
the reset (Python's time.perf_counter(), rounded to 6 digits), so it differs between runs: parity and golden
comparisons leave the t entry out.
Reference: gymnasium/wrappers/common.py.
Constructors
RecordEpisodeStatistics(Env<TObs, TAct>, RecordEpisodeStatisticsOptions)
Builds the instance from its options record: the properties set, the constructor's defaults for the rest.
public RecordEpisodeStatistics(Env<TObs, TAct> env, RecordEpisodeStatisticsOptions options)
Parameters
envEnv<TObs, TAct>The env to wrap.
optionsRecordEpisodeStatisticsOptionsThe options.
Exceptions
- ArgumentNullException
Thrown when
optionsis null.
RecordEpisodeStatistics(Env<TObs, TAct>, int, string)
Wraps env.
public RecordEpisodeStatistics(Env<TObs, TAct> env, int bufferLength = 100, string statsKey = "episode")
Parameters
envEnv<TObs, TAct>The env whose episodes to record.
bufferLengthintHow many episodes the queues keep (Python's
deque(maxlen=buffer_length)).statsKeystringThe info key for the statistics.
Exceptions
- TypeError
Thrown when
envis null.- ValueError
Thrown for a negative
bufferLength:maxlen must be non-negative.
Properties
EpisodeCount
The number of episodes finished (episode_count).
public long EpisodeCount { get; set; }
Property Value
EpisodeLengths
The current episode's length so far (episode_lengths).
public long EpisodeLengths { get; set; }
Property Value
EpisodeReturns
The current episode's return so far (episode_returns).
public double EpisodeReturns { get; set; }
Property Value
EpisodeStartTime
When the current episode began, in perf_counter seconds (episode_start_time); -1 before the first reset.
public double EpisodeStartTime { get; set; }
Property Value
LengthQueue
The lengths of the last episodes, oldest first (length_queue).
public Deque<long> LengthQueue { get; }
Property Value
ReturnQueue
The returns of the last episodes, oldest first (return_queue).
public Deque<double> ReturnQueue { get; }
Property Value
SavedKwargs
The recorded constructor arguments, {'buffer_length': 100, 'stats_key': 'episode'} (Python's _saved_kwargs).
[PyName("_saved_kwargs")]
public Info SavedKwargs { get; }
Property Value
TimeQueue
The durations of the last episodes, oldest first (time_queue).
public Deque<double> TimeQueue { get; }
Property Value
Methods
Reset(BigInteger?, IReadOnlyDictionary<string, object?>?)
Resets the env and starts a new episode's statistics.
public override ResetResult<TObs> Reset(BigInteger? seed = null, IReadOnlyDictionary<string, object?>? options = null)
Parameters
seedBigInteger?The seed, passed on.
optionsIReadOnlyDictionary<string, object>The options, passed on.
Returns
- ResetResult<TObs>
The env's first observation and info.
Exceptions
- Error
Thrown for a negative seed.
Step(TAct)
Steps the env and counts the step; the step that ends an episode records it and adds the statistics to the info.
public override StepResult<TObs> Step(TAct action)
Parameters
actionTActThe action, passed on.
Returns
- StepResult<TObs>
The env's transition, its info extended when the episode ended.
Exceptions
- AssertionError
Thrown, empty as Python's bare assert, when the info already has the statistics key.