// 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; } } }
// 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); }