Table of Contents

Class WrapperFunctions

Namespace
Gym.Wrappers
Assembly
Gym.dll

Gymnasium's gymnasium.wrappers.utils functions that this phase's wrappers use.

public static class WrapperFunctions
Inheritance
WrapperFunctions
Inherited Members

Methods

CreateZeroArray(Space)

A valid element of space as close to zero as the space allows (Gymnasium's create_zero_array): unlike CreateEmptyArray(Space, int, Func<Shape, DType, NDArray>?), a Box that excludes zero gets its nearest bound, so the result is always a member of the space. What the observation wrappers fill with before an episode has data (DelayObservation, FrameStackObservation's padding).

public static object? CreateZeroArray(Space space)

Parameters

space Space

The space; an ObjectSpace view is looked through.

Returns

object

A new element the caller owns: an array for Box, MultiDiscrete and MultiBinary, a 0-d array of the space's dtype holding start for Discrete, an object?[] (Python's tuple) for Tuple, an Info for Dict, the first character repeated min_length times for Text, a GraphInstance with one zero node (and one zero edge from node 0 to node 0) for Graph, the stacked feature space's zero or an empty tuple for Sequence, and (0, zero of the first subspace) for OneOf.

Remarks

Exceptions

TypeError

Thrown when space is null, with Gymnasium's message.

CustomSpaceError

Thrown for a space class Gymnasium registers no zero for, with Gymnasium's message.

RescaleBox(Space, object, object)

Rescales and shifts a Box onto new bounds (Gymnasium's rescale_box): the new box, the forward map (original values to rescaled ones) and the backward map. Unbounded components stay unbounded and are shifted, not scaled. What RescaleObservation (forward) and RescaleAction (backward) apply.

public static (Box Box, Func<NDArray, NDArray> Forward, Func<NDArray, NDArray> Backward) RescaleBox(Space box, object newMin, object newMax)

Parameters

box Space

The space; it must be a Box (an ObjectSpace view of one is looked through).

newMin object

The new lower bound: an array of the box's shape, or a number broadcast to it. A .NET integer is a Python int (int64), a double a Python float (float64), a float or a 0-d array a NumPy scalar of its own dtype, as np.full would take them.

newMax object

The new upper bound, in the same forms.

Returns

(Box Box, Func<NDArray, NDArray> Forward, Func<NDArray, NDArray> Backward)

The rescaled box (the caller owns it) and the two maps. Each map captures the gradient and intercept arrays, in the box's dtype, and returns a new array the caller owns; its dtype is NumPy's promotion of the argument with the box's dtype (float32 for float32 values of a float32 box).

Remarks

Gymnasium computes high - low in np.float128 where NumPy has it and in float64 otherwise; Windows NumPy, the reference platform, has no float128, so this is the float64 path everywhere (port plan ยง1.3).

Reference: gymnasium/wrappers/utils.py.

Exceptions

TypeError

Thrown when box is no Box, or a bound is neither an array nor an integer or float, with Gymnasium's messages.

ValueError

Thrown, with Gymnasium's messages, when a bound's shape is not the box's, an unbounded component's new bound is not the same infinity, a new minimum exceeds its maximum, or the box's own low exceeds its high.

UpdateMeanVarCountFromMoments(NDArray, NDArray, double, NDArray, NDArray, long)

Gymnasium's update_mean_var_count_from_moments: merges running moments with a batch's, element by element, in the dtype NumPy 2 computes them in (the statistics' dtype promoted with the batch's; the Python counts cast to it as weak scalars), with the source's order of operations.

public static (NDArray Mean, NDArray Var, double Count) UpdateMeanVarCountFromMoments(NDArray mean, NDArray var, double count, NDArray batchMean, NDArray batchVar, long batchCount)

Parameters

mean NDArray

The running mean.

var NDArray

The running variance.

count double

The running count.

batchMean NDArray

The batch's mean, of the running mean's shape.

batchVar NDArray

The batch's variance, of the same shape.

batchCount long

The batch's length.

Returns

(NDArray Mean, NDArray Var, double Count)

New mean and variance arrays the caller owns, and the new count.

Remarks

Exceptions

ArgumentNullException

Thrown when an array is null.

ValueError

Thrown when the shapes differ.