Search in sources :

Example 1 with NARS

use of nars.NARS 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 2 with NARS

use of nars.NARS 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 3 with NARS

use of nars.NARS in project narchy by automenta.

the class STRIPSTest method testBanana1.

@Test
public void testBanana1() throws Narsese.NarseseException {
    NAR n = new NARS().tmp();
    n.log();
    n.input("At(A). :|:", "Level(low). :|:", "BoxAt(C). :|:", "BananasAt(B). :|:", /* Goal state:    Eat(bananas) */
    "Eat(bananas)!", // _Move(X, Y)_
    "((At($X) &&+0 Level(low)) ==>+1 (--At($X) &&+0 At(#Y))).", // _ClimbUp(Location)_ climb up the box
    "(((At(#Location) &&+0 BoxAt(#Location)) &&+0 Level(low)) ==>+1 (Level(high) &&+0 --Level(low))).", // _ClimbDown(Location)_ climb down from the box
    "(((At(#Location) &&+0 BoxAt(#Location)) &&+0 Level(high)) ==>+1 (Level(low), --Level(high))).", /* Preconditions:  At(X), BoxAt(X), Level(low)
               Postconditions: BoxAt(Y), not BoxAt(X), At(Y), not At(X) */
    "(((At($X) &&+0 BoxAt($X)) &&+0 Level(low)) ==>+1 ((((At(#Y) &&+0 BoxAt(#Y)) &&+0 --BoxAt($X)) &&+0 --At($X)))).", /* Preconditions:  At(Location), BananasAt(Location), Level(high)
               Postconditions: Eat(bananas) */
    "(((At(#Location) &&+0 BananasAt(#Location)) &&+0 Level(high)) ==>+1 Eat(bananas)).");
    n.run(1000);
}
Also used : NARS(nars.NARS) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 4 with NARS

use of nars.NARS in project narchy by automenta.

the class WorkerMultiExecTest method test1.

@Test
public void test1() {
    int threads = 3;
    Focus.DefaultRevaluator reval = new Focus.DefaultRevaluator();
    WorkerMultiExec exe = new WorkerMultiExec(reval, threads, 16, 3);
    NAR n = new NARS().exe(exe).get();
    AtomicLong dutyTimeNS = new AtomicLong();
    DummyCan a = new DummyCan("a", dutyTimeNS, n, (int j) -> Util.sleep(1 * j)).value(4f);
    DummyCan b = new DummyCan("b", dutyTimeNS, n, (int j) -> Util.sleep(1 * j)).value(1f);
    DummyCan c = new DummyCan("c", dutyTimeNS, n, (int j) -> Util.sleep(2 * j)).value(1f);
    // n.onCycle(nn -> {
    // Focus.Schedule s = exe.focus.schedule.read();
    // System.out.println(nn.time() + " " +
    // Arrays.toString(s.active) + "->" + n4(s.weight));
    // });
    long start = System.nanoTime();
    Loop l = n.startFPS(5f);
    Util.sleep(4000);
    l.stop();
    long totalTimeNS = (System.nanoTime() - start) * threads;
    System.out.println("dutyTime=" + timeStr(dutyTimeNS.get()) + " , totalTime=" + timeStr(totalTimeNS) + ", efficiency=" + ((double) dutyTimeNS.get()) / totalTimeNS);
    System.out.println(a.executed.get());
    System.out.println(b.executed.get());
    System.out.println(c.executed.get());
    System.out.println(exe.focus);
    assertEquals(3 + 1, exe.focus.choice.size());
    assertEquals(expectedDuty(a) / expectedDuty(b), ((float) a.executed.get()) / b.executed.get(), 0.5f);
    assertEquals(expectedDuty(a) / expectedDuty(c) / 2, ((float) a.executed.get()) / c.executed.get(), 0.5f);
}
Also used : NARS(nars.NARS) Loop(jcog.exe.Loop) AtomicLong(java.util.concurrent.atomic.AtomicLong) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 5 with NARS

use of nars.NARS in project narchy by automenta.

the class TermTreeTest method testCompoundInsertion.

@Test
public void testCompoundInsertion() throws Narsese.NarseseException {
    TreeConceptIndex index;
    NAR nar = new NARS().index(index = new TreeConceptIndex(1000)).get();
    int preSize = index.size();
    String[] terms = { "x", "(x)", "(xx)", "(xxx)", "(x,y)", "(x,z)", "(x --> z)", "(x <-> z)", "(x&&z)" };
    HashSet<Term> input = new HashSet();
    for (String s : terms) {
        @NotNull Term ts = $(s);
        input.add(ts);
        index.get(ts, true);
    }
    assertEquals(terms.length + preSize, index.size());
    for (Term x : input) assertNotNull(index.get(x, false));
    // Set<Termed> stored = StreamSupport.stream(index.concepts.spliterator(), false).collect(Collectors.toSet());
    // assertEquals(Sets.symmetricDifference(input, stored) + " = difference", input, stored);
    index.concepts.prettyPrint();
    index.print(System.out);
// String stringWithUnicode = "unicode\u00easomething";
// assertNull( tree.resolveOrAdd(stringWithUnicode)); //unicode not supported yet
}
Also used : NARS(nars.NARS) TreeConceptIndex(nars.index.term.TreeConceptIndex) NotNull(org.jetbrains.annotations.NotNull) NAR(nars.NAR) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

NARS (nars.NARS)20 NAR (nars.NAR)19 Test (org.junit.jupiter.api.Test)14 Term (nars.term.Term)2 FileNotFoundException (java.io.FileNotFoundException)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Consumer (java.util.function.Consumer)1 Predicate (java.util.function.Predicate)1 Loop (jcog.exe.Loop)1 nars.$ (nars.$)1 Narsese (nars.Narsese)1 BELIEF (nars.Op.BELIEF)1 Task (nars.Task)1 TaskConcept (nars.concept.TaskConcept)1 DurService (nars.control.DurService)1 Traffic (nars.control.Traffic)1 TreeConceptIndex (nars.index.term.TreeConceptIndex)1 ConjClustering (nars.op.stm.ConjClustering)1