Search in sources :

Example 41 with BudgetValue

use of nars.entity.BudgetValue in project opennars by opennars.

the class InternalExperience method beliefReason.

/**
 * used in full internal experience mode only
 */
protected void beliefReason(Sentence belief, Term beliefTerm, Term taskTerm, DerivationContext nal) {
    Memory memory = nal.memory;
    if (Memory.randomNumber.nextDouble() < INTERNAL_EXPERIENCE_RARE_PROBABILITY) {
        // the operators which dont have a innate belief
        // also get a chance to reveal its effects to the system this way
        Operator op = memory.getOperator(nonInnateBeliefOperators[Memory.randomNumber.nextInt(nonInnateBeliefOperators.length)]);
        Product prod = new Product(new Term[] { belief.term });
        if (op != null && prod != null) {
            Term new_term = Inheritance.make(prod, op);
            Sentence sentence = new Sentence(new_term, Symbols.GOAL_MARK, // a naming convension
            new TruthValue(1, Parameters.DEFAULT_JUDGMENT_CONFIDENCE), new Stamp(memory));
            float quality = BudgetFunctions.truthToQuality(sentence.truth);
            BudgetValue budget = new BudgetValue(Parameters.DEFAULT_GOAL_PRIORITY * INTERNAL_EXPERIENCE_PRIORITY_MUL, Parameters.DEFAULT_GOAL_DURABILITY * INTERNAL_EXPERIENCE_DURABILITY_MUL, quality);
            Task newTask = new Task(sentence, budget, true);
            nal.derivedTask(newTask, false, false, false);
        }
    }
    if (beliefTerm instanceof Implication && Memory.randomNumber.nextDouble() <= INTERNAL_EXPERIENCE_PROBABILITY) {
        Implication imp = (Implication) beliefTerm;
        if (imp.getTemporalOrder() == TemporalRules.ORDER_FORWARD) {
            // 1. check if its (&/,term,+i1,...,+in) =/> anticipateTerm form:
            boolean valid = true;
            if (imp.getSubject() instanceof Conjunction) {
                Conjunction conj = (Conjunction) imp.getSubject();
                if (!conj.term[0].equals(taskTerm)) {
                    // the expected needed term is not included
                    valid = false;
                }
                for (int i = 1; i < conj.term.length; i++) {
                    if (!(conj.term[i] instanceof Interval)) {
                        valid = false;
                        break;
                    }
                }
            } else {
                if (!imp.getSubject().equals(taskTerm)) {
                    valid = false;
                }
            }
            if (valid) {
                Operator op = memory.getOperator("^anticipate");
                if (op == null)
                    throw new RuntimeException(this + " requires ^anticipate operator");
                Product args = new Product(new Term[] { imp.getPredicate() });
                Term new_term = Operation.make(args, op);
                Sentence sentence = new Sentence(new_term, Symbols.GOAL_MARK, // a naming convension
                new TruthValue(1, Parameters.DEFAULT_JUDGMENT_CONFIDENCE), new Stamp(memory));
                float quality = BudgetFunctions.truthToQuality(sentence.truth);
                BudgetValue budget = new BudgetValue(Parameters.DEFAULT_GOAL_PRIORITY * INTERNAL_EXPERIENCE_PRIORITY_MUL, Parameters.DEFAULT_GOAL_DURABILITY * INTERNAL_EXPERIENCE_DURABILITY_MUL, quality);
                Task newTask = new Task(sentence, budget, true);
                nal.derivedTask(newTask, false, false, false);
            }
        }
    }
}
Also used : Operator(nars.operator.Operator) BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) Memory(nars.storage.Memory) Product(nars.language.Product) Term(nars.language.Term) Implication(nars.language.Implication) TruthValue(nars.entity.TruthValue) Conjunction(nars.language.Conjunction) Sentence(nars.entity.Sentence) Interval(nars.language.Interval)

Example 42 with BudgetValue

use of nars.entity.BudgetValue in project opennars by opennars.

the class Memory method executedTask.

/**
 * ExecutedTask called in Operator.call
 *
 * @param operation The operation just executed
 */
