Class TransformObservation<TWObs, TObs, TAct>
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
TWObsThe transformed observation type.
TObsThe env's observation type.
TActThe 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
envEnv<TObs, TAct>The env.
Exceptions
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
envEnv<TObs, TAct>The env to wrap.
optionsTransformObservationOptions<TWObs, TObs>The options.
Exceptions
- ArgumentNullException
Thrown when
optionsis 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
envEnv<TObs, TAct>The env.
funcFunc<TObs, TWObs>The transformation; null fails at the first observation, as Python's
Nonedoes when called.observationSpaceSpace<TWObs>The transformed observations' space, owned by the wrapper from now on; null forwards the env's.
Exceptions
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
Methods
Observation(TObs)
Applies Func (observation(observation)).
public override TWObs Observation(TObs observation)
Parameters
observationTObsThe env's observation.
Returns
- TWObs
The function's result, as it returns it.