Search in sources :

Example 36 with NAR

use of nars.NAR in project narchy by automenta.

the class TemporalInductionTest method testQuestionProjection.

@Test
public void testQuestionProjection() throws Narsese.NarseseException {
    NAR n = NARS.tmp();
    n.log();
    n.input("a:b. :|:");
    // n.frame();
    n.input("a:b? :/:");
    n.run(5);
    n.input("a:b? :/:");
    n.run(30);
    n.input("a:b? :/:");
    n.run(250);
    n.input("a:b? :/:");
    n.run(1);
// n.forEachConcept(Concept::print);
// Concept c = n.concept("a:b");
// assertEquals("(b-->a). 5+0 %.50;.95%", c.getBeliefs().top().toStringWithoutBudget());
}
Also used : TestNAR(nars.test.TestNAR) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 37 with NAR

use of nars.NAR in project narchy by automenta.

the class TemporalInductionTest method testTemporalRevision.

@Test
public void testTemporalRevision() throws Narsese.NarseseException {
    NAR n = NARS.tmp();
    n.time.dur(1);
    n.log();
    // TextOutput.out(n);
    n.input("a:b. %1.0|0.9%");
    n.run(5);
    n.input("a:b. %0.0|0.9%");
    n.run(5);
    n.input("a:b. %0.5|0.9%");
    n.run(1);
    // n.forEachConcept(Concept::print);
    TaskConcept c = (TaskConcept) n.conceptualize("a:b");
    assertNotNull(c);
    // assertEquals("(b-->a). 5+0 %.50;.95%", c.getBeliefs().top(n.time()).toStringWithoutBudget());
    BeliefTable b = c.beliefs();
    b.print();
    assertTrue(3 <= b.size());
    // when originality is considered:
    // assertEquals("(b-->a). 5+0 %0.0;.90%", c.beliefs().top(n.time()).toStringWithoutBudget());
    // most current relevant overall:
    assertEquals("(b-->a). 5 %0.0;.90%", n.belief(c.term(), 5).toStringWithoutBudget());
    // least relevant
    assertEquals("(b-->a). 0 %1.0;.90%", n.belief(c.term(), 0).toStringWithoutBudget());
}
Also used : TaskConcept(nars.concept.TaskConcept) BeliefTable(nars.table.BeliefTable) TestNAR(nars.test.TestNAR) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 38 with NAR

use of nars.NAR in project narchy by automenta.

the class TemporalInductionTest method testPriorityOfInductedRulesVsEventsThatItLearnedFrom.

/**
 * higher-level rules learned from events, especially repeatd
 * events, "should" ultimately accumulate a higher priority than
 * the events themselves.
 */
@Test
public void testPriorityOfInductedRulesVsEventsThatItLearnedFrom() throws FileNotFoundException {
    NAR n = NARS.tmp();
    n.beliefPriDefault.set(0.1f);
    // n.deep.set(1f);
    n.log();
    TemporalMetrics m = new TemporalMetrics(1024);
    n.onCycle(() -> m.update(n.time()));
    m.add(new PriMeter(n, "(0)"));
    m.add(new PriMeter(n, "(1)"));
    m.add(new PriMeter(n, "(2)"));
    m.add(new PriMeter(n, "((0) && (1))"));
    m.add(new PriMeter(n, "((0) ==> (1))"));
    m.add(new PriMeter(n, "((1) && (2))"));
    m.add(new PriMeter(n, "((1) ==> (2))"));
    // expose to repeat sequence
    int loops = 32, eventsPerLoop = 3, delayBetweenEvents = 2;
    for (int i = 0; i < loops; i++) {
        for (int j = 0; j < eventsPerLoop; j++) {
            n.believe($.p(j), Tense.Present);
            n.run(delayBetweenEvents);
        }
    }
    m.printCSV4("/tmp/x.csv");
    m.printCSV4(System.out);
}
Also used : TemporalMetrics(jcog.meter.TemporalMetrics) TestNAR(nars.test.TestNAR) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 39 with NAR

use of nars.NAR in project narchy by automenta.

the class TemporalInductionTest method testTemporalInduction.

@Test
public void testTemporalInduction() throws Narsese.NarseseException {
    String task = "<a --> b>. :|:";
    String task2 = "<c --> d>. :|:";
    NAR n = NARS.tmp();
    // TextOutput.out(n);
    n.input(task);
    n.run(10);
    n.input(task2);
    n.run(10);
}
Also used : TestNAR(nars.test.TestNAR) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 40 with NAR

use of nars.NAR in project narchy by automenta.

the class ImplicationTest method testGoal.

@Test
public void testGoal() {
    // Z, X==>Y
    StringBuilder o = new StringBuilder();
    for (boolean sp : B) {
        Term z = sp ? x : y;
        for (boolean zz : B) {
            for (boolean xx : B) {
                for (boolean yy : B) {
                    NAR n = NARS.tmp();
                    Term cond = z.negIf(!zz);
                    Term impl = IMPL.the(x.negIf(!xx), y.negIf(!yy));
                    n.believe(impl);
                    n.goal(cond);
                    n.run(64);
                    Term nz = sp ? y : x;
                    @Nullable Truth nzt = n.goalTruth(nz, ETERNAL);
                    o.append(cond + "! " + impl + ". " + nz + "=" + nzt + "\n");
                }
            }
        }
    }
    String oo = o.toString();
    System.out.println(oo);
    // strong
    assertContains(oo, "y! (x==>y). x=%1.0;.81%");
    assertContains(oo, "y! ((--,x)==>y). x=%0.0;.81%");
    assertContains(oo, "(--,y)! (--,(x==>y)). x=%1.0;.81%");
    assertContains(oo, "(--,y)! (--,((--,x)==>y)). x=%0.0;.81%");
    // weak
    assertContains(oo, "x! (x==>y). y=%1.0;.45%");
    assertContains(oo, "x! (--,(x==>y)). y=%0.0;.45%");
// ...
}
Also used : Term(nars.term.Term) NAR(nars.NAR) Nullable(org.jetbrains.annotations.Nullable) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Aggregations

NAR (nars.NAR)124 Test (org.junit.jupiter.api.Test)92 NARS (nars.NARS)23 Term (nars.term.Term)20 Truth (nars.truth.Truth)18 TestNAR (nars.test.TestNAR)16 BeliefTable (nars.table.BeliefTable)10 Disabled (org.junit.jupiter.api.Disabled)9 PrologCore (nars.op.prolog.PrologCore)8 Nullable (org.jetbrains.annotations.Nullable)8 Task (nars.Task)7 Concept (nars.concept.Concept)6 Param (nars.Param)5 Termed (nars.term.Termed)5 List (java.util.List)4 FasterList (jcog.list.FasterList)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 nars.$ (nars.$)3 ITask (nars.task.ITask)3 NALTest (nars.util.NALTest)3