public void executedTask(final Operation operation, TruthValue truth) {
    Task opTask = operation.getTask();
    // logic.TASK_EXECUTED.commit(opTask.budget.getPriority());
    Stamp stamp = new Stamp(this, Tense.Present);
    Sentence sentence = new Sentence(operation, Symbols.JUDGMENT_MARK, truth, stamp);
    Task task = new Task(sentence, new BudgetValue(Parameters.DEFAULT_FEEDBACK_PRIORITY, Parameters.DEFAULT_FEEDBACK_DURABILITY, truthToQuality(sentence.getTruth())), true);
    task.setElemOfSequenceBuffer(true);
    addNewTask(task, "Executed");
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) Sentence(nars.entity.Sentence)

Example 43 with BudgetValue

use of nars.entity.BudgetValue in project opennars by opennars.

the class BagOperationsTest method makeConcept.

static Concept makeConcept(String name, float priority) {
    BudgetValue budg = new BudgetValue(priority, priority, priority);
    Concept s = new Concept(budg, new Term(name), nar.memory);
    return s;
}
Also used : BudgetValue(nars.entity.BudgetValue) Concept(nars.entity.Concept) Term(nars.language.Term)

Example 44 with BudgetValue

use of nars.entity.BudgetValue in project opennars by opennars.

the class CompositionalRules method IntroVarSameSubjectOrPredicate.

