Search in sources :

Example 41 with Concept

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

the class LinkageTest method ProperlyLinkedIndirectlyTest.

// interlinked with an intermediate concept, this is needed in order to select one as task and the other as belief
public void ProperlyLinkedIndirectlyTest(@NotNull String spremise1, byte punc, @NotNull String spremise2) throws Exception {
    test.requireConditions = false;
    NAR nar = test.nar;
    // nar.log();
    Termed premise1 = $.$(spremise1);
    assertEquals($.$(spremise1), premise1, "reparsed");
    assertNotNull(premise1);
    assertEquals($.$(spremise1), premise1);
    Termed premise2 = $.$(spremise2);
    assertEquals($.$(spremise2), premise2, "reparsed");
    assertNotNull(premise2);
    assertEquals($.$(spremise2), premise2);
    String t1 = getTask(punc, premise1);
    String t2 = getTask(punc, premise2);
    nar.input(t1, t2).run(runCycles);
    // List<String> fails = new ArrayList();
    @Nullable Concept p1 = nar.concept(premise1);
    assertNotNull(p1.state());
    // p1.print(); System.out.println("------------------------");
    Concept p2 = nar.concept(premise2);
    assertNotNull(p2);
    assertNotNull(p2.state());
    // c2.print(); System.out.println("------------------------");
    AdjGraph<Term, Float> g = TermGraph.termlink(nar);
    boolean p12 = linksIndirectly(p1, p2, nar);
    assertTrue(p12, why(nar, premise1, premise2));
    boolean p21 = linksIndirectly(p2, p1, nar);
    assertTrue(p21, why(nar, premise2, premise1));
    System.err.println(premise1 + " not linked with " + premise2);
    int numNodes = g.nodeCount();
    assertTrue(numNodes > 0);
    assertTrue(g.edgeCount() > 0, g.toString());
// for (Term x : g.nodes()) {
// assertEquals(x + " not reachable by all other nodes", numNodes, Graphs.reachableNodes(g.asGraph(), x).size());
// }
// //g.print(System.out);
// //System.out.println(g.isConnected() + " " + g.vertexSet().size() + " " + g.edgeSet().size());
// if (!g.isConnected()) {
// //        if (!g.isStronglyConnected()) {
// //            StrongConnectivityInspector ci =
// ConnectivityInspector ci = new ConnectivityInspector(g);
// //                    new StrongConnectivityInspector(g);
// 
// System.out.println("premises: " + premise1 + " and " + premise2 + " termlink subgraph connectivity:");
// 
// ci
// .connectedSets()
// //.stronglyConnectedSubgraphs()
// .forEach( s -> System.out.println("\t" + s));
// 
// nar.forEachConceptActive(x -> x.get().print());
// 
// }
// assertTrue(g.isConnected());
}
Also used : Termed(nars.term.Termed) Concept(nars.concept.Concept) Term(nars.term.Term) TestNAR(nars.test.TestNAR) NAR(nars.NAR) Nullable(org.jetbrains.annotations.Nullable)

Example 42 with Concept

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

the class DynamicTruthBeliefTableTest method testDynamicIntersection.

@Test
public void testDynamicIntersection() throws Narsese.NarseseException {
    NAR n = NARS.tmp();
    n.believe("a:x", 1f, 0.9f);
    n.believe("a:y", 1f, 0.9f);
    n.believe("a:(--,y)", 0f, 0.9f);
    n.believe("a:z", 0f, 0.9f);
    n.believe("a:(--,z)", 1f, 0.9f);
    n.believe("x:b", 1f, 0.9f);
    n.believe("y:b", 1f, 0.9f);
    n.believe("z:b", 0f, 0.9f);
    n.run(2);
    for (long now : new long[] { 0, n.time(), /* 2 */
    ETERNAL }) {
        assertTrue(n.conceptualize($("((x|y)-->a)")).beliefs() instanceof DynamicTruthBeliefTable);
        assertEquals($.t(1f, 0.81f), n.beliefTruth("((x|y)-->a)", now));
        assertEquals($.t(0f, 0.90f), n.beliefTruth(n.conceptualize($("((x|z)-->a)")), now));
        assertEquals($.t(1f, 0.90f), n.beliefTruth(n.conceptualize($("((x&z)-->a)")), now));
        assertEquals($.t(1f, 0.90f), n.beliefTruth(n.conceptualize($("(b --> (x|y))")), now));
        assertEquals($.t(1f, 0.90f), n.beliefTruth(n.conceptualize($("(b --> (x|z))")), now));
        assertEquals($.t(0f, 0.90f), n.beliefTruth(n.conceptualize($("(b --> (x&z))")), now));
        Concept xIntNegY = n.conceptualize($("((x|--y)-->a)"));
        assertTrue(xIntNegY.beliefs() instanceof DynamicTruthBeliefTable);
        assertTrue(xIntNegY.goals() instanceof DynamicTruthBeliefTable);
        assertEquals($.t(0f, 0.90f), n.beliefTruth(xIntNegY, now), now + " " + xIntNegY);
        assertEquals($.t(1f, 0.81f), n.beliefTruth(n.conceptualize($("((x|--z)-->a)")), now));
    }
}
Also used : TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) Test(org.junit.jupiter.api.Test)

Example 43 with Concept

use of nars.concept.Concept 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 44 with Concept

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

the class DynamicTruthBeliefTableTest method testDynamicIntVectorRange.

@Test
public void testDynamicIntVectorRange() throws Narsese.NarseseException {
    NAR n = NARS.tmp();
    n.believe("x(1,1)", 1f, 0.9f);
    n.believe("x(1,2)", 0.5f, 0.9f);
    n.believe("x(1,3)", 0f, 0.9f);
    n.run(1);
    Term t12 = $.inh($.p(Int.the(1), Int.range(1, 2)), $.the("x"));
    assertEquals("x(1,1..2)", t12.toString());
    Concept x12 = n.conceptualize(t12);
    assertTrue(x12.beliefs() instanceof DynamicTruthBeliefTable);
    Concept x23 = n.conceptualize($.inh($.p(Int.the(1), Int.range(2, 3)), $.the("x")));
    Concept x123 = n.conceptualize($.inh($.p(Int.the(1), Int.range(1, 3)), $.the("x")));
    assertEquals("%.50;.81%", n.beliefTruth(x12, ETERNAL).toString());
    assertEquals("%0.0;.90%", n.beliefTruth(x23, ETERNAL).toString());
    assertEquals("%0.0;.90%", n.beliefTruth(x123, ETERNAL).toString());
}
Also used : TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) Term(nars.term.Term) Test(org.junit.jupiter.api.Test)

Example 45 with Concept

use of nars.concept.Concept 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)

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