Class NormalizeObservationVector<TAct>
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
TActThe 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
envVectorEnv<NDArray, TAct>The vector env, whose single observation space has a shape.
epsilondoubleAdded 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
envis null.
Properties
Epsilon
The variance's offset under the square root (epsilon).
public double Epsilon { get; set; }
Property Value
ObsRms
The running statistics of the observations (obs_rms); owned by this wrapper.
public RunningMeanStd ObsRms { get; }
Property Value
SavedKwargs
The recorded constructor arguments, {'epsilon': 1e-08} (Python's _saved_kwargs).
[PyName("_saved_kwargs")]
public Info SavedKwargs { get; }
Property Value
UpdateRunningMean
Whether observations update the statistics (update_running_mean); turn off to evaluate with frozen statistics.
public bool UpdateRunningMean { get; set; }
Property Value
Methods
Dispose(bool)
Disposes the statistics with the stack.
protected override void Dispose(bool disposing)
Parameters
Observations(NDArray)
Updates the statistics with the batch, then returns float32((obs - mean) / sqrt(var + epsilon)).
public override NDArray Observations(NDArray observations)
Parameters
observationsNDArrayThe 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
seedsIReadOnlyList<BigInteger?>The seeds, passed on.
optionsIReadOnlyDictionary<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
seedBigInteger?The seed, passed on.
optionsIReadOnlyDictionary<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.