Ejemplo n.º 1
0
        /// <summary>
        /// 生成可以测试的动作计划集:从动作记忆中找到的行动计划,加上新补充的一些
        /// </summary>
        /// <param name="plans">从动作记忆中找到的行动计划</param>
        /// <param name="time"></param>
        /// <returns></returns>
        private List <ActionPlan> checkActionPlansFull(List <ObservationHistory.ActionRecord> actionRecords, int time)
        {
            List <List <double> > actionSets = CreateTestActionSet(Session.instinctActionHandler(net, time));

            ActionPlan[] r = new ActionPlan[actionSets.Count];
            for (int i = 0; i < actionSets.Count; i++)
            {
                ActionPlan plan      = null;
                String     judgeType = ActionPlan.JUDGE_INFERENCE;
                if (i == 0)
                {
                    judgeType = ActionPlan.JUDGE_INSTINCT;
                }
                else if (actionSets[i][0] == 0.5)
                {
                    judgeType = ActionPlan.JUDGE_MAINTAIN;
                }

                ObservationHistory.ActionRecord record = actionRecords.FirstOrDefault(p => p.actions[0] == actionSets[i][0]);
                if (record == null)
                {
                    plan = ActionPlan.CreateActionPlan(net, actionSets[i], time, judgeType, "");
                }
                else
                {
                    plan            = ActionPlan.CreateActionPlan(net, record.actions, time, judgeType, "");
                    plan.evaulation = record.evaluation;
                }
                r[i] = plan;
            }
            return(r.ToList());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 对当前行为进行推理,预测其未来评估
        /// </summary>
        /// <returns></returns>
        private double forcastActionPlan()
        {
            if (this.net.actionPlanChain.Length <= 0)
            {
                return(double.NaN);
            }
            //寻找当前场景,如果继续维持当前行为,是否会导致负评估
            //由于漫游空间大,碰找到的几率不大
            List <ObservationHistory.ActionRecord> actionRecords = this.net.actionMemory.FindMatchActionPlans();

            if (actionRecords != null && actionRecords.Count > 0)
            {
                ObservationHistory.ActionRecord record = actionRecords.FirstOrDefault(r => r.actions[0] == 0.5);
                if (record != null)
                {
                    return(record.evaluation);
                }
            }

            //执行推理操作
            List <Vector> observations = net.GetReceoptorValues();

            observations = net.ReplaceWithAction(observations, ActionPlan.MaintainAction);
            return(forcastActionPlan(observations));
        }
Ejemplo n.º 3
0
        private double forcastActionPlan(List <Vector> observation)
        {
            int maxinferencecount = Session.GetConfiguration().evaluation.policy.init_plan_depth;

            for (int n = 1; n <= maxinferencecount; n++)
            {
                List <Vector> nextObservation = net.forward_inference(observation);
                if (nextObservation == null)
                {
                    break;
                }

                List <ObservationHistory.ActionRecord> actionRecords = this.net.actionMemory.FindMatchActionPlans(nextObservation);

                if (actionRecords != null && actionRecords.Count > 0)
                {
                    ObservationHistory.ActionRecord record = actionRecords.FirstOrDefault(r => r.actions[0] == 0.5);
                    if (record != null)
                    {
                        return(record.evaluation > 0 ? n + record.evaluation : -1 * n + record.evaluation);
                    }
                }
                observation = nextObservation;
                net.ReplaceMaintainAction(observation);
            }

            return(double.NaN);
        }