Ejemplo n.º 1
0
 /// <summary>
 /// Updates the Model for the agent. Any model currently assigned to the
 /// agent will be replaced with the provided one. If the arguments are
 /// identical to the current parameters of the agent, the model will
 /// remain unchanged.
 /// </summary>
 /// <param name="behaviorName"> The identifier of the behavior. This
 /// will categorize the agent when training.
 /// </param>
 /// <param name="model"> The model to use for inference.</param>
 /// <param name = "inferenceDevice"> Define on what device the model
 /// will be run.</param>
 public void GiveModel(
     string behaviorName,
     NNModel model,
     InferenceDevice inferenceDevice = InferenceDevice.CPU)
 {
     m_PolicyFactory.GiveModel(behaviorName, model, inferenceDevice);
     m_Brain?.Dispose();
     m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the agent. Can be safely called multiple times.
        /// </summary>
        public void LazyInitialize()
        {
            if (m_Initialized)
            {
                return;
            }
            m_Initialized = true;

            // Grab the "static" properties for the Agent.
            m_EpisodeId     = EpisodeIdCounter.GetEpisodeId();
            m_PolicyFactory = GetComponent <BehaviorParameters>();

            m_Info   = new AgentInfo();
            m_Action = new AgentAction();
            sensors  = new List <ISensor>();

            Academy.Instance.AgentIncrementStep += AgentIncrementStep;
            Academy.Instance.AgentSendState     += SendInfo;
            Academy.Instance.DecideAction       += DecideAction;
            Academy.Instance.AgentAct           += AgentStep;
            Academy.Instance.AgentForceReset    += _AgentReset;
            m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic);
            ResetData();
            Initialize();
            InitializeSensors();

            // The first time the Academy resets, all Agents in the scene will be
            // forced to reset through the <see cref="AgentForceReset"/> event.
            // To avoid the Agent resetting twice, the Agents will not begin their
            // episode when initializing until after the Academy had its first reset.
            if (Academy.Instance.TotalStepCount != 0)
            {
                OnEpisodeBegin();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the agent. Can be safely called multiple times.
        /// </summary>
        public void LazyInitialize()
        {
            if (m_Initialized)
            {
                return;
            }
            m_Initialized = true;

            // Grab the "static" properties for the Agent.
            m_EpisodeId     = EpisodeIdCounter.GetEpisodeId();
            m_PolicyFactory = GetComponent <BehaviorParameters>();

            m_Info   = new AgentInfo();
            m_Action = new AgentAction();
            sensors  = new List <ISensor>();

            Academy.Instance.AgentIncrementStep += AgentIncrementStep;
            Academy.Instance.AgentSendState     += SendInfo;
            Academy.Instance.DecideAction       += DecideAction;
            Academy.Instance.AgentAct           += AgentStep;
            Academy.Instance.AgentForceReset    += _AgentReset;
            m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic);
            ResetData();
            InitializeAgent();
            InitializeSensors();
        }
Ejemplo n.º 4
0
        /// Helper method for the <see cref="OnEnable"/> event, created to
        /// facilitate testing.
        void OnEnableHelper(Academy academy)
        {
            m_Info    = new AgentInfo();
            m_Action  = new AgentAction();
            m_Sensors = new List <ISensor>();

            if (academy == null)
            {
                throw new UnityAgentsException(
                          "No Academy Component could be found in the scene.");
            }

            academy.AgentSetStatus        += SetStatus;
            academy.AgentResetIfDone      += ResetIfDone;
            academy.AgentSendState        += SendInfo;
            academy.DecideAction          += DecideAction;
            academy.AgentAct              += AgentStep;
            academy.AgentForceReset       += _AgentReset;
            academy.AgentSetDoneFlagFalse += NotDone;
            m_PolicyFactory = GetComponent <BehaviorParameters>();
            m_Brain         = m_PolicyFactory.GeneratePolicy(Heuristic);
            ResetData();
            InitializeAgent();
            InitializeSensors();
        }
Ejemplo n.º 5
0
 internal void ReloadPolicy()
 {
     if (!m_Initialized)
     {
         // If we haven't initialized yet, no need to make any changes now; they'll
         // happen in LazyInitialize later.
         return;
     }
     m_Brain?.Dispose();
     m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic);
 }
Ejemplo n.º 6
0
        /// Helper method for the <see cref="OnEnable"/> event, created to
        /// facilitate testing.
        void OnEnableHelper()
        {
            m_Info   = new AgentInfo();
            m_Action = new AgentAction();
            sensors  = new List <ISensor>();

            Academy.Instance.AgentSendState  += SendInfo;
            Academy.Instance.DecideAction    += DecideAction;
            Academy.Instance.AgentAct        += AgentStep;
            Academy.Instance.AgentForceReset += _AgentReset;
            m_PolicyFactory = GetComponent <BehaviorParameters>();
            m_Brain         = m_PolicyFactory.GeneratePolicy(Heuristic);
            ResetData();
            InitializeAgent();
            InitializeSensors();
        }