Search in sources :

Example 56 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class Signal method set.

public Task set(Concept c, @Nullable Truth nextTruth, LongSupplier stamper, long now, int dur, NAR nar) {
    @Nullable Truth tt = // nextTruth;
    nextTruth != null ? nextTruth.dither(nar) : null;
    final boolean[] keep = { false };
    Task cur = current.updateAndGet((last) -> {
        if (last == null && nextTruth == null)
            return null;
        TruthletTask next;
        int gapFillTolerance = dur * 2;
        if (tt == null) {
            // no signal
            next = null;
        } else {
            if (last == null || last.isDeleted() || ((!tt.equals(last.truth(last.end()), nar) || (now - last.end() > gapFillTolerance)) || (Param.SIGNAL_LATCH_TIME_MAX != Integer.MAX_VALUE && now - last.start() >= dur * Param.SIGNAL_LATCH_TIME_MAX))) {
                long beforeNow = (last != null && (now - last.end()) < gapFillTolerance) ? last.end() : now;
                // TODO move the task construction out of this critical update section?
                next = taskStart(c, last, tt, beforeNow, now + lookAheadDurs * dur, stamper.getAsLong(), dur);
            } else {
                // nothing, keep as-is
                next = last;
            }
        }
        if (last == next) {
            if (last != null) {
                last.pri(pri.asFloat());
                last.updateEnd(c, now + lookAheadDurs * dur);
                keep[0] = true;
            }
            // dont re-input the task, just stretch it where it is in the temporal belief table
            return last;
        } else {
            // new or null input; stretch will be assigned on first insert to the belief table (if this happens)
            return next;
        }
    // } finally {
    // busy.set(false);
    // }
    });
    return keep[0] ? null : cur;
}
Also used : SignalTask(nars.task.signal.SignalTask) Task(nars.Task) TruthletTask(nars.task.signal.TruthletTask) TruthletTask(nars.task.signal.TruthletTask) Nullable(org.jetbrains.annotations.Nullable) Truth(nars.truth.Truth)

Example 57 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class DynamicTruthBeliefTableTest method testDynamicConjunction3.

@Test
public void testDynamicConjunction3() throws Narsese.NarseseException {
    NAR n = NARS.tmp();
    n.believe("a:x", 1f, 0.9f);
    n.believe("a:y", 1f, 0.9f);
    n.believe("a:z", 1f, 0.9f);
    n.run(1);
    TaskConcept cc = (TaskConcept) n.conceptualize($("(&&, a:x, a:y, a:z)"));
    Truth now = n.beliefTruth(cc, n.time());
    assertNotNull(now);
    assertTrue($.t(1f, 0.73f).equals(now, 0.1f), now + " truth at " + n.time());
    // the truth values were provided despite the belief tables being empty:
    // test unknown:
    {
        TaskConcept ccn = (TaskConcept) n.conceptualize($("(&&, a:x, a:w)"));
        Truth nown = n.beliefTruth(ccn, n.time());
        assertNull(nown);
    }
    // test negation:
    Concept ccn = n.conceptualize($("(&&, a:x, (--, a:y), a:z)"));
    {
        Task t = n.belief(ccn.term());
        assertNotNull(t);
        // the critical component
        assertEquals($("a:y"), t.term());
        assertEquals(1f, t.freq());
    }
    assertTrue(ccn instanceof TaskConcept);
    Truth nown = n.beliefTruth(ccn, n.time());
    assertEquals("%0.0;.90%", nown.toString());
    n.clear();
    // test change after a component's revision to negate the input freq
    n.believe("a:y", 0, 0.95f);
    n.run(1);
    n.concept("a:y").print();
    Task ay = n.belief($$("a:y"));
    assertTrue(ay.freq() < 0.5f);
    Task bb = n.belief(n.conceptualize($("(&&, a:x, a:y, a:z)")), n.time());
    Truth now2 = bb.truth();
    assertTrue(now2.freq() < 0.4f);
}
Also used : TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) TaskConcept(nars.concept.TaskConcept) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 58 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class DynamicTruthBeliefTableTest method testDynamicConjunctionEternalOverride.

