namespace MLAgents.Sensor
{
public enum SensorCompressionType
{
None,
PNG
}
///
/// Sensor interface for generating observations.
/// For custom implementations, it is recommended to SensorBase instead.
///
public interface ISensor {
///
/// 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 [] {Width, Height, 3}
///
///
int[] GetFloatObservationShape();
///
/// Write the observation data directly to the WriteAdapter.
/// This is considered an advanced interface; for a simpler approach, use SensorBase and override WriteFloats instead.
/// Note that this (and GetCompressedObservation) may be called multiple times per agent step, so should not
/// mutate any internal state.
///
///
/// The number of elements written
int Write(WriteAdapter adapater);
///
/// 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.
///
///
byte[] GetCompressedObservation();
///
/// Update any internal state of the sensor. This is called once per each agent step.
///
void Update();
///
/// Return the compression type being used. If no compression is used, return SensorCompressionType.None
///
///
SensorCompressionType GetCompressionType();
///
/// 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.
///
/// The name of the sensor
string GetName();
}
public static class SensorExtensions
{
///
/// Get the total number of elements in the ISensor's observation (i.e. the product of the shape elements).
///
///
///
public static int ObservationSize(this ISensor sensor)
{
var shape = sensor.GetFloatObservationShape();
int count = 1;
for (var i = 0; i < shape.Length; i++)
{
count *= shape[i];
}
return count;
}
}
}