Class TransformAction<TObs, TWAct, TAct>
Applies a function to every action before the env steps with it, as Gymnasium's TransformAction does.
Give it the space of the actions it takes when they differ from the env's.
public class TransformAction<TObs, TWAct, TAct> : ActionWrapper<TObs, TWAct, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs
Type Parameters
TObsThe observation type, passed through.
TWActThe action type the wrapper takes.
TActThe env's action type.
- Inheritance
-
Env<TObs, TWAct>Wrapper<TObs, TWAct, TObs, TAct>ActionWrapper<TObs, TWAct, TAct>TransformAction<TObs, TWAct, TAct>
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
Without an action space the wrapper forwards the env's, which only works when TWAct is the
env's action type: reading it otherwise raises TypeError. The base of Gymnasium's action wrappers,
which set Func and SavedKwargs in their own constructors.
Reference: gymnasium/wrappers/transform_action.py.
Constructors
TransformAction(Env<TObs, TAct>)
Wraps env for a subclass that computes its function and space in its own constructor and
assigns Func, ActionSpace and SavedKwargs there.
protected TransformAction(Env<TObs, TAct> env)
Parameters
envEnv<TObs, TAct>The env.
Exceptions
TransformAction(Env<TObs, TAct>, TransformActionOptions<TWAct, TAct>)
Builds the instance from its options record: the properties set, the constructor's defaults for the rest.
public TransformAction(Env<TObs, TAct> env, TransformActionOptions<TWAct, TAct> options)
Parameters
envEnv<TObs, TAct>The env to wrap.
optionsTransformActionOptions<TWAct, TAct>The options.
Exceptions
- ArgumentNullException
Thrown when
optionsis null.- TypeError
Thrown when a required argument is unset, with Python's missing-argument message.
TransformAction(Env<TObs, TAct>, Func<TWAct, TAct>, Space<TWAct>?)
Wraps env.
public TransformAction(Env<TObs, TAct> env, Func<TWAct, TAct> func, Space<TWAct>? actionSpace)
Parameters
envEnv<TObs, TAct>The env.
funcFunc<TWAct, TAct>The transformation; null fails at the first step, as Python's
Nonedoes when called.actionSpaceSpace<TWAct>The wrapper's action space, owned by the wrapper from now on; null forwards the env's.
Exceptions
Properties
Func
The transformation (func).
[PyName("func")]
public Func<TWAct, TAct> Func { get; protected set; }
Property Value
- Func<TWAct, TAct>
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
Action(TWAct)
Applies Func (action(action)).
public override TAct Action(TWAct action)
Parameters
actionTWActThe wrapper's action.
Returns
- TAct
The env's action.