using System; using UnityEngine; using UnityEngine.Serialization; namespace Unity.MLAgents.Policies { /// /// Whether the action space is discrete or continuous. /// public enum SpaceType { /// /// Discrete action space: a fixed number of options are available. /// Discrete, /// /// Continuous action space: each action can take on a float value. /// Continuous } /// /// Holds information about the brain. It defines what are the inputs and outputs of the /// decision process. /// /// /// Set brain parameters for an instance using the /// component attached to the agent's [GameObject]. /// /// [GameObject]: https://docs.unity3d.com/Manual/GameObjects.html /// [Serializable] public class BrainParameters { /// /// The number of the observations that are added in /// /// /// /// The length of the vector containing observation values. /// [FormerlySerializedAs("vectorObservationSize")] public int VectorObservationSize = 1; /// /// Stacking refers to concatenating the observations across multiple frames. This field /// indicates the number of frames to concatenate across. /// [FormerlySerializedAs("numStackedVectorObservations")] [Range(1, 50)] public int NumStackedVectorObservations = 1; /// /// The size of the action space. /// /// The size specified is interpreted differently depending on whether /// the agent uses the continuous or the discrete action space. /// /// For the continuous action space: the length of the float vector that represents /// the action. /// For the discrete action space: the number of branches in the action space. /// [FormerlySerializedAs("vectorActionSize")] public int[] VectorActionSize = new[] { 1 }; /// /// The list of strings describing what the actions correspond to. /// [FormerlySerializedAs("vectorActionDescriptions")] public string[] VectorActionDescriptions; /// /// Defines if the action is discrete or continuous. /// [FormerlySerializedAs("vectorActionSpaceType")] public SpaceType VectorActionSpaceType = SpaceType.Discrete; /// /// The number of actions specified by this Brain. /// public int NumActions { get { switch (VectorActionSpaceType) { case SpaceType.Discrete: return VectorActionSize.Length; case SpaceType.Continuous: return VectorActionSize[0]; default: return 0; } } } /// /// Deep clones the BrainParameter object. /// /// A new BrainParameter object with the same values as the original. public BrainParameters Clone() { return new BrainParameters { VectorObservationSize = VectorObservationSize, NumStackedVectorObservations = NumStackedVectorObservations, VectorActionSize = (int[])VectorActionSize.Clone(), VectorActionDescriptions = (string[])VectorActionDescriptions.Clone(), VectorActionSpaceType = VectorActionSpaceType }; } } }