Class DiscretizeAction<TObs, TAct>
Takes discrete actions and steps the env with the center of the matching bin of its finite Box, as
Gymnasium's DiscretizeAction does: one Discrete number (row-major over the box's elements) or a
MultiDiscrete vector of one index per element.
public class DiscretizeAction<TObs, TAct> : TransformAction<TObs, NDArray, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs
Type Parameters
TObsThe observation type, passed through.
TActThe env's action type: arrays (NDArray, or object holding them).
- Inheritance
-
ActionWrapper<TObs, NDArray, TAct>TransformAction<TObs, NDArray, TAct>DiscretizeAction<TObs, TAct>
- Implements
- Inherited Members
- Extension Methods
Remarks
The centers are 0.5 * (edges[:-1] + edges[1:]) of NumPy's np.linspace(low[i], high[i], bins[i] + 1),
in the box's dtype; an index beyond its element's bins is clamped to the nearest bin.
Reference: gymnasium/wrappers/transform_action.py.
Constructors
DiscretizeAction(Env<TObs, TAct>, DiscretizeActionOptions)
Builds the instance from its options record: the properties set, the constructor's defaults for the rest.
public DiscretizeAction(Env<TObs, TAct> env, DiscretizeActionOptions options)
Parameters
envEnv<TObs, TAct>The env to wrap.
optionsDiscretizeActionOptionsThe options.
Exceptions
- ArgumentNullException
Thrown when
optionsis null.- TypeError
Thrown when a required argument is unset, with Python's missing-argument message.
DiscretizeAction(Env<TObs, TAct>, object, bool)
Wraps env.
public DiscretizeAction(Env<TObs, TAct> env, object bins, bool multidiscrete = false)
Parameters
envEnv<TObs, TAct>The env; its action space must be a finite
Box.binsobjectThe bins per element: one number for every element, or a sequence of one per element.
multidiscreteboolWhether actions are
MultiDiscretevectors instead of oneDiscretenumber.
Exceptions
- TypeError
Thrown when the action space is no
Box(Gymnasium's message), orenvis null.- ValueError
Thrown when a bound is infinite, or the bins do not match the elements, with Gymnasium's messages.
Properties
BinCenters
The bin centers of each element (bin_centers), in the box's dtype.
public NDArray[] BinCenters { get; }
Property Value
- NDArray[]
Bins
The bins of each element (bins).
public long[] Bins { get; }
Property Value
- long[]
High
The box's upper bounds, flattened (high).
public NDArray High { get; }
Property Value
Low
The box's lower bounds, flattened (low).
public NDArray Low { get; }
Property Value
Multidiscrete
Whether actions are MultiDiscrete (multidiscrete).
public bool Multidiscrete { get; }
Property Value
NDims
The number of elements discretized (n_dims).
[PyName("n_dims")]
public int NDims { get; }
Property Value
Methods
Dispose(bool)
Releases the bounds and centers, then disposes the wrapper (and the env beneath) as every wrapper does.
protected override void Dispose(bool disposing)
Parameters
RevertAction(NDArray)
The discrete action whose bin centers are nearest a continuous action (revert_action): per element, the
center at the smallest distance (np.argmin(np.abs(centers - action[i]))).
public NDArray RevertAction(NDArray action)
Parameters
actionNDArrayA continuous action of the env's shape.
Returns
- NDArray
A new int64 array:
(n_dims,)forMultiDiscrete, 0-d (the flat index) forDiscrete.