Пример #1
0
        /// Helper function that resets all the data structures associated with
        /// the agent. Typically used when the agent is being initialized or reset
        /// at the end of an episode.
        void ResetData()
        {
            if (brain == null)
            {
                return;
            }

            BrainParameters param = brain.brainParameters;

            actionMasker = new ActionMasker(param);
            if (param.vectorActionSpaceType == SpaceType.continuous)
            {
                action.vectorActions     = new float[param.vectorActionSize[0]];
                info.storedVectorActions = new float[param.vectorActionSize[0]];
            }
            else
            {
                action.vectorActions     = new float[param.vectorActionSize.Length];
                info.storedVectorActions = new float[param.vectorActionSize.Length];
            }

            if (info.textObservation == null)
            {
                info.textObservation = "";
            }
            action.textActions     = "";
            info.memories          = new List <float>();
            action.memories        = new List <float>();
            info.vectorObservation =
                new List <float>(param.vectorObservationSize);
            info.stackedVectorObservation =
                new List <float>(param.vectorObservationSize
                                 * brain.brainParameters.numStackedVectorObservations);
            info.stackedVectorObservation.AddRange(
                new float[param.vectorObservationSize
                          * param.numStackedVectorObservations]);

            info.visualObservations = new List <Texture2D>();

            /// Added by M.Baske to enable frame-stacking.
            ///
            visualObservations = brain.gameObject.GetComponent <VisualObservations>();
            if (visualObservations)
            {
                visualObservations.OnAgentResetData(this);
            }
        }
Пример #2
0
        /// Helper function that resets all the data structures associated with
        /// the agent. Typically used when the agent is being initialized or reset
        /// at the end of an episode.
        void ResetData()
        {
            if (brain == null)
            {
                return;
            }

            BrainParameters param = brain.brainParameters;

            actionMasker = new ActionMasker(param);
            // If we haven't initialized vectorActions, initialize to 0. This should only
            // happen during the creation of the Agent. In subsequent episodes, vectorAction
            // should stay the previous action before the Done(), so that it is properly recorded.
            if (action.vectorActions == null)
            {
                if (param.vectorActionSpaceType == SpaceType.continuous)
                {
                    action.vectorActions     = new float[param.vectorActionSize[0]];
                    info.storedVectorActions = new float[param.vectorActionSize[0]];
                }
                else
                {
                    action.vectorActions     = new float[param.vectorActionSize.Length];
                    info.storedVectorActions = new float[param.vectorActionSize.Length];
                }
            }

            if (info.textObservation == null)
            {
                info.textObservation = "";
            }
            action.textActions     = "";
            info.memories          = new List <float>();
            action.memories        = new List <float>();
            info.vectorObservation =
                new List <float>(param.vectorObservationSize);
            info.stackedVectorObservation =
                new List <float>(param.vectorObservationSize
                                 * brain.brainParameters.numStackedVectorObservations);
            info.stackedVectorObservation.AddRange(
                new float[param.vectorObservationSize
                          * param.numStackedVectorObservations]);

            info.visualObservations = new List <Texture2D>();
            info.customObservation  = null;
        }
        /// Helper function that resets all the data structures associated with
        /// the agent. Typically used when the agent is being initialized or reset
        /// at the end of an episode.
        void ResetData()
        {
            var param = m_PolicyFactory.brainParameters;

            m_ActionMasker = new ActionMasker(param);
            // If we haven't initialized vectorActions, initialize to 0. This should only
            // happen during the creation of the Agent. In subsequent episodes, vectorAction
            // should stay the previous action before the Done(), so that it is properly recorded.
            if (m_Action.vectorActions == null)
            {
                if (param.vectorActionSpaceType == SpaceType.Continuous)
                {
                    m_Action.vectorActions     = new float[param.vectorActionSize[0]];
                    m_Info.storedVectorActions = new float[param.vectorActionSize[0]];
                }
                else
                {
                    m_Action.vectorActions     = new float[param.vectorActionSize.Length];
                    m_Info.storedVectorActions = new float[param.vectorActionSize.Length];
                }
            }

            if (m_Info.textObservation == null)
            {
                m_Info.textObservation = "";
            }
            m_Action.textActions     = "";
            m_Info.memories          = new List <float>();
            m_Action.memories        = new List <float>();
            m_Info.vectorObservation =
                new List <float>(param.vectorObservationSize);
            m_Info.stackedVectorObservation =
                new List <float>(param.vectorObservationSize
                                 * param.numStackedVectorObservations);
            m_Info.stackedVectorObservation.AddRange(
                new float[param.vectorObservationSize
                          * param.numStackedVectorObservations]);

            m_Info.compressedObservations = new List <CompressedObservation>();
            m_Info.customObservation      = null;
        }
