Search in sources :

Example 86 with NAR

use of nars.NAR in project narchy by automenta.

the class NARTest method testCycleScheduling.

@Test
public void testCycleScheduling() {
    NAR n = NARS.tmp();
    final int[] runs = { 0 };
    long[] events = { 2, 4, 4 /* test repeat */
    };
    for (long w : events) {
        n.at(w, () -> {
            assertEquals(w, n.time());
            runs[0]++;
        });
    }
    n.run(1);
    assertEquals(0, runs[0]);
    /* nothing yet in that 1st cycle */
    n.run((int) Longs.max(events));
    assertEquals(events.length, runs[0]);
}
Also used : NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 87 with NAR

use of nars.NAR in project narchy by automenta.

the class WorkerMultiExecTest method testValueDerivationBranches.

@Test
public void testValueDerivationBranches() throws Narsese.NarseseException {
    // int threads = 1;
    // Exec exe = new MultiExec(32, threads, 2);
    Exec exe = new UniExec(32);
    NAR n = new NARS().deriverAdd(1, 1).deriverAdd(6, 6).exe(exe).get();
    // all -1 except goal production
    Arrays.fill(n.emotion.want, -1);
    n.emotion.want(MetaGoal.Desire, +1);
    Exec.Revaluator r = new Focus.DefaultRevaluator();
    int cycles = 100;
    // 2 competing independent processes. NAL1 rules will apply to one, and NAL6 rules apply to ther other.
    // measure the amount of derivation work occurring for each
    ByteIntHashMap byPunc = new ByteIntHashMap();
    n.onTask(t -> {
        if (t instanceof DerivedTask) {
            byPunc.addToValue(t.punc(), 1);
        }
    });
    n.log();
    n.input("(x==>y).");
    n.input("f:a.");
    for (int i = 0; i < cycles; i++) {
        n.input("f:b. :|:");
        n.input("x! :|:");
        n.run(1);
        r.update(n);
    }
    System.out.println(byPunc);
    n.causes.forEach(c -> {
        double sum = Util.sum((ToDoubleFunction<Traffic>) (t -> t.total), c.goal);
        if (sum > Double.MIN_NORMAL) {
            System.out.println(Arrays.toString(c.goal) + "\t" + c);
        }
    });
}
Also used : NARS(nars.NARS) ByteIntHashMap(org.eclipse.collections.impl.map.mutable.primitive.ByteIntHashMap) Traffic(nars.control.Traffic) DerivedTask(nars.task.DerivedTask) NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 88 with NAR

use of nars.NAR in project narchy by automenta.

the class ListFuncTest method testAppendTransform.

@Test
public void testAppendTransform() {
    NAR n = NARS.shell();
    assertEquals(Set.of($$("(x,y)")), Solution.solve($$("append((x),(y))"), n.concepts.functors));
    assertEquals(Set.of($$("append(#x,(y))")), Solution.solve($$("append(#x,(y))"), n.concepts.functors));
}
Also used : NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 89 with NAR

use of nars.NAR in project narchy by automenta.

the class ListFuncTest method testAppendResult.

@Test
public void testAppendResult() {
    NAR n = NARS.shell();
    // solve result
    assertEquals(Set.of($$("append((x),(y),(x,y))")), Solution.solve($$("append((x),(y),#what)"), n.concepts.functors));
    // solve result in multiple instances
    assertEquals(Set.of($$("(append((x),(y),(x,y)) && ((x,y)<->solution))")), Solution.solve($$("(append((x),(y),#what) && (#what<->solution))"), n.concepts.functors));
}
Also used : NAR(nars.NAR) Test(org.junit.jupiter.api.Test)

Example 90 with NAR

use of nars.NAR in project narchy by automenta.

the class ExeCharts method metaGoalControls.

public static Surface metaGoalControls(NAR n) {
    CheckBox auto = new CheckBox("Auto");
    auto.set(false);
    float[] want = n.emotion.want;
    Gridding g = grid(// Stream.of(auto),
    IntStream.range(0, want.length).mapToObj(w -> new FloatSlider(want[w], -1f, +1f) {

        @Override
        protected void paintWidget(GL2 gl, RectFloat2D bounds) {
            if (auto.on()) {
                value(want[w]);
            }
        }
    }.text(MetaGoal.values()[w].name()).type(BaseSlider.Knob).on((s, v) -> {
        if (!auto.on())
            want[w] = v;
    })).toArray(Surface[]::new));
    return g;
}
Also used : GL2(com.jogamp.opengl.GL2) IntStream(java.util.stream.IntStream) BaseSlider(spacegraph.space2d.widget.slider.BaseSlider) DurService(nars.control.DurService) Causable(nars.exe.Causable) Surface(spacegraph.space2d.Surface) TreeChart(spacegraph.space2d.widget.meter.TreeChart) StringUtils(org.apache.commons.lang3.StringUtils) Draw(spacegraph.video.Draw) Function(java.util.function.Function) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface) Traffic(nars.control.Traffic) Gridding(spacegraph.space2d.container.Gridding) BitmapMatrixView(spacegraph.space2d.widget.meter.BitmapMatrixView) FloatSlider(spacegraph.space2d.widget.slider.FloatSlider) NAgent(nars.NAgent) FasterList(jcog.list.FasterList) FloatRange(jcog.math.FloatRange) nars.$(nars.$) LoopPanel(spacegraph.space2d.widget.meta.LoopPanel) Collectors(java.util.stream.Collectors) Util(jcog.Util) RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) CheckBox(spacegraph.space2d.widget.button.CheckBox) List(java.util.List) Splitting(spacegraph.space2d.container.Splitting) NAR(nars.NAR) Cause(nars.control.Cause) MetaGoal(nars.control.MetaGoal) FloatFunction(org.eclipse.collections.api.block.function.primitive.FloatFunction) Label(spacegraph.space2d.widget.text.Label) Gridding(spacegraph.space2d.container.Gridding) CheckBox(spacegraph.space2d.widget.button.CheckBox) FloatSlider(spacegraph.space2d.widget.slider.FloatSlider) RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) GL2(com.jogamp.opengl.GL2) Surface(spacegraph.space2d.Surface) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface)

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