File size: 2,189 Bytes
05c9ac2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
using UnityEngine;
namespace Unity.MLAgents.Sensors
{
/// <summary>
/// Grid-based sensor with one-hot observations.
/// </summary>
public class OneHotGridSensor : GridSensorBase
{
/// <summary>
/// Create a OneHotGridSensor with the specified configuration.
/// </summary>
/// <param name="name">The sensor name</param>
/// <param name="cellScale">The scale of each cell in the grid</param>
/// <param name="gridSize">Number of cells on each side of the grid</param>
/// <param name="detectableTags">Tags to be detected by the sensor</param>
/// <param name="compression">Compression type</param>
public OneHotGridSensor(
string name,
Vector3 cellScale,
Vector3Int gridSize,
string[] detectableTags,
SensorCompressionType compression
) : base(name, cellScale, gridSize, detectableTags, compression)
{
}
/// <inheritdoc/>
protected override int GetCellObservationSize()
{
return DetectableTags == null ? 0 : DetectableTags.Length;
}
/// <inheritdoc/>
protected override bool IsDataNormalized()
{
return true;
}
/// <inheritdoc/>
protected internal override ProcessCollidersMethod GetProcessCollidersMethod()
{
return ProcessCollidersMethod.ProcessClosestColliders;
}
/// <summary>
/// Get the one-hot representation of the detected game object's tag.
/// </summary>
/// <param name="detectedObject">The game object that was detected within a certain cell</param>
/// <param name="tagIndex">The index of the detectedObject's tag in the DetectableObjects list</param>
/// <param name="dataBuffer">The buffer to write the observation values.
/// The buffer size is configured by <seealso cref="GetCellObservationSize"/>.
/// </param>
protected override void GetObjectData(GameObject detectedObject, int tagIndex, float[] dataBuffer)
{
dataBuffer[tagIndex] = 1;
}
}
}
|