Пример #4
0
 /// Helper function that resets all the data structures associated with
 /// the agent. Typically used when the agent is being initialized or reset
 /// at the end of an episode.
 void ResetData()
 {
     var param = m_PolicyFactory.brainParameters;
     m_ActionMasker = new ActionMasker(param);
     // If we haven't initialized vectorActions, initialize to 0. This should only
     // happen during the creation of the Agent. In subsequent episodes, vectorAction
     // should stay the previous action before the Done(), so that it is properly recorded.
     if (m_Action.vectorActions == null)
     {
         if (param.vectorActionSpaceType == SpaceType.Continuous)
         {
             m_Action.vectorActions = new float[param.vectorActionSize[0]];
             m_Info.storedVectorActions = new float[param.vectorActionSize[0]];
         }
         else
         {
             m_Action.vectorActions = new float[param.vectorActionSize.Length];
             m_Info.storedVectorActions = new float[param.vectorActionSize.Length];
         }
     }
 }
Пример #5
0
        /// Helper function that resets all the data structures associated with
        /// the agent. Typically used when the agent is being initialized or reset
        /// at the end of an episode.
        void ResetData()
        {
            if (brain == null)
            {
                return;
            }

            BrainParameters param = brain.brainParameters;

            actionMasker = new ActionMasker(param);
            if (param.vectorActionSpaceType == SpaceType.continuous)
            {
                action.vectorActions     = new float[param.vectorActionSize[0]];
                info.storedVectorActions = new float[param.vectorActionSize[0]];
            }
            else
            {
                action.vectorActions     = new float[param.vectorActionSize.Length];
                info.storedVectorActions = new float[param.vectorActionSize.Length];
            }

            if (info.textObservation == null)
            {
                info.textObservation = "";
            }
            action.textActions     = "";
            info.memories          = new List <float>();
            action.memories        = new List <float>();
            info.vectorObservation =
                new List <float>(param.vectorObservationSize);
            info.stackedVectorObservation =
                new List <float>(param.vectorObservationSize
                                 * brain.brainParameters.numStackedVectorObservations);
            info.stackedVectorObservation.AddRange(
                new float[param.vectorObservationSize
                          * param.numStackedVectorObservations]);

            info.visualObservations = new List <Texture2D>();
            info.customObservation  = null;
        }
Пример #6
0
 /// <summary>
 /// Collects the vector observations of the agent.
 /// The agent observation describes the current environment from the
 /// perspective of the agent.
 /// </summary>
 /// <remarks>
 /// An agents observation is any environment information that helps
 /// the Agent achieve its goal. For example, for a fighting Agent, its
 /// observation could include distances to friends or enemies, or the
 /// current level of ammunition at its disposal.
 /// Recall that an Agent may attach vector or visual observations.
 /// Vector observations are added by calling the provided helper methods
 /// on the VectorSensor input:
 ///     - <see cref="AddObservation(int)"/>
 ///     - <see cref="AddObservation(float)"/>
 ///     - <see cref="AddObservation(Vector3)"/>
 ///     - <see cref="AddObservation(Vector2)"/>
 ///     - <see cref="AddObservation(Quaternion)"/>
 ///     - <see cref="AddObservation(bool)"/>
 ///     - <see cref="AddOneHotObservation(int, int)"/>
 /// Depending on your environment, any combination of these helpers can
 /// be used. They just need to be used in the exact same order each time
 /// this method is called and the resulting size of the vector observation
 /// needs to match the vectorObservationSize attribute of the linked Brain.
 /// Visual observations are implicitly added from the cameras attached to
 /// the Agent.
 /// When using Discrete Control, you can prevent the Agent from using a certain
 /// action by masking it. You can call the following method on the ActionMasker
 /// input :
 ///     - <see cref="SetActionMask(int branch, IEnumerable<int> actionIndices)"/>
 ///     - <see cref="SetActionMask(int branch, int actionIndex)"/>
 ///     - <see cref="SetActionMask(IEnumerable<int> actionIndices)"/>
 ///     - <see cref="SetActionMask(int branch, int actionIndex)"/>
 /// The branch input is the index of the action, actionIndices are the indices of the
 /// invalid options for that action.
 /// </remarks>
 public virtual void CollectObservations(VectorSensor sensor, ActionMasker actionMasker)
 {
     CollectObservations(sensor);
 }