@Test
public void testDynamicConjunctionEternalOverride() throws Narsese.NarseseException {
    NAR n = NARS.shell().believe($$("a:x"), 0).believe($$("a:y"), 0);
    long now = n.time();
    // truth only
    assertEquals($.t(1f, 0.81f), n.beliefTruth($("(a:x && a:y)"), now));
    // contradict
    n.believe("--(a:x && a:y)");
    n.concept("(a:x && a:y)").beliefs().print();
    Truth tNow = n.beliefTruth($("(a:x && a:y)"), now);
    assertTrue($.t(0.32f, 0.93f).equals(tNow, n));
    Truth tAfter = n.beliefTruth($("(a:x && a:y)"), now + 2);
    assertTrue($.t(0.11f, 0.91f).equals(tAfter, n));
    Truth tLater = n.beliefTruth($("(a:x && a:y)"), now + 5);
    // more certainly negative because the eternal will override
    assertTrue($.t(0.05f, 0.9f).equals(tLater, n));
}
Also used : Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 59 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class AtomicExec method update.

public void update(NAR n) {
    // if (!busy.compareAndSet(false, true))
    // return; //in-progress
    // probe all active concepts.
    // remove any below desire threshold
    // execute any above desire-belief threshold
    // if no active remain, disable update service
    long[] focus = n.timeFocus();
    // List<Task> evoke = $.newArrayList(0);
    float exeThresh = this.exeThresh.floatValue();
    List<Term> dispatch = new FasterList(active.size());
    active.forEach(x -> {
        Term xx = x.get();
        Concept c = n.concept(xx);
        if (c == null) {
            // concept disappeared
            x.delete();
            return;
        }
        Truth goalTruth = c.goals().truth(focus, n);
        if (goalTruth == null || goalTruth.expectation() < exeThresh) {
            x.delete();
            // undesired
            return;
        }
        Truth beliefTruth = c.beliefs().truth(focus, n);
        /* assume false with no evidence */
        if (beliefTruth != null && beliefTruth.expectation() > exeThresh) {
            // satisfied
            return;
        }
        logger.info("{} EVOKE (b={},g={}) {}", n.time(), beliefTruth, goalTruth, xx);
        dispatch.add(xx);
        x.delete();
    // MetaGoal.learn(MetaGoal.Action, goal.cause(), g, n);
    });
    dispatch.forEach(tt -> {
        exe.accept(tt, n);
    });
    active.commit();
    if (active.isEmpty()) {
        disable();
    }
}
Also used : Concept(nars.concept.Concept) FasterList(jcog.list.FasterList) Term(nars.term.Term) Truth(nars.truth.Truth)

Example 60 with Truth

use of nars.truth.Truth in project narchy by automenta.

the class TaskCondition method truthMatches.

private boolean truthMatches(Truthed task) {
    Truth tt = task.truth();
    if ((punc == Op.BELIEF) || (punc == Op.GOAL)) {
        float co = tt.conf();
        if ((co > confMax) || (co < confMin))
            return false;
        float fr = tt.freq();
        return (fr <= freqMax && fr >= freqMin);
    } else {
        return tt == null;
    }
}
Also used : Truth(nars.truth.Truth)

Aggregations

Truth (nars.truth.Truth)65 Term (nars.term.Term)31 Test (org.junit.jupiter.api.Test)22 Nullable (org.jetbrains.annotations.Nullable)20 NAR (nars.NAR)18 Task (nars.Task)14 BeliefTable (nars.table.BeliefTable)13 Concept (nars.concept.Concept)9 NALTask (nars.task.NALTask)9 TaskConcept (nars.concept.TaskConcept)7 PreciseTruth (nars.truth.PreciseTruth)7 NotNull (org.jetbrains.annotations.NotNull)7 FasterList (jcog.list.FasterList)6 ITask (nars.task.ITask)6 Tense (nars.time.Tense)6 Util (jcog.Util)5 BELIEF (nars.Op.BELIEF)5 Consumer (java.util.function.Consumer)4 Predicate (java.util.function.Predicate)4 Param (nars.Param)4