Search in sources :

Example 31 with NAR

use of nars.NAR in project narchy by automenta.

the class TruthletTaskTest method testImpulseTruthlet.

@Test
public void testImpulseTruthlet() {
    NAR n = NARS.shell();
    Term x = $.the("x");
    float conf = 0.9f;
    n.input(new TruthletTask(x, BELIEF, Truthlet.impulse(1, 2, 1f, 0f, c2w(conf)), n));
    BeliefTable xb = n.truths(x, BELIEF);
    for (int i = -1; i < 5; i++) {
        Truth ti = xb.truth(i, n);
        assertEquals((i <= 0 || i >= 3) ? 0 : 1, ti.freq());
        if (i >= 1 && i <= 2)
            assertEquals(conf, ti.conf());
        else
            assertTrue(conf > ti.conf());
        System.out.println(i + ": " + ti);
    }
}
Also used : BeliefTable(nars.table.BeliefTable) Term(nars.term.Term) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 32 with NAR

use of nars.NAR in project narchy by automenta.

the class ArithmeticTest method testMul.

@Test
public void testMul() throws Narsese.NarseseException {
    NAR t = NARS.shell();
    assertEquals("0", $.$("mul(x,0)").eval(t.concepts.functors).toString());
    assertEquals("x", $.$("mul(x,1)").eval(t.concepts.functors).toString());
}
Also used : NAR(nars.NAR) TestNAR(nars.test.TestNAR) Test(org.junit.jupiter.api.Test)

Example 33 with NAR

use of nars.NAR in project narchy by automenta.

the class ArithmeticTest method testCompleteAddInduction.

@Test
public void testCompleteAddInduction() throws Narsese.NarseseException {
    NAR n = NARS.tmp();
    new ArithmeticIntroduction(16, n);
    TestNAR t = new TestNAR(n);
    t.confTolerance(0.8f);
    t.log();
    // t.believe("(x:1,x:2)");
    // t.believe("(x:2,x:3)");
    // t.believe("(x:3,x:4)");
    // t.believe("(x:4,x:5)");
    // t.ask("(x:5,?1)");
    // t.mustBelieve(1000, "(x:5,x:6)", 1f, 0.81f);
    t.believe("(a,1)");
    t.believe("(a,2)");
    t.believe("(a,3)");
    t.believe("(a,4)");
    t.ask("(a,#x)");
    t.mustBelieve(1000, // "((a,add(#1,1))&&(#1<->4))",
    "((a,add($1,1))==>(#1<->4))", 1f, 0.81f);
    t.mustBelieve(1000, "(a,5)", 1f, 0.81f);
    t.test(true);
}
Also used : TestNAR(nars.test.TestNAR) NAR(nars.NAR) TestNAR(nars.test.TestNAR) Test(org.junit.jupiter.api.Test)

Example 34 with NAR

use of nars.NAR in project narchy by automenta.

the class ConjClusteringTest method testSameTruthSameTime.

@Test
public void testSameTruthSameTime() throws Narsese.NarseseException {
    NAR n = NARS.shell();
    int ccap = 4;
    ConjClustering c = new ConjClustering(n, BELIEF, (t) -> t.isInput(), 4, ccap);
    n.log();
    for (int i = 0; i < ccap; i++) n.believe($.the("x" + i), Tense.Present);
    n.run(1);
    assertEquals(1, n.concept($.$("(&&,x0,x1,x2,x3)")).beliefs().size());
}
Also used : ConjClustering(nars.op.stm.ConjClustering) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 35 with NAR

use of nars.NAR in project narchy by automenta.

the class RuleInductionTest method test1.

@Test
public void test1() {
    int dur = 1;
    int loops = 10;
    int period = 2;
    int dutyPeriod = 1;
    NAR n = NARS.tmp();
    n.termVolumeMax.set(3);
    // n.log();
    // dense proressing
    Deriver.derivers(n).forEach(d -> d.conceptsPerIteration.set(64));
    n.time.dur(dur);
    Term aConjB = $$("(a &&+" + dutyPeriod + " b)");
    float lastAConjB_exp = 0;
    PairedStatsAccumulator aConjB_exp = new PairedStatsAccumulator();
    for (int i = 0; i < loops; i++) {
        // n.clear(); //distraction clear
        n.believe("a", Tense.Present, 1, 0.9f);
        if (i > 0) {
        // TODO test that the newest tasklink inserted into concept 'a' is the, or nearly the strongest
        // n.concept("a").tasklinks().print();
        }
        n.run(dutyPeriod);
        n.believe("b", Tense.Present, 1, 0.9f);
        // delay
        n.run(period - dutyPeriod);
        long now = n.time();
        System.out.println("\n" + now);
        Truth aConjB_truth = n.belief(aConjB, now).truth(now, n.dur());
        System.out.println(aConjB_truth);
        n.conceptualize(aConjB).beliefs().print();
        float exp = aConjB_truth.expectation();
        if (!(exp >= lastAConjB_exp)) {
            // for debug
            Task tt = n.belief(aConjB, now);
        }
        // assertTrue(exp > lastAConjB_exp); //increasing
        aConjB_exp.add(now, exp);
        lastAConjB_exp = exp;
    }
    System.out.println(aConjB_exp.yStats());
    System.out.println("slope=" + aConjB_exp.leastSquaresFit().slope());
    // rising confidence
    assertTrue(aConjB_exp.leastSquaresFit().slope() > 0);
}
Also used : Task(nars.Task) Term(nars.term.Term) PairedStatsAccumulator(com.google.common.math.PairedStatsAccumulator) NAR(nars.NAR) 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