Class StackingSensor
Sensor that wraps around another Sensor to provide temporal stacking. Conceptually, consecutive observations are stored left-to-right, which is how they're output For example, 4 stacked sets of observations would be output like | t = now - 3 | t = now -3 | t = now - 2 | t = now | Internally, a circular buffer of arrays is used. The m_CurrentIndex represents the most recent observation. Currently, observations are stacked on the last dimension.
Inherited Members
Namespace: Unity.MLAgents.Sensors
Syntax
public class StackingSensor : ISparseChannelSensor, ISensor, IBuiltInSensor
Constructors
StackingSensor(ISensor, Int32)
Initializes the sensor.
Declaration
public StackingSensor(ISensor wrapped, int numStackedObservations)
Parameters
Type | Name | Description |
---|---|---|
ISensor | wrapped | The wrapped sensor. |
Int32 | numStackedObservations | Number of stacked observations to keep. |
Methods
GetBuiltInSensorType()
Declaration
public BuiltInSensorType GetBuiltInSensorType()
Returns
Type | Description |
---|---|
BuiltInSensorType |
GetCompressedChannelMapping()
Returns the mapping of the channels in compressed data to the actual channel after decompression. The mapping is a list of interger index with the same length as the number of output observation layers (channels), including padding if there's any. Each index indicates the actual channel the layer will go into. Layers with the same index will be averaged, and layers with negative index will be dropped. For example, mapping for CameraSensor using grayscale and stacking of two: [0, 0, 0, 1, 1, 1] Mapping for GridSensor of 4 channels and stacking of two: [0, 1, 2, 3, -1, -1, 4, 5, 6, 7, -1, -1]
Declaration
public int[] GetCompressedChannelMapping()
Returns
Type | Description |
---|---|
Int32[] | Mapping of the compressed data |
Implements
GetCompressedObservation()
Return a compressed representation of the observation. For small observations, this should generally not be implemented. However, compressing large observations (such as visual results) can significantly improve model training time.
Declaration
public byte[] GetCompressedObservation()
Returns
Type | Description |
---|---|
Byte[] | Compressed observation. |
Implements
GetCompressionType()
Return the compression type being used. If no compression is used, return None.
Declaration
public SensorCompressionType GetCompressionType()
Returns
Type | Description |
---|---|
SensorCompressionType | Compression type used by the sensor. |
Implements
GetName()
Get the name of the sensor. This is used to ensure deterministic sorting of the sensors on an Agent, so the naming must be consistent across all sensors and agents.
Declaration
public string GetName()
Returns
Type | Description |
---|---|
String | The name of the sensor. |
Implements
GetObservationShape()
Returns the size of the observations that will be generated. For example, a sensor that observes the velocity of a rigid body (in 3D) would return new {3}. A sensor that returns an RGB image would return new [] {Height, Width, 3}
Declaration
public int[] GetObservationShape()
Returns
Type | Description |
---|---|
Int32[] | Size of the observations that will be generated. |
Implements
Reset()
Resets the internal state of the sensor. This is called at the end of an Agent's episode. Most implementations can leave this empty.
Declaration
public void Reset()
Implements
Update()
Updates the index of the "current" buffer.
Declaration
public void Update()
Implements
Write(ObservationWriter)
Write the observation data directly to the ObservationWriter. Note that this (and GetCompressedObservation()) may be called multiple times per agent step, so should not mutate any internal state.
Declaration
public int Write(ObservationWriter writer)
Parameters
Type | Name | Description |
---|---|---|
ObservationWriter | writer | Where the observations will be written to. |
Returns
Type | Description |
---|---|
Int32 | The number of elements written. |