コード例 #1
0
ファイル: LocalRules.cs プロジェクト: chargen/AGI-X0
        // does the emotion part of the trySolution function
        private static void trySolution_emotion(ClassicalSentence belief, ClassicalTask task, DerivationContext ctx)
        {
            ClassicalSentence problem = task.sentence;
            Memory            memory  = ctx.memory;

            ClassicalSentence oldBest = task.bestSolution;

            if (oldBest != null)
            {
                TemporalRules.EnumRateByConfidence rateByConfidence =
                    oldBest.term == belief.term ? TemporalRules.EnumRateByConfidence.YES : TemporalRules.EnumRateByConfidence.NO;

                float newQ = TemporalRules.solutionQuality(rateByConfidence, task, belief, memory, ctx.compoundAndTermContext);
                float oldQ = TemporalRules.solutionQuality(rateByConfidence, task, oldBest, memory, ctx.compoundAndTermContext);
                if (oldQ >= newQ)
                {
                    if (problem.isGoal)
                    {
                        memory.emotion.adjustHappy(oldQ, task.budget.priority, ctx);
                    }
                    //System.out.println("Unsolved: Solution of lesser quality");
                    //java memory.emit(Unsolved.class, task, belief, "Lower quality");
                    return;
                }
            }
        }
コード例 #2
0
ファイル: TemporalRules.cs プロジェクト: chargen/AGI-X0
        // TODO< rename to evaluateQualityOfBeliefAsASolutionToProblemAndReward and refactor into functions >
        // https://github.com/opennars/opennars/blob/master/nars_core/nars/inference/TemporalRules.java#L537
        /* ----- Functions used both in direct and indirect processing of tasks ----- */

        /**
         * Evaluate the quality of a belief as a solution to a problem, then reward
         * the belief and de-prioritize the problem
         *
         * \param problem The problem (question or goal) to be solved
         * \param solution The belief as solution
         * \param task The task to be immediately processed, or null for continued process
         * \return The budget for the new task which is the belief activated, if
         * necessary
         */
        public static ClassicalBudgetValue solutionEval(
            ClassicalTask problem,
            ClassicalSentence solution,
            ClassicalTask task,
            DerivationContext ctx
            )
        {
            ClassicalBudgetValue budget = null;

            bool feedbackToLinks = false;

            if (task == null)
            {
                task            = ctx.currentTask;
                feedbackToLinks = true;
            }
            bool taskSentenceIsjudgment           = task.sentence.isJudgment;
            EnumRateByConfidence rateByConfidence = problem.sentence.term.hasVarQuery() ? EnumRateByConfidence.YES : EnumRateByConfidence.NO; // here its whether its a what or where question for budget adjustment
            float quality = TemporalRules.solutionQuality(rateByConfidence, problem, solution, ctx.memory, ctx.compoundAndTermContext);

            if (problem.sentence.isGoal)
            {
                ctx.memory.emotion.adjustHappy(quality, task.budget.priority, ctx);
            }

            if (taskSentenceIsjudgment)
            {
                task.budget.incPriority(quality);
            }
            else
            {
                float taskPriority = task.budget.priority; // +goal satisfication is a matter of degree - https://groups.google.com/forum/#!topic/open-nars/ZfCM416Dx1M
                budget = new ClassicalBudgetValue(UtilityFunctions.or(taskPriority, quality), task.budget.durability, BudgetFunctions.truthToQuality(solution.truth));
                task.budget.priority = Math.Min(1 - quality, taskPriority);
            }

            // TODO< implement links >

            /* LINKS commented because links are not implemented
             * if (feedbackToLinks) {
             *  TaskLink tLink = ctx.currentTaskLink;
             *  tLink.setPriority(Math.Min(1 - quality, tLink.getPriority()));
             *  TermLink bLink = ctx.currentBeliefLink;
             *  bLink.incPriority(quality);
             * }*/
            return(budget);
        }
コード例 #3
0
ファイル: LocalRules.cs プロジェクト: chargen/AGI-X0
        /**
         * Check if a Sentence provide a better answer to a Question or Goal
         *
         * \param belief The proposed answer
         * \param task The task to be processed
         */
        public static bool trySolution(ClassicalSentence belief, ClassicalTask task, DerivationContext ctx, bool report, Memory memory)
        {
            trySolution_emotion(belief, task, ctx);

            task.setBestSolution(memory, belief);

            //memory.logic.SOLUTION_BEST.commit(task.getPriority());

            ClassicalBudgetValue budget = TemporalRules.solutionEval(task, belief, task, ctx);

            if (budget == null || !budget.isAboveThreshold)
            {
                //memory.emit(Unsolved.class, task, belief, "Insufficient budget");
                return(false);
            }
            // Solution was Activated

            // report
            if (task.sentence.isQuestion || task.sentence.isQuest)
            {
                if (task.isInput && report)  //only show input tasks as solutions
                //memory.emit(Answer.class, task, belief);
                {
                }
                else
                {
                    //memory.emit(Output.class, task, belief);   //solution to quests and questions can be always showed
                }
            }
            else
            {
                //memory.emit(Output.class, task, belief);   //goal things only show silence related
            }


            /*memory.output(task);
             *
             * //only questions and quests get here because else output is spammed
             * if(task.sentence.isQuestion() || task.sentence.isQuest()) {
             *  memory.emit(Solved.class, task, belief);
             * } else {
             *  memory.emit(Output.class, task, belief);
             * }*/

            ctx.addTask(ctx.currentTask, budget, belief, task.getParentBelief());
            return(true);
        }