Table of Contents

Class MaxAndSkipObservation<TObs, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

Repeats each action for skip steps, sums the rewards, and returns the element-wise maximum of the last two observations, as Gymnasium's MaxAndSkipObservation does: the frame skipping of Atari agents, where the maximum removes the flicker of sprites drawn on alternate frames.

public class MaxAndSkipObservation<TObs, TAct> : Wrapper<TObs, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs

Type Parameters

TObs

The env's observation type: arrays (NDArray, or object holding arrays or numbers).

TAct

The action type, passed through.

Inheritance
Env<TObs, TAct>
Wrapper<TObs, TAct, TObs, TAct>
Wrapper<TObs, TAct>
MaxAndSkipObservation<TObs, TAct>
Implements
Inherited Members
Extension Methods

Remarks

An episode that ends early stops the repetition, and the maximum then reads what the earlier steps left in the buffer, as in Gymnasium: after a one-step episode the second slot still holds the previous episode's frame. A reset is the env's own, not a maximum. The rewards are summed as Python floats. Each step returns a new array of the space's dtype; the env's frames are copied into the buffer and left to their owner.

Gymnasium refuses a non-integer skip with TypeError; here it is a long.

Reference: gymnasium/wrappers/stateful_observation.py.

Constructors

MaxAndSkipObservation(Env<TObs, TAct>, MaxAndSkipObservationOptions)

Builds the instance from its options record: the properties set, the constructor's defaults for the rest.

public MaxAndSkipObservation(Env<TObs, TAct> env, MaxAndSkipObservationOptions options)

Parameters

env Env<TObs, TAct>

The env to wrap.

options MaxAndSkipObservationOptions

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

MaxAndSkipObservation(Env<TObs, TAct>, long)

Wraps env.

public MaxAndSkipObservation(Env<TObs, TAct> env, long skip = 4)

Parameters

env Env<TObs, TAct>

The env; its observation space must have a shape.

skip long

The number of steps each action is repeated; at least 2.

Exceptions

ValueError

Thrown for a skip below 2 (The skip value needs to be equal or greater than two, actual value: 0), or a space without a shape (The observation space must have the shape attribute.).

TypeError

Thrown when env is null.

Properties

SavedKwargs

The recorded constructor arguments, {'skip': 4} (Python's _saved_kwargs).

[PyName("_saved_kwargs")]
public Info SavedKwargs { get; }

Property Value

Info

Skip

The number of steps each action is repeated (_skip).

[PyName("_skip")]
public long Skip { get; }

Property Value

long

Methods

Dispose(bool)

Releases the buffer, then disposes the wrapper as every wrapper does.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true from Dispose().

Step(TAct)

Steps the env Skip times with the action (fewer when the episode ends) and returns the maximum of the last two observations.

public override StepResult<TObs> Step(TAct action)

Parameters

action TAct

The action, repeated.

Returns

StepResult<TObs>

The maximum frame (a new array), the summed reward, and the last step's flags and info.