Table of Contents

Class TransformObservation<TWObs, TObs, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

Applies a function to every observation Reset and Step return, as Gymnasium's TransformObservation does. Give it the transformed observations' space when they leave the env's.

public class TransformObservation<TWObs, TObs, TAct> : ObservationWrapper<TWObs, TObs, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs

Type Parameters

TWObs

The transformed observation type.

TObs

The env's observation type.

TAct

The action type, passed through.

Inheritance
Env<TWObs, TAct>
Wrapper<TWObs, TAct, TObs, TAct>
ObservationWrapper<TWObs, TObs, TAct>
TransformObservation<TWObs, TObs, TAct>
Implements
Derived
Inherited Members
Extension Methods

Remarks

Without an observation space the wrapper forwards the env's, which only works when TWObs is the env's observation type: reading it otherwise raises TypeError. The base of Gymnasium's stateless observation wrappers, which compute their space and function in their constructors; they set Func and SavedKwargs themselves, as Python's subclasses record their own arguments before this class's constructor runs.

The function's result is returned as it is: whether it shares memory with the env's observation (a reshape view, a dict holding the same arrays) is the function's business, as in Python.

Reference: gymnasium/wrappers/transform_observation.py.

Constructors

TransformObservation(Env<TObs, TAct>)

Wraps env for a subclass that computes its function and space in its own constructor and assigns Func, ObservationSpace and SavedKwargs there.

protected TransformObservation(Env<TObs, TAct> env)

Parameters

env Env<TObs, TAct>

The env.

Exceptions

TypeError

Thrown when env is null.

TransformObservation(Env<TObs, TAct>, TransformObservationOptions<TWObs, TObs>)

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

public TransformObservation(Env<TObs, TAct> env, TransformObservationOptions<TWObs, TObs> options)

Parameters

env Env<TObs, TAct>

The env to wrap.

options TransformObservationOptions<TWObs, TObs>

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

TypeError

Thrown when a required argument is unset, with Python's missing-argument message.

TransformObservation(Env<TObs, TAct>, Func<TObs, TWObs>, Space<TWObs>?)

Wraps env.

public TransformObservation(Env<TObs, TAct> env, Func<TObs, TWObs> func, Space<TWObs>? observationSpace)

Parameters

env Env<TObs, TAct>

The env.

func Func<TObs, TWObs>

The transformation; null fails at the first observation, as Python's None does when called.

observationSpace Space<TWObs>

The transformed observations' space, owned by the wrapper from now on; null forwards the env's.

Exceptions

TypeError

Thrown when env is null.

Properties

Func

The transformation (func).

[PyName("func")]
public Func<TObs, TWObs> Func { get; protected set; }

Property Value

Func<TObs, TWObs>

SavedKwargs

The recorded constructor arguments (Python's _saved_kwargs): a subclass's own, as Python records the first call's.

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

Property Value

Info

Methods

Observation(TObs)

Applies Func (observation(observation)).

public override TWObs Observation(TObs observation)

Parameters

observation TObs

The env's observation.

Returns

TWObs

The function's result, as it returns it.

Exceptions

TypeError

Thrown when the function is null: 'NoneType' object is not callable.