Class ObservableAttribute | ML Agents | 1.6.0-preview
docs.unity.cn
    Show / Hide Table of Contents

    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.

    Inheritance
    Object
    Attribute
    ObservableAttribute
    Inherited Members
    Attribute.GetCustomAttributes(MemberInfo, Type)
    Attribute.GetCustomAttributes(MemberInfo, Type, Boolean)
    Attribute.GetCustomAttributes(MemberInfo)
    Attribute.GetCustomAttributes(MemberInfo, Boolean)
    Attribute.IsDefined(MemberInfo, Type)
    Attribute.IsDefined(MemberInfo, Type, Boolean)
    Attribute.GetCustomAttribute(MemberInfo, Type)
    Attribute.GetCustomAttribute(MemberInfo, Type, Boolean)
    Attribute.GetCustomAttributes(ParameterInfo)
    Attribute.GetCustomAttributes(ParameterInfo, Type)
    Attribute.GetCustomAttributes(ParameterInfo, Type, Boolean)
    Attribute.GetCustomAttributes(ParameterInfo, Boolean)
    Attribute.IsDefined(ParameterInfo, Type)
    Attribute.IsDefined(ParameterInfo, Type, Boolean)
    Attribute.GetCustomAttribute(ParameterInfo, Type)
    Attribute.GetCustomAttribute(ParameterInfo, Type, Boolean)
    Attribute.GetCustomAttributes(Module, Type)
    Attribute.GetCustomAttributes(Module)
    Attribute.GetCustomAttributes(Module, Boolean)
    Attribute.GetCustomAttributes(Module, Type, Boolean)
    Attribute.IsDefined(Module, Type)
    Attribute.IsDefined(Module, Type, Boolean)
    Attribute.GetCustomAttribute(Module, Type)
    Attribute.GetCustomAttribute(Module, Type, Boolean)
    Attribute.GetCustomAttributes(Assembly, Type)
    Attribute.GetCustomAttributes(Assembly, Type, Boolean)
    Attribute.GetCustomAttributes(Assembly)
    Attribute.GetCustomAttributes(Assembly, Boolean)
    Attribute.IsDefined(Assembly, Type)
    Attribute.IsDefined(Assembly, Type, Boolean)
    Attribute.GetCustomAttribute(Assembly, Type)
    Attribute.GetCustomAttribute(Assembly, Type, Boolean)
    Attribute.Equals(Object)
    Attribute.GetHashCode()
    Attribute.Match(Object)
    Attribute.IsDefaultAttribute()
    Attribute._Attribute.GetTypeInfoCount(UInt32)
    Attribute._Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)
    Attribute._Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)
    Attribute._Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)
    Attribute.TypeId
    Object.ToString()
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.MLAgents.Sensors.Reflection
    Syntax
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
    public class ObservableAttribute : Attribute, _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 CollectObservations(VectorSensor) or creating a custom ISensor implementation to read the values without reflection.

    Note that you do not need to adjust the VectorObservationSize in BrainParameters when adding ObservableAttribute to fields or properties.

    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, Int32)

    ObservableAttribute constructor.

    Declaration
    public ObservableAttribute(string name = null, int numStackedObservations = 1)
    Parameters
    Type Name Description
    String name

    Optional override for the sensor name. Note that all sensors for an Agent must have a unique name.

    Int32 numStackedObservations

    Number of frames to concatenate observations from.

    Back to top Copyright © 2020 Unity Technologies
    Generated by DocFX
    on 20 November 2020