Table of Contents

Class NormalizeObservationVector<TAct>

Namespace
Gym.Wrappers.Vector
Assembly
Gym.dll

Normalizes the batched observations by running statistics, as Gymnasium's vector NormalizeObservation does: every batch updates the mean and variance (one update of num_envs rows), and the observations come back as float32((obs - mean) / sqrt(var + epsilon)).

[PyName("NormalizeObservation")]
public class NormalizeObservationVector<TAct> : VectorObservationWrapper<NDArray, NDArray, TAct>, IVectorEnv, IDisposable, IRecordConstructorArgs

Type Parameters

TAct

The batched action type, passed through.

Inheritance
NormalizeObservationVector<TAct>
Implements
Inherited Members
Extension Methods

Remarks

The statistics are float32 (the new single space's dtype); a batch of a wider dtype promotes them, as NumPy does. Partial resets are refused (the statistics would mix episodes), and the env must autoreset NEXT_STEP. Not thread-safe.

Reference: gymnasium/wrappers/vector/stateful_observation.py.

Constructors

NormalizeObservationVector(VectorEnv<NDArray, TAct>, double)

Wraps env.

public NormalizeObservationVector(VectorEnv<NDArray, TAct> env, double epsilon = 1E-08)

Parameters

env VectorEnv<NDArray, TAct>

The vector env, whose single observation space has a shape.

epsilon double

Added to the variance under the square root, strictly positive.

Exceptions

InvalidBound

Thrown for a non-positive epsilon, with Gymnasium's message.

ValueError

Thrown when the env's autoreset mode is not NEXT_STEP, with Gymnasium's message.

TypeError

Thrown when env is null.

Properties

Epsilon

The variance's offset under the square root (epsilon).

public double Epsilon { get; set; }

Property Value

double

ObsRms

The running statistics of the observations (obs_rms); owned by this wrapper.

public RunningMeanStd ObsRms { get; }

Property Value

RunningMeanStd

SavedKwargs

The recorded constructor arguments, {'epsilon': 1e-08} (Python's _saved_kwargs).

[PyName("_saved_kwargs")]
public Info SavedKwargs { get; }

Property Value

Info

UpdateRunningMean

Whether observations update the statistics (update_running_mean); turn off to evaluate with frozen statistics.

public bool UpdateRunningMean { get; set; }

Property Value

bool

Methods

Dispose(bool)

Disposes the statistics with the stack.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true from Dispose().

Observations(NDArray)

Updates the statistics with the batch, then returns float32((obs - mean) / sqrt(var + epsilon)).

public override NDArray Observations(NDArray observations)

Parameters

observations NDArray

The env's batched observations; left to the env's caller.

Returns

NDArray

A new float32 batch.

Reset(IReadOnlyList<BigInteger?>, IReadOnlyDictionary<string, object?>?)

Resets the env with one seed per sub-env; a partial reset is refused.

public override VectorResetResult<NDArray> Reset(IReadOnlyList<BigInteger?> seeds, IReadOnlyDictionary<string, object?>? options = null)

Parameters

seeds IReadOnlyList<BigInteger?>

The seeds, passed on.

options IReadOnlyDictionary<string, object>

The options, passed on.

Returns

VectorResetResult<NDArray>

The normalized first observations and the env's infos.

Exceptions

ValueError

Thrown for a partial reset_mask, with Gymnasium's message.

Reset(BigInteger?, IReadOnlyDictionary<string, object?>?)

Resets the env; a partial reset (a reset_mask not all true) is refused.

public override VectorResetResult<NDArray> Reset(BigInteger? seed = null, IReadOnlyDictionary<string, object?>? options = null)

Parameters

seed BigInteger?

The seed, passed on.

options IReadOnlyDictionary<string, object>

The options, passed on.

Returns

VectorResetResult<NDArray>

The normalized first observations and the env's infos.

Exceptions

ValueError

Thrown for a partial reset_mask, with Gymnasium's message.