static void IntroVarSameSubjectOrPredicate(final Sentence originalMainSentence, final Sentence subSentence, final Term component, final Term content, final int index, final DerivationContext nal) {
    Term T1 = originalMainSentence.term;
    if (!(T1 instanceof CompoundTerm) || !(content instanceof CompoundTerm)) {
        return;
    }
    CompoundTerm T = (CompoundTerm) T1;
    CompoundTerm T2 = (CompoundTerm) content;
    if ((component instanceof Inheritance && content instanceof Inheritance) || (component instanceof Similarity && content instanceof Similarity)) {
        // CompoundTerm result = T;
        if (component.equals(content)) {
            // wouldnt make sense to create a conjunction here, would contain a statement twice
            return;
        }
        Variable depIndVar1 = new Variable("#depIndVar1");
        Variable depIndVar2 = new Variable("#depIndVar2");
        if (((Statement) component).getPredicate().equals(((Statement) content).getPredicate()) && !(((Statement) component).getPredicate() instanceof Variable)) {
            CompoundTerm zw = (CompoundTerm) T.term[index];
            zw = (CompoundTerm) zw.setComponent(1, depIndVar1, nal.mem());
            T2 = (CompoundTerm) T2.setComponent(1, depIndVar1, nal.mem());
            Conjunction res = (Conjunction) Conjunction.make(zw, T2);
            T = (CompoundTerm) T.setComponent(index, res, nal.mem());
        } else if (((Statement) component).getSubject().equals(((Statement) content).getSubject()) && !(((Statement) component).getSubject() instanceof Variable)) {
            CompoundTerm zw = (CompoundTerm) T.term[index];
            zw = (CompoundTerm) zw.setComponent(0, depIndVar2, nal.mem());
            T2 = (CompoundTerm) T2.setComponent(0, depIndVar2, nal.mem());
            Conjunction res = (Conjunction) Conjunction.make(zw, T2);
            T = (CompoundTerm) T.setComponent(index, res, nal.mem());
        }
        TruthValue truth = induction(originalMainSentence.truth, subSentence.truth);
        BudgetValue budget = BudgetFunctions.compoundForward(truth, T, nal);
        nal.doublePremiseTask(T, truth, budget, false, false);
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) BudgetValue(nars.entity.BudgetValue) Variable(nars.language.Variable) Similarity(nars.language.Similarity) Statement(nars.language.Statement) TruthValue(nars.entity.TruthValue) Inheritance(nars.language.Inheritance) TruthFunctions.reduceConjunction(nars.inference.TruthFunctions.reduceConjunction) Conjunction(nars.language.Conjunction) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 45 with BudgetValue

use of nars.entity.BudgetValue in project opennars by opennars.

the class LocalRules method revision.

/**
 * Belief revision
 * <p>
 * called from Concept.reviseTable and match
 *
 * @param newBelief The new belief in task
 * @param oldBelief The previous belief with the same content
 * @param feedbackToLinks Whether to send feedback to the links
 * @param memory Reference to the memory
 */
public static boolean revision(final Sentence newBelief, final Sentence oldBelief, final boolean feedbackToLinks, final DerivationContext nal) {
    if (newBelief.term == null) {
        return false;
    }
    newBelief.stamp.alreadyAnticipatedNegConfirmation = oldBelief.stamp.alreadyAnticipatedNegConfirmation;
    TruthValue newTruth = newBelief.truth.clone();
    TruthValue oldTruth = oldBelief.truth;
    boolean useNewBeliefTerm = false;
    if (newBelief.getTerm().hasInterval()) {
        Term cterm = replaceIntervals(newBelief.getTerm());
        Concept c = nal.memory.concept(cterm);
        ArrayList<Long> ivalOld = extractIntervals(nal.memory, oldBelief.getTerm());
        if (c.recent_intervals.size() == 0) {
            for (Long l : ivalOld) {
                c.recent_intervals.add((float) l);
            }
        }
        ArrayList<Long> ivalNew = extractIntervals(nal.memory, newBelief.getTerm());
        for (int i = 0; i < ivalNew.size(); i++) {
            // vote as one new entry, turtle style
            float Inbetween = (c.recent_intervals.get(i) + ivalNew.get(i)) / 2.0f;
            // less truth expectation, slower
            float speed = 1.0f / (float) (Parameters.INTERVAL_ADAPT_SPEED * (1.0f - newBelief.getTruth().getExpectation()));
            c.recent_intervals.set(i, c.recent_intervals.get(i) + speed * (Inbetween - c.recent_intervals.get(i)));
        }
        long AbsDiffSumNew = 0;
        for (int i = 0; i < ivalNew.size(); i++) {
            AbsDiffSumNew += Math.abs(ivalNew.get(i) - c.recent_intervals.get(i));
        }
        long AbsDiffSumOld = 0;
        for (int i = 0; i < ivalNew.size(); i++) {
            AbsDiffSumOld += Math.abs(ivalOld.get(i) - c.recent_intervals.get(i));
        }
        long AbsDiffSum = 0;
        for (int i = 0; i < ivalNew.size(); i++) {
            AbsDiffSum += Math.abs(ivalNew.get(i) - ivalOld.get(i));
        }
        // re-project, and it's safe:
        float a = temporalProjection(0, AbsDiffSum, 0);
        // we won't count more confidence than
        // when the second premise would have been shifted
        // to the necessary time in the first place
        // to build the hypothesis newBelief encodes
        newTruth.setConfidence(newTruth.getConfidence() * a);
        useNewBeliefTerm = AbsDiffSumNew < AbsDiffSumOld;
    }
    TruthValue truth = TruthFunctions.revision(newTruth, oldTruth);
    BudgetValue budget = BudgetFunctions.revise(newTruth, oldTruth, truth, feedbackToLinks, nal);
    if (budget.aboveThreshold()) {
        if (nal.doublePremiseTaskRevised(useNewBeliefTerm ? newBelief.term : oldBelief.term, truth, budget)) {
            // nal.mem().logic.BELIEF_REVISION.commit();
            return true;
        }
    }
    return false;
}
Also used : Concept(nars.entity.Concept) BudgetValue(nars.entity.BudgetValue) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Aggregations

BudgetValue (nars.entity.BudgetValue)66 TruthValue (nars.entity.TruthValue)52 Term (nars.language.Term)48 Sentence (nars.entity.Sentence)39 Task (nars.entity.Task)36 CompoundTerm (nars.language.CompoundTerm)34 Stamp (nars.entity.Stamp)22 Statement (nars.language.Statement)21 Conjunction (nars.language.Conjunction)18 Inheritance (nars.language.Inheritance)11 Interval (nars.language.Interval)9 Implication (nars.language.Implication)8 Concept (nars.entity.Concept)7 Product (nars.language.Product)7 Variable (nars.language.Variable)6 Operation (nars.operator.Operation)5 Memory (nars.storage.Memory)5 HashMap (java.util.HashMap)4 TruthFunctions.reduceConjunction (nars.inference.TruthFunctions.reduceConjunction)4 Equivalence (nars.language.Equivalence)4