Class NormalizeObservation<TObs, TAct>
Normalizes every observation to roughly zero mean and unit variance by running statistics of the observations seen
so far, as Gymnasium's NormalizeObservation does, byte for byte: float32 statistics, float32 results.
public class NormalizeObservation<TObs, TAct> : ObservationWrapper<NDArray, TObs, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs
Type Parameters
TObsThe env's observation type (an array, or a number).
TActThe action type, passed through.
- Inheritance
-
ObservationWrapper<NDArray, TObs, TAct>NormalizeObservation<TObs, TAct>
- Implements
- Inherited Members
- Extension Methods
Remarks
The statistics (ObsRms) start at mean 0 and variance 1 and are float32 like the new observation space
(an unbounded float32 Box of the env's shape); an observation of a wider dtype promotes them to float64, as
NumPy does. Every observation, the reset's included, updates them unless UpdateRunningMean is off.
Not thread-safe.
Reference: gymnasium/wrappers/stateful_observation.py.
Constructors
NormalizeObservation(Env<TObs, TAct>, NormalizeObservationOptions)
Builds the instance from its options record: the properties set, the constructor's defaults for the rest.
public NormalizeObservation(Env<TObs, TAct> env, NormalizeObservationOptions options)
Parameters
envEnv<TObs, TAct>The env to wrap.
optionsNormalizeObservationOptionsThe options.
Exceptions
- ArgumentNullException
Thrown when
optionsis null.
NormalizeObservation(Env<TObs, TAct>, double)
Wraps env.
public NormalizeObservation(Env<TObs, TAct> env, double epsilon = 1E-08)
Parameters
envEnv<TObs, TAct>The env, whose observation space must have a shape.
epsilondoubleAdded to the variance under the square root, strictly positive.
Exceptions
- InvalidBound
Thrown for a non-positive
epsilon:.epsilonshould be strictly positive. Received 0.0- TypeError
Thrown when
envis null.- ValueError
Thrown when the observation space has no shape.
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
Observation(TObs)
Updates the statistics with the observation, then returns np.float32((obs - mean) / np.sqrt(var + epsilon)),
each operation in the dtype NumPy computes it in.
public override NDArray Observation(TObs observation)
Parameters
observationTObsThe env's observation; left to the env's caller.
Returns
- NDArray
A new float32 array of the observation's shape.