Search in sources :

Example 11 with NARS

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

use of nars.NARS in project narchy by automenta.

the class Line1DQ method main.

public static void main(String[] args) {
    // Param.DEBUG = true;
    NAR n = new NARS().get();
    // n.log();
    n.time.dur(5);
    Line1DSimplest a = new Line1DSimplest();
    a.curiosity.set(0.01f);
    a.onFrame((z) -> {
        a.target(Util.unitize(// (float) (0.5f * (Math.sin(n.time() / 50f) + 1f))
        (Math.abs(3484 ^ n.time() / 200) % 11) / 10.0f));
    });
    // Arkancide a = new Arkancide(n, false, true);
    // Tetris a = new Tetris(n, 6, 10, 4);
    // a.onFrame(x -> Util.sleep(1));
    // a.trace = true;
    // Line1DTrainer trainer = new Line1DTrainer(a);
    // new RLBooster(a, new HaiQAgent(), 2); n.deriver.rate.setValue(0); a.curiosity.setValue(0f);
    NAgentX.chart(a);
    // int h = q.ae.W[0].length;
    // int w = q.ae.W.length;
    // window( grid(
    // new MatrixView(w, h, MatrixView.arrayRenderer(q.ae.W)),
    // new MatrixView(w, 1, MatrixView.arrayRenderer(q.ae.y)),
    // new MatrixView(w, 1, MatrixView.arrayRenderer(q.ae.z))
    // ), 500, 500);
    float grandTotal = 0;
    for (int i = 0; i < 100; i++) {
        int period = 1000;
    // a.runCycles(period);
    }
    System.err.println(" grand total = " + grandTotal);
}
Also used : NARS(nars.NARS) Line1DSimplest(nars.test.agent.Line1DSimplest) NAR(nars.NAR)

Example 13 with NARS

use of nars.NARS in project narchy by automenta.

the class RoverMaze1 method main.

public static void main(String[] args) {
    Rover r = new Rover(new NARS().get()) {

        @Override
        protected void create(Dynamics3D world) {
            SimpleSpatial torso;
            add(torso = new SimpleSpatial("torso") {

                @Override
                protected CollisionShape newShape() {
                    // return new CylinderShape(v(1f, 0.1f, 1f));
                    return new BoxShape(v(1.6f, 0.1f, 1f));
                }

                @Override
                public float mass() {
                    return 40f;
                }
            });
            SimpleSpatial neck;
            add(neck = new SimpleSpatial("neck") {

                @Override
                protected CollisionShape newShape() {
                    // return new TetrahedronShapeEx(v(0,10,0), v(10,0,0), v(10,10,0), v(0,0,10));
                    return new CylinderShape(v(0.25f, 0.75f, 0.25f));
                }

                @Override
                protected Body3D create(Dynamics3D world) {
                    torso.body.clearForces();
                    Body3D n = super.create(world);
                    HingeConstraint p = new HingeConstraint(torso.body, body, v(0, 0.2f, 0), v(0, -1f, 0), v(1, 0, 0), v(1, 0, 0));
                    p.setLimit(-1.0f, 1.0f);
                    add(p);
                    return n;
                }

                @Override
                public float mass() {
                    return 10f;
                }
            });
            neck.shapeColor[0] = 1f;
            neck.shapeColor[1] = 0.1f;
            neck.shapeColor[2] = 0.5f;
            neck.shapeColor[3] = 1f;
            RetinaGrid rg = new RetinaGrid("cam1", v(), v(0, 0, 1), v(0.1f, 0, 0), v(0, 0.1f, 0), 6, 6, 4f) {

                @Override
                protected Body3D create(Dynamics3D world) {
                    Body3D l = super.create(world);
                    // move(0,-1,0);
                    // body.clearForces();
                    l.clearForces();
                    HingeConstraint p = new HingeConstraint(neck.body, body, v(0, 0.6f, 0), v(0, -0.6f, 0), v(0, 1, 0), v(0, 1, 0));
                    p.setLimit(-0.75f, 0.75f);
                    // Point2PointConstraint p = new Point2PointConstraint(body, torso.body, v(2, 0, 0), v(-2, 0, 0));
                    // p.impulseClamp = 0.01f;
                    // //p.damping = 0.5f;
                    // p.tau = 0.01f;
                    add(p);
                    return l;
                }
            };
            add(rg);
        }
    };
// new SpaceGraph<>(
// new Maze("x", 20, 20),
// r
// );//.setGravity(v(0, 0, -5)).show(1000, 1000);
}
Also used : NARS(nars.NARS) CylinderShape(spacegraph.space3d.phys.shape.CylinderShape) SimpleSpatial(spacegraph.space3d.SimpleSpatial) Body3D(spacegraph.space3d.phys.Body3D) Dynamics3D(spacegraph.space3d.phys.Dynamics3D) BoxShape(spacegraph.space3d.phys.shape.BoxShape) HingeConstraint(spacegraph.space3d.phys.constraint.HingeConstraint)

Example 14 with NARS

use of nars.NARS in project narchy by automenta.

the class SATStream method main.

public static void main(String[] args) throws Narsese.NarseseException {
    // this.activeTasks = activeTasks;
    NAR d = new NARS().get();
    // d.inputActivation.setValue(0.2f);
    d.log();
    d.input("$0.1;0.2;0.5$ T:x1. :|:", "$0.1;0.2;0.5$ T:x2. :|:", "$0.1;0.2;0.5$ T:(--,x3). :|:", "$0.1;0.2;0.5$ T:(--,x4). :|:", "$1.0;1.0;1.0$ (($c:$x && $c:$y) ==> AND({$x,$y})). %1.00;1.00%");
    d.run(10360);
// d.dumpConcepts("/tmp/x.txt");
}
Also used : NARS(nars.NARS) NAR(nars.NAR)

Example 15 with NARS

use of nars.NARS in project narchy by automenta.

the class TrieDeriverTest method test.

public TestNAR test(int tlMax, boolean debug, String... rules) {
    NAR n = new NARS().deriverAddRules(rules).get();
    TestNAR t = new TestNAR(n);
    tests.add(t);
    return t;
}
Also used : NARS(nars.NARS) TestNAR(nars.test.TestNAR) TestNAR(nars.test.TestNAR) NAR(nars.NAR)

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