Table of Contents

Class DiscretizeAction<TObs, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

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

TObs

The observation type, passed through.

TAct

The env's action type: arrays (NDArray, or object holding them).

Inheritance
Env<TObs, NDArray>
Wrapper<TObs, NDArray, TObs, TAct>
ActionWrapper<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

env Env<TObs, TAct>

The env to wrap.

options DiscretizeActionOptions

The options.

Exceptions

ArgumentNullException

Thrown when options is 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

env Env<TObs, TAct>

The env; its action space must be a finite Box.

bins object

The bins per element: one number for every element, or a sequence of one per element.

multidiscrete bool

Whether actions are MultiDiscrete vectors instead of one Discrete number.

Exceptions

TypeError

Thrown when the action space is no Box (Gymnasium's message), or env is 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

NDArray

Low

The box's lower bounds, flattened (low).

public NDArray Low { get; }

Property Value

NDArray

Multidiscrete

Whether actions are MultiDiscrete (multidiscrete).

public bool Multidiscrete { get; }

Property Value

bool

NDims

The number of elements discretized (n_dims).

[PyName("n_dims")]
public int NDims { get; }

Property Value

int

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

disposing bool

true from Dispose().

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

action NDArray

A continuous action of the env's shape.

Returns

NDArray

A new int64 array: (n_dims,) for MultiDiscrete, 0-d (the flat index) for Discrete.