Class WrapperFunctions
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
spaceSpaceThe space; an ObjectSpace view is looked through.
Returns
- object
A new element the caller owns: an array for
Box,MultiDiscreteandMultiBinary, a 0-d array of the space's dtype holdingstartforDiscrete, an object?[] (Python's tuple) forTuple, an Info forDict, the first character repeatedmin_lengthtimes forText, a GraphInstance with one zero node (and one zero edge from node 0 to node 0) forGraph, the stacked feature space's zero or an empty tuple forSequence, and(0, zero of the first subspace)forOneOf.
Remarks
Reference: gymnasium/wrappers/utils.py.
Exceptions
- TypeError
Thrown when
spaceis 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
boxSpaceThe space; it must be a
Box(an ObjectSpace view of one is looked through).newMinobjectThe 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 Pythonfloat(float64), a float or a 0-d array a NumPy scalar of its own dtype, asnp.fullwould take them.newMaxobjectThe 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
boxis noBox, 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
meanNDArrayThe running mean.
varNDArrayThe running variance.
countdoubleThe running count.
batchMeanNDArrayThe batch's mean, of the running mean's shape.
batchVarNDArrayThe batch's variance, of the same shape.
batchCountlongThe batch's length.
Returns
- (NDArray Mean, NDArray Var, double Count)
New mean and variance arrays the caller owns, and the new count.
Remarks
Reference: gymnasium/wrappers/utils.py.
Exceptions
- ArgumentNullException
Thrown when an array is null.
- ValueError
Thrown when the shapes differ.