Search in sources :

Example 11 with NAR

use of nars.NAR in project narchy by automenta.

the class SecondLevelUnificationTest method test1.

@Test
public void test1() throws Narsese.NarseseException {
    // this.activeTasks = activeTasks;
    NAR n = new NARS().get();
    // n.log();
    // n.eventTaskRemoved.on(t -> {
    // //System.err.println("rm: " + t + " " + t.getLogLast());
    // });
    // en("all xs are opened by some y");
    n.believe("<<$1 --> x> ==> (&&,<#2 --> y>,open(#2,$1))>", 1.00f, 0.90f);
    // en("z is a y");
    n.believe("<{z} --> y>", 1.00f, 0.90f);
    // tester.mustBelieve(cycles, "<<$1 --> x> ==> <$1 --> (/,open,{z},_)>>", 1.00f, 0.42f); //en("maybe all xs are opened by z");
    n.run(250);
}
Also used : NARS(nars.NARS) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 12 with NAR

use of nars.NAR in project narchy by automenta.

the class SecondLevelUnificationTest method test2.

@Test
public void test2() throws Narsese.NarseseException {
    // this.activeTasks = activeTasks;
    NAR n = new NARS().get();
    // n.log();
    // n.eventTaskRemoved.on(t -> {
    // //System.err.println("rm: " + t + " " + t.getLogLast());
    // });
    // en("all xs are opened by some y");
    n.believe("<<$1 --> x> ==> (&&,<#2 --> y>,<$1 --> #2>)>", 1.00f, 0.90f);
    // en("z is a y");
    n.believe("<{z} --> y>", 1.00f, 0.90f);
    // tester.mustBelieve(cycles, "<<$1 --> x> ==> <$1 --> {z}>>", 1.00f, 0.42f); //en("maybe all xs are opened by z");
    n.run(250);
}
Also used : NARS(nars.NARS) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 13 with NAR

use of nars.NAR in project narchy by automenta.

the class NAL7ImplProjectionTest method test1.

@Test
public void test1() {
    int implDT = 5;
    int dur = 1;
    /* eventTime, relative to impl belief */
    for (int implTime = 0; implTime < 5; implTime += 2) {
        for (int eventTime = 0; eventTime < 5; eventTime += 2) {
            Term y = $.the("y");
            Param.DEBUG = true;
            NAR n = NARS.tmp();
            // n.log();
            n.time.dur(dur);
            n.inputAt(eventTime, "x. :|:");
            n.inputAt(implTime, "(x ==>+" + implDT + " y). :|:");
            int end = Math.max(eventTime + implDT, implTime);
            n.run(end + 1);
            double[] max = new MyBrentOptimizer(0.001f, 0.01, 0, end, (t) -> {
                Truth u = n.beliefTruth(y, Math.round(t));
                if (u == null)
                    return -1f;
                return u.conf();
            }).max(0, end, end / 2.0);
            long yTimeEstimate = Math.round(max[0]);
            long yTimeActual = eventTime + implDT;
            assertTrue(Math.abs(yTimeEstimate - yTimeActual) <= 1);
            double yConfMax = max[1];
            long eventBeliefDelta = Math.abs(eventTime - implTime);
            System.out.println("+-" + eventBeliefDelta + " -> " + max[0] + "=" + max[1]);
        }
    }
// double zero = UnivariateSolverUtils.solve(t->{
// return 0;
// }, 0, end, 0.01f);
// n.concept(x).print();
// n.concept(y).print();
}
Also used : Param(nars.Param) Test(org.junit.jupiter.api.Test) NumberIsTooSmallException(org.apache.commons.math3.exception.NumberIsTooSmallException) Truth(nars.truth.Truth) Precision(org.apache.commons.math3.util.Precision) NotStrictlyPositiveException(org.apache.commons.math3.exception.NotStrictlyPositiveException) NARS(nars.NARS) NAR(nars.NAR) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) nars.$(nars.$) DoubleToDoubleFunction(org.eclipse.collections.api.block.function.primitive.DoubleToDoubleFunction) Term(nars.term.Term) Term(nars.term.Term) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 14 with NAR

use of nars.NAR in project narchy by automenta.

the class ImplicationNetworkTest method testEternal_A_PosBelief_ToBC.

@Test
public void testEternal_A_PosBelief_ToBC() {
    NAR n = NARS.tmp();
    Param.DEBUG = true;
    n.believe(IMPL.the(a, b));
    n.believe(IMPL.the(b, c));
    n.believe(a);
    n.run(100);
    BeliefTable aBeliefs = n.concept(a).beliefs();
    Truth aBelief = aBeliefs.truth(ETERNAL, n);
    // n.concept(a).print();
    // a belief state should not exceed the input (default confidence) and freq remain stable
    // additional beliefs are not helpful
    // assertEquals(1, aBeliefs.size());
    BeliefTable bBeliefs = n.concept(b).beliefs();
    Truth bBelief = bBeliefs.truth(ETERNAL, n);
    // n.concept(b).print();
    // assertEquals(1, bBeliefs.size());
    // b should have less conf than a but higher than c
    // same freq among all
    Truth cBelief = n.concept(c).beliefs().truth(ETERNAL, n);
    // n.concept(c).print();
    System.out.println("a: " + aBelief);
    System.out.println("b: " + bBelief);
    System.out.println("c: " + cBelief);
    assertEquals(aBelief.freq(), bBelief.freq(), n.freqResolution.floatValue());
    assertEquals(bBelief.freq(), cBelief.freq(), n.freqResolution.floatValue());
    assertTrue(aBelief.conf() - bBelief.conf() > n.confResolution.floatValue() * 2);
    assertTrue(bBelief.conf() - cBelief.conf() > n.confResolution.floatValue() * 2);
}
Also used : BeliefTable(nars.table.BeliefTable) NAR(nars.NAR) Truth(nars.truth.Truth) Test(org.junit.jupiter.api.Test)

Example 15 with NAR

use of nars.NAR in project narchy by automenta.

the class ImplicationNetworkTest method testEternal_A_NegBelief_NegToBC.

@Test
public void testEternal_A_NegBelief_NegToBC() {
    NAR n = NARS.tmp(6);
    n.termVolumeMax.set(16);
    Param.DEBUG = true;
    n.believe(IMPL.the(a.neg(), b));
    n.believe(IMPL.the(b, c));
    n.believe(a.neg());
    n.run(800);
    BeliefTable aa = n.concept(a).beliefs();
    BeliefTable bb = n.concept(b).beliefs();
    BeliefTable cc = n.concept(c).beliefs();
    aa.print();
    bb.print();
    // cc.print();
    cc.forEachTask(x -> System.out.println(x.proof()));
    // assertEquals(1, aBeliefs.size());
    Truth bBelief = bb.truth(ETERNAL, n);
    Truth cBelief = cc.truth(ETERNAL, n);
    assertEquals("%1.0;.81%", bBelief.toString());
    assertEquals("%1.0;.73%", cBelief.toString());
}
Also used : BeliefTable(nars.table.BeliefTable) 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