Class OneHotGridSensor
Grid-based sensor with one-hot observations.
Inherited Members
Namespace: Unity.MLAgents.Sensors
Syntax
public class OneHotGridSensor : GridSensorBase, ISensor, IBuiltInSensor, IDisposable
Constructors
OneHotGridSensor(String, Vector3, Vector3Int, String[], SensorCompressionType)
Create a OneHotGridSensor with the specified configuration.
Declaration
public OneHotGridSensor(string name, Vector3 cellScale, Vector3Int gridSize, string[] detectableTags, SensorCompressionType compression)
Parameters
Type | Name | Description |
---|---|---|
String | name | The sensor name |
Vector3 | cellScale | The scale of each cell in the grid |
Vector3Int | gridSize | Number of cells on each side of the grid |
String[] | detectableTags | Tags to be detected by the sensor |
SensorCompressionType | compression | Compression type |
Methods
GetCellObservationSize()
Get the observation size for each cell. This will be the size of dataBuffer for GetObjectData(GameObject, Int32, Single[]). If overriding GetObjectData(GameObject, Int32, Single[]), override this method as well to the custom observation size.
Declaration
protected override int GetCellObservationSize()
Returns
Type | Description |
---|---|
Int32 | The observation size of each cell. |
Overrides
GetObjectData(GameObject, Int32, Single[])
Get the one-hot representation of the detected game object's tag.
Declaration
protected override void GetObjectData(GameObject detectedObject, int tagIndex, float[] dataBuffer)
Parameters
Type | Name | Description |
---|---|---|
GameObject | detectedObject | The game object that was detected within a certain cell |
Int32 | tagIndex | The index of the detectedObject's tag in the DetectableObjects list |
Single[] | dataBuffer | The buffer to write the observation values. The buffer size is configured by GetCellObservationSize(). |
Overrides
GetProcessCollidersMethod()
Whether to process all detected colliders in a cell. Default to false and only use the one closest to the agent. If overriding GetObjectData(GameObject, Int32, Single[]), consider override this method when needed.
Declaration
protected override ProcessCollidersMethod GetProcessCollidersMethod()
Returns
Type | Description |
---|---|
ProcessCollidersMethod | Bool value indicating whether to process all detected colliders in a cell. |
Overrides
IsDataNormalized()
Whether the data is normalized within [0, 1]. The sensor can only use PNG compression if the data is normailzed. If overriding GetObjectData(GameObject, Int32, Single[]), override this method as well according to the custom observation values.
Declaration
protected override bool IsDataNormalized()
Returns
Type | Description |
---|---|
Boolean | Bool value indicating whether data is normalized. |