Search in sources :

Example 1 with Traffic

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

use of nars.control.Traffic in project narchy by automenta.

the class ExeCharts method metaGoalChart.

private static Surface metaGoalChart(NAgent a) {
    return new TreeChart<Cause>() {

        final DurService on;

        final FasterList<ItemVis<Cause>> cache = new FasterList();

        final Function<Cause, TreeChart.ItemVis<Cause>> builder = ((i) -> {
            short id = i.id;
            ItemVis<Cause> item;
            if (cache.capacity() - 1 < id)
                cache.ensureCapacity(id + 16);
            else {
                item = cache.get(id);
                if (item != null)
                    return item;
            }
            String str = i.toString();
            if (str.startsWith("class nars."))
                // skip default toString
                str = str.substring("class nars.".length());
            if (str.startsWith("class "))
                // skip default toString
                str = str.substring(5);
            item = new CauseVis(i, str);
            cache.set(id, item);
            return item;
        });

        {
            on = a.onFrame(() -> {
                update(a.nar().causes, (c, i) -> {
                    float v = c.value();
                    float r, g, b;
                    if (v < 0) {
                        r = 0.75f * Math.max(0.1f, Math.min(1f, -v));
                        g = 0;
                    } else {
                        g = 0.75f * Math.max(0.1f, Math.min(1f, +v));
                        r = 0;
                    }
                    float t = Util.sum(((FloatFunction<Traffic>) (p -> Math.abs(p.last))), c.goal);
                    b = Math.max(r, g) / 2f * Util.unitize(t);
                    i.update(v, r, g, b);
                // i.updateMomentum(
                // //0.01f + Util.sqr(Util.tanhFast(v)+1),
                // //Math.signum(v) *(1+Math.abs(v))*(t),
                // //Math.signum(v) * t,
                // v,
                // 0.25f,
                // r, g, b);
                }, builder);
            });
        }

        @Override
        public void stop() {
            super.stop();
            on.off();
        }
    };
}
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) Function(java.util.function.Function) FloatFunction(org.eclipse.collections.api.block.function.primitive.FloatFunction) FasterList(jcog.list.FasterList) Cause(nars.control.Cause) Traffic(nars.control.Traffic) TreeChart(spacegraph.space2d.widget.meter.TreeChart) DurService(nars.control.DurService)

Aggregations

NAR (nars.NAR)2 Traffic (nars.control.Traffic)2 GL2 (com.jogamp.opengl.GL2)1 List (java.util.List)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Util (jcog.Util)1 FasterList (jcog.list.FasterList)1 FloatRange (jcog.math.FloatRange)1 RectFloat2D (jcog.tree.rtree.rect.RectFloat2D)1 nars.$ (nars.$)1 NARS (nars.NARS)1 NAgent (nars.NAgent)1 Cause (nars.control.Cause)1 DurService (nars.control.DurService)1 MetaGoal (nars.control.MetaGoal)1 Causable (nars.exe.Causable)1 DerivedTask (nars.task.DerivedTask)1 StringUtils (org.apache.commons.lang3.StringUtils)1