namespace Unity.MLAgents.Sensors
{
///
/// The Dimension property flags of the observations
///
[System.Flags]
public enum DimensionProperty
{
///
/// No properties specified.
///
Unspecified = 0,
///
/// No Property of the observation in that dimension. Observation can be processed with
/// fully connected networks.
///
None = 1,
///
/// Means it is suitable to do a convolution in this dimension.
///
TranslationalEquivariance = 2,
///
/// Means that there can be a variable number of observations in this dimension.
/// The observations are unordered.
///
VariableSize = 4,
}
///
/// The ObservationType enum of the Sensor.
///
public enum ObservationType
{
///
/// Collected observations are generic.
///
Default = 0,
///
/// Collected observations contain goal information.
///
GoalSignal = 1,
}
///
/// Sensor interface for generating observations.
///
public interface ISensor
{
///
/// Returns a description of the observations that will be generated by the sensor.
/// See for more details, and helper methods to create one.
///
///
ObservationSpec GetObservationSpec();
///
/// Write the observation data directly to the .
/// Note that this (and ) may
/// be called multiple times per agent step, so should not mutate any internal state.
///
/// Where the observations will be written to.
/// The number of elements written.
int Write(ObservationWriter writer);
///
/// 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.
///
/// Compressed observation.
byte[] GetCompressedObservation();
///
/// Update any internal state of the sensor. This is called once per each agent step.
///
void Update();
///
/// Resets the internal state of the sensor. This is called at the end of an Agent's episode.
/// Most implementations can leave this empty.
///
void Reset();
///
/// Return information on the compression type being used. If no compression is used, return
/// .
///
/// CompressionSpec used by the sensor.
CompressionSpec GetCompressionSpec();
///
/// 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();
}
///
/// Helper methods to be shared by all classes that implement .
///
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 obsSpec = sensor.GetObservationSpec();
var count = 1;
for (var i = 0; i < obsSpec.Rank; i++)
{
count *= obsSpec.Shape[i];
}
return count;
}
}
}