Class ObservableAttribute
Specify that a field or property should be used to generate observations for an Agent. For each field or property that uses ObservableAttribute, a corresponding ISensor will be created during Agent initialization, and this sensor will read the values during training and inference.
Inherited Members
Namespace: Unity.MLAgents.Sensors.Reflection
Assembly: Unity.ML-Agents.dll
Syntax
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field)]
public class ObservableAttribute : Attribute
Remarks
ObservableAttribute is intended to make initial setup of an Agent easier. Because it
uses reflection to read the values of fields and properties at runtime, this may
be much slower than reading the values directly. If the performance of
ObservableAttribute is an issue, you can get the same functionality by overriding
Collect
Note that you do not need to adjust the VectorObservationSize in
Brain
Examples
This sample class will produce two observations, one for the m_Health field, and one for the HealthPercent property.
using Unity.MLAgents;
using Unity.MLAgents.Sensors.Reflection;
public class MyAgent : Agent
{
[Observable]
int m_Health;
[Observable]
float HealthPercent
{
get => return 100.0f * m_Health / float(m_MaxHealth);
}
}
Constructors
ObservableAttribute(string, int)
ObservableAttribute constructor.
Declaration
public ObservableAttribute(string name = null, int numStackedObservations = 1)