| | using System; |
| | using UnityEngine; |
| | using UnityEngine.Serialization; |
| | using Unity.MLAgents.Actuators; |
| |
|
| | namespace Unity.MLAgents.Policies |
| | { |
| | |
| | |
| | |
| | [Obsolete("Continuous and discrete actions on the same Agent are now supported; see ActionSpec.")] |
| | internal enum SpaceType |
| | { |
| | |
| | |
| | |
| | Discrete, |
| |
|
| | |
| | |
| | |
| | Continuous |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [Serializable] |
| | public class BrainParameters : ISerializationCallbackReceiver |
| | { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [FormerlySerializedAs("vectorObservationSize")] |
| | public int VectorObservationSize = 1; |
| |
|
| | |
| | |
| | |
| | |
| | [FormerlySerializedAs("numStackedVectorObservations")] |
| | [Range(1, 50)] public int NumStackedVectorObservations = 1; |
| |
|
| | [SerializeField] |
| | internal ActionSpec m_ActionSpec = new ActionSpec(0, null); |
| |
|
| | |
| | |
| | |
| | public ActionSpec ActionSpec |
| | { |
| | get { return m_ActionSpec; } |
| | set |
| | { |
| | m_ActionSpec.NumContinuousActions = value.NumContinuousActions; |
| | m_ActionSpec.BranchSizes = value.BranchSizes; |
| | SyncDeprecatedActionFields(); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | [Obsolete("VectorActionSize has been deprecated, please use ActionSpec instead.")] |
| | [SerializeField] |
| | [FormerlySerializedAs("vectorActionSize")] |
| | internal int[] VectorActionSize = new[] { 1 }; |
| |
|
| | |
| | |
| | |
| | [FormerlySerializedAs("vectorActionDescriptions")] |
| | public string[] VectorActionDescriptions; |
| |
|
| | |
| | |
| | |
| | [Obsolete("VectorActionSpaceType has been deprecated, please use ActionSpec instead.")] |
| | [SerializeField] |
| | [FormerlySerializedAs("vectorActionSpaceType")] |
| | internal SpaceType VectorActionSpaceType = SpaceType.Discrete; |
| |
|
| | [SerializeField] |
| | [HideInInspector] |
| | internal bool hasUpgradedBrainParametersWithActionSpec; |
| |
|
| | |
| | |
| | |
| | |
| | public BrainParameters Clone() |
| | { |
| | |
| | #pragma warning disable CS0618 |
| | return new BrainParameters |
| | { |
| | VectorObservationSize = VectorObservationSize, |
| | NumStackedVectorObservations = NumStackedVectorObservations, |
| | VectorActionDescriptions = (string[])VectorActionDescriptions.Clone(), |
| | ActionSpec = new ActionSpec(ActionSpec.NumContinuousActions, ActionSpec.BranchSizes), |
| | VectorActionSize = (int[])VectorActionSize.Clone(), |
| | VectorActionSpaceType = VectorActionSpaceType, |
| | }; |
| | #pragma warning restore CS0618 |
| | } |
| |
|
| | |
| | |
| | |
| | private void UpdateToActionSpec() |
| | { |
| | |
| | #pragma warning disable CS0618 |
| | if (!hasUpgradedBrainParametersWithActionSpec |
| | && m_ActionSpec.NumContinuousActions == 0 |
| | && m_ActionSpec.NumDiscreteActions == 0) |
| | { |
| | if (VectorActionSpaceType == SpaceType.Continuous) |
| | { |
| | m_ActionSpec.NumContinuousActions = VectorActionSize[0]; |
| | } |
| | if (VectorActionSpaceType == SpaceType.Discrete) |
| | { |
| | m_ActionSpec.BranchSizes = (int[])VectorActionSize.Clone(); |
| | } |
| | } |
| | hasUpgradedBrainParametersWithActionSpec = true; |
| | #pragma warning restore CS0618 |
| | } |
| |
|
| | |
| | |
| | |
| | private void SyncDeprecatedActionFields() |
| | { |
| | |
| | #pragma warning disable CS0618 |
| |
|
| | if (m_ActionSpec.NumContinuousActions == 0) |
| | { |
| | VectorActionSize = (int[])ActionSpec.BranchSizes.Clone(); |
| | VectorActionSpaceType = SpaceType.Discrete; |
| | } |
| | else if (m_ActionSpec.NumDiscreteActions == 0) |
| | { |
| | VectorActionSize = new[] { m_ActionSpec.NumContinuousActions }; |
| | VectorActionSpaceType = SpaceType.Continuous; |
| | } |
| | else |
| | { |
| | VectorActionSize = null; |
| | } |
| | #pragma warning restore CS0618 |
| | } |
| |
|
| | |
| | |
| | |
| | public void OnBeforeSerialize() |
| | { |
| | UpdateToActionSpec(); |
| | SyncDeprecatedActionFields(); |
| | } |
| |
|
| | |
| | |
| | |
| | public void OnAfterDeserialize() |
| | { |
| | UpdateToActionSpec(); |
| | SyncDeprecatedActionFields(); |
| | } |
| | } |
| | } |
| |
|