Table of Contents

Class NormalizeObservation<TObs, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

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

TObs

The env's observation type (an array, or a number).

TAct

The action type, passed through.

Inheritance
Env<NDArray, TAct>
Wrapper<NDArray, TAct, 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

env Env<TObs, TAct>

The env to wrap.

options NormalizeObservationOptions

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

NormalizeObservation(Env<TObs, TAct>, double)

Wraps env.

public NormalizeObservation(Env<TObs, TAct> env, double epsilon = 1E-08)

Parameters

env Env<TObs, TAct>

The env, whose observation space must have a shape.

epsilon double

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

Exceptions

InvalidBound

Thrown for a non-positive epsilon: epsilon should be strictly positive. Received 0.0.

TypeError

Thrown when env is 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

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().

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

observation TObs

The env's observation; left to the env's caller.

Returns

NDArray

A new float32 array of the observation's shape.