Search in sources :

Example 21 with Concept

use of nars.concept.Concept in project narchy by automenta.

the class Anoncepts method leak.

@Override
protected float leak(Task task) {
    Term taskTerm = task.term().root();
    Term a = taskTerm.anon();
    if (// ?<- why would this, if it does
    a == null)
        return 0;
    // HACK
    Concept c = nar.concept(a);
    if (c == null) {
        nar.concepts.set(a, c = new AnonConcept(a, nar));
    }
    float pri = task.priElseZero();
    float cr = conceptActivationRate.floatValue();
    c = nar.activate(c, pri * cr);
    if (c == null)
        // ???
        return 0;
    short cid = out.id;
    // c.tasklinks().putAsync(new CauseLink.CauseLinkUntilDeleted<>(task, pri * taskLinkActivationRate.floatValue(), cid));
    c.termlinks().putAsync(new CauseLink.PriCauseLink<>(taskTerm, pri * cr, cid));
    return 1;
}
Also used : NodeConcept(nars.concept.NodeConcept) Concept(nars.concept.Concept) CauseLink(nars.link.CauseLink) Term(nars.term.Term)

Example 22 with Concept

use of nars.concept.Concept in project narchy by automenta.

the class Implier method run.

@Override
protected void run(NAR nar, long dt) {
    search(nar);
    int implCount = impl.edgeCount();
    if (implCount == 0)
        return;
    // impl.edges.forEach
    dur = nar.dur();
    now = nar.time();
    then = TIMELESS;
    beliefTruth.clear();
    goalTruth.clear();
    int dtDither = nar.dtDitherCycles();
    for (float relativeTargetDur : relativeTargetDurs) {
        long nextThen = Tense.dither(now + Math.round(relativeTargetDur * dur), dtDither);
        if (then == nextThen)
            // same time as previous iteration, don't repeat
            continue;
        then = nextThen;
        impl.each((subj, pred, implTerm) -> {
            Concept implConcept = nar.concept(implTerm);
            if (implConcept != null)
                implConcept.beliefs().forEachTask(this::imply);
        });
    }
    if (!beliefTruth.isEmpty() || !goalTruth.isEmpty()) {
        commit();
    }
}
Also used : Concept(nars.concept.Concept)

Example 23 with Concept

use of nars.concept.Concept in project narchy by automenta.

the class NAL6MultistepTest method testBurglarEarthquake1.

/**
 * https://dtai.cs.kuleuven.be/problog/tutorial/basic/02_bayes.html
 */
@Test
public void testBurglarEarthquake1() throws Narsese.NarseseException {
    // 0.7::burglary.
    // 0.2::earthquake.
    // 0.9::p_alarm1.
    // 0.8::p_alarm2.
    // 0.1::p_alarm3.
    // 
    // alarm :- burglary, earthquake, p_alarm1.
    // alarm :- burglary, \+earthquake, p_alarm2.
    // alarm :- \+burglary, earthquake, p_alarm3.
    // 
    // evidence(alarm,true).
    // 
    // query(burglary).
    // query(earthquake).
    NAR n = NARS.tmp();
    // d.log();
    n.input("(burglary). %0.7;0.9%", "(earthquake). %0.2;0.9%", "(p_alarm1). %0.9;0.9%", "(p_alarm2). %0.8;0.9%", "(p_alarm3). %0.1;0.9%", "((&&, (burglary), (earthquake), (p_alarm1)) ==> (alarm)). %1.0;0.95%", "((&&, (burglary), (--,(earthquake)), (p_alarm2)) ==> (alarm)). %1.0;0.95%", "((&&, (--,(burglary)), (earthquake), (p_alarm3)) ==> (alarm)). %1.0;0.95%", "(alarm).", "(burglary)?", "(earthquake)?");
    Concept burglary = null, earthquake = null;
    for (int i = 0; i < 5; i++) {
        // long now = d.time();
        n.run(100);
        burglary = n.conceptualize("(burglary)");
        // burglary.print();  earthquake.print();
        earthquake = n.conceptualize("(earthquake)");
    // System.out.println("burglary=" + burglary.belief(Tense.ETERNAL,0, nar) + "\tearthquake=" + earthquake.belief(Tense.ETERNAL,0, nar));
    }
    n.stats(System.out);
    // result from Probcog:  earthquake=23%, burglary=99%
    Truth burgTruth = n.beliefTruth(burglary, Tense.ETERNAL);
    assertNotNull(burgTruth);
    assertEquals(0.99f, burgTruth.freq(), 0.4f);
    assertEquals(0.31f, n.beliefTruth(earthquake, Tense.ETERNAL).freq(), 0.2f);
}
Also used : TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 24 with Concept

use of nars.concept.Concept in project narchy by automenta.

the class RevisionTest method testRevision2TemporalImpl.

@Test
public void testRevision2TemporalImpl() throws Narsese.NarseseException {
    NAR n = newNAR(3).input("(x ==> y). :|: %1.0;0.9%", "(x ==> y). :|: %0.0;0.9%");
    n.run(1);
    Concept c = n.concept($.$("(x ==> y)"));
    assertEquals(2, c.beliefs().size());
    Truth t = n.belief($.$("(x ==> y)"), 0).truth();
    assertEquals(0.5f, t.freq(), 0.01f);
    assertEquals(0.947f, t.conf(), 0.01f);
}
Also used : TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 25 with Concept

use of nars.concept.Concept in project narchy by automenta.

the class TemporalTermTest method testCommutiveTemporalityConcepts.

@Test
public void testCommutiveTemporalityConcepts() throws Narsese.NarseseException {
    NAR n = NARS.shell();
    n.log();
    n.input("(goto(#1) &&+5 ((SELF,#1)-->at)).");
    // n.step();
    n.input("(goto(#1) &&-5 ((SELF,#1)-->at)).");
    // n.step();
    n.input("(goto(#1) &&+0 ((SELF,#1)-->at)).");
    // n.step();
    n.input("(((SELF,#1)-->at) &&-3 goto(#1)).");
    // n.step();
    // n.input("(((SELF,#1)-->at) &&+3 goto(#1)).");
    // n.step();
    // n.input("(((SELF,#1)-->at) &&+0 goto(#1)).");
    n.run(2);
    TaskConcept a = (TaskConcept) n.conceptualize("(((SELF,#1)-->at) && goto(#1)).");
    Concept a0 = n.conceptualize("(goto(#1) && ((SELF,#1)-->at)).");
    assertNotNull(a);
    assertSame(a, a0);
    a.beliefs().print();
    assertTrue(a.beliefs().size() >= 4);
}
Also used : TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) TaskConcept(nars.concept.TaskConcept) Test(org.junit.jupiter.api.Test)

Aggregations

Concept (nars.concept.Concept)47 TaskConcept (nars.concept.TaskConcept)19 Term (nars.term.Term)19 Test (org.junit.jupiter.api.Test)15 Nullable (org.jetbrains.annotations.Nullable)11 Truth (nars.truth.Truth)9 NAR (nars.NAR)6 Termed (nars.term.Termed)6 FasterList (jcog.list.FasterList)4 PermanentConcept (nars.concept.PermanentConcept)4 BeliefTable (nars.table.BeliefTable)4 TestNAR (nars.test.TestNAR)4 Util (jcog.Util)3 PriReference (jcog.pri.PriReference)3 GL2 (com.jogamp.opengl.GL2)2 java.io (java.io)2 java.util (java.util)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Op (nars.Op)2 CauseLink (nars.link.CauseLink)2