Search in sources :

Example 1 with AutoSurface

use of spacegraph.space2d.widget.meta.AutoSurface in project narchy by automenta.

the class TensorGlow method main.

public static void main(String[] args) {
    PhyWall p = SpaceGraph.wall(1200, 1000);
    p.W.setGravity(new v2(0, -2.8f));
    staticBox(p.W, -5, -8, +5, 2f, false, true, true, true);
    for (int j = 0; j < 3; j++) {
        BodyDef bodyDef2 = new BodyDef();
        bodyDef2.type = BodyType.DYNAMIC;
        // otocenie
        bodyDef2.angle = -0.6f;
        // smer pohybu
        bodyDef2.linearVelocity = new v2(0.0f, 0.0f);
        // rotacia (rychlost rotacie)
        bodyDef2.angularVelocity = 0.0f;
        Body2D newBody = p.W.addBody(bodyDef2);
        PolygonShape shape2 = new PolygonShape();
        shape2.setAsBox(0.25f, 0.25f);
        Fixture f = newBody.addFixture(shape2, 1.0f);
        // trenie
        f.friction = 0.5f;
        // odrazivost
        f.restitution = 0.0f;
        f.material = new Uniform();
        f.material.m_rigidity = 1.0f;
    }
    // //ceiling rack
    // addBox(p.W, -1, +0.4f, 0, +0.65f, false, true, true, true);
    // new Pacman(p.W);
    {
        p.W.setContactListener(new Explosives.ExplosionContacts());
        TheoJansen t = new TheoJansen(p.W, 0.35f);
        PhyWall.PhyWindow pw = p.put(new Gridding(0.5f, new Port((float[] v) -> {
            // System.out.println(v);
            t.motorJoint.setMotorSpeed(v[0] * 2 - v[1] * 2);
            t.motorJoint.setMaxMotorTorque(v[2]);
            t.motorJoint.enableLimit(true);
            t.motorJoint.setLimits((float) (-v[3] * Math.PI), (float) (+v[4] * Math.PI));
            if (v[5] > 0.5f) {
                t.gun.fire();
            }
            t.turretJoint.setLimits((float) (+Math.PI / 2 + v[6] * Math.PI - 0.1f), (float) (+Math.PI / 2 + v[6] * Math.PI + 0.1f));
        })), 0.8f, 0.4f);
        p.W.addJoint(new RevoluteJoint(p.W, new RevoluteJointDef(pw.body, t.chassis)));
    }
    {
        p.W.setParticleRadius(0.05f);
        p.W.setParticleDamping(0.1f);
        CircleShape shape = new CircleShape();
        shape.center.set(0, 10);
        shape.radius = 2f;
        ParticleGroupDef pd = new ParticleGroupDef();
        pd.flags = ParticleType.b2_waterParticle;
        // b2_viscousParticle;
        // b2_elasticParticle;
        // b2_springParticle;
        // b2_powderParticle;
        pd.color = new ParticleColor(0.7f, 0.1f, 0.1f, 0.8f);
        pd.shape = shape;
        p.W.addParticles(pd);
    }
    HaiQae q = new HaiQae(8, 2);
    float[] in = new float[q.ae.inputs()];
    final Tensor randomVector = Tensor.randomVectorGauss(in.length, 0, 1, rng);
    final FloatRange lerpRate = new FloatRange(0.01f, 0, 1f);
    final TensorLERP lerpVector = new TensorLERP(randomVector, lerpRate);
    PhyWall.PhyWindow w = p.put(new Gridding(0.25f, new AutoUpdateMatrixView(lerpVector.data), new LabeledPane("lerp", new XYSlider().on((x, y) -> {
        lerpRate.set(x);
    })), new LabeledPane("out", new Port((x) -> {
    }) {

        @Override
        public void prePaint(int dtMS) {
            super.prePaint(dtMS);
            out(lerpVector.data);
        }
    })), 0.5f, 0.5f);
    p.put(new TogglePort(), 0.25f, 0.25f);
    PhyWall.PhyWindow qw = p.put(new Gridding(new Label("HaiQ"), new AutoSurface<>(q), new LabeledPane("input", new Port((float[] i) -> {
        System.arraycopy(i, 0, in, 0, i.length);
    })), new Gridding(VERTICAL, new AutoUpdateMatrixView(in), new AutoUpdateMatrixView(q.ae.x), new AutoUpdateMatrixView(q.ae.W), new AutoUpdateMatrixView(q.ae.y)), new Gridding(VERTICAL, new AutoUpdateMatrixView(q.q), new AutoUpdateMatrixView(q.et))), 1, 1);
    Loop.of(() -> {
        lerpVector.update();
        q.act((((float) Math.random()) - 0.5f) * 2, in);
    }).runFPS(25);
}
Also used : Fixture(spacegraph.space2d.phys.dynamics.Fixture) ParticleGroupDef(spacegraph.space2d.phys.particle.ParticleGroupDef) Explosives(spacegraph.space2d.phys.explosive.Explosives) Tensor(jcog.math.tensor.Tensor) HaiQae(jcog.learn.ql.HaiQae) Random(java.util.Random) RevoluteJoint(spacegraph.space2d.phys.dynamics.joints.RevoluteJoint) Port(spacegraph.space2d.widget.windo.Port) ParticleColor(spacegraph.space2d.phys.particle.ParticleColor) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface) AutoUpdateMatrixView(spacegraph.space2d.widget.meter.AutoUpdateMatrixView) BodyDef(spacegraph.space2d.phys.dynamics.BodyDef) PhyWall(spacegraph.space2d.widget.windo.PhyWall) Gridding(spacegraph.space2d.container.Gridding) BodyType(spacegraph.space2d.phys.dynamics.BodyType) ParticleType(spacegraph.space2d.phys.particle.ParticleType) RevoluteJointDef(spacegraph.space2d.phys.dynamics.joints.RevoluteJointDef) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) PolygonShape(spacegraph.space2d.phys.collision.shapes.PolygonShape) LabeledPane(spacegraph.space2d.widget.text.LabeledPane) Loop(jcog.exe.Loop) TogglePort(spacegraph.space2d.widget.windo.TogglePort) XYSlider(spacegraph.space2d.widget.slider.XYSlider) Dynamics2D.staticBox(spacegraph.space2d.phys.dynamics.Dynamics2D.staticBox) Uniform(spacegraph.space2d.phys.fracture.materials.Uniform) FloatRange(jcog.math.FloatRange) CircleShape(spacegraph.space2d.phys.collision.shapes.CircleShape) spacegraph.util.math.v2(spacegraph.util.math.v2) TensorLERP(jcog.math.tensor.TensorLERP) VERTICAL(spacegraph.space2d.container.Gridding.VERTICAL) SpaceGraph(spacegraph.SpaceGraph) Label(spacegraph.space2d.widget.text.Label) Body2D(spacegraph.space2d.phys.dynamics.Body2D) PolygonShape(spacegraph.space2d.phys.collision.shapes.PolygonShape) Port(spacegraph.space2d.widget.windo.Port) TogglePort(spacegraph.space2d.widget.windo.TogglePort) Label(spacegraph.space2d.widget.text.Label) Uniform(spacegraph.space2d.phys.fracture.materials.Uniform) CircleShape(spacegraph.space2d.phys.collision.shapes.CircleShape) TogglePort(spacegraph.space2d.widget.windo.TogglePort) FloatRange(jcog.math.FloatRange) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface) LabeledPane(spacegraph.space2d.widget.text.LabeledPane) Fixture(spacegraph.space2d.phys.dynamics.Fixture) BodyDef(spacegraph.space2d.phys.dynamics.BodyDef) ParticleGroupDef(spacegraph.space2d.phys.particle.ParticleGroupDef) HaiQae(jcog.learn.ql.HaiQae) Tensor(jcog.math.tensor.Tensor) RevoluteJoint(spacegraph.space2d.phys.dynamics.joints.RevoluteJoint) TensorLERP(jcog.math.tensor.TensorLERP) RevoluteJoint(spacegraph.space2d.phys.dynamics.joints.RevoluteJoint) RevoluteJointDef(spacegraph.space2d.phys.dynamics.joints.RevoluteJointDef) Gridding(spacegraph.space2d.container.Gridding) AutoUpdateMatrixView(spacegraph.space2d.widget.meter.AutoUpdateMatrixView) XYSlider(spacegraph.space2d.widget.slider.XYSlider) PhyWall(spacegraph.space2d.widget.windo.PhyWall) ParticleColor(spacegraph.space2d.phys.particle.ParticleColor) spacegraph.util.math.v2(spacegraph.util.math.v2) Body2D(spacegraph.space2d.phys.dynamics.Body2D)

Example 2 with AutoSurface

use of spacegraph.space2d.widget.meta.AutoSurface in project narchy by automenta.

the class NAgentX method chart.

public static void chart(NAgent a) {
    NAR nar = a.nar();
    nar.runLater(() -> {
        SpaceGraph.window(grid(new AutoSurface(a), Vis.beliefCharts(nar.dur() * 64, a.actions.keySet(), a.nar()), new EmotionPlot(64, a), grid(// concept query box
        new TextEdit() {

            @Override
            protected void onKeyEnter() {
                String s = text();
                text("");
                try {
                    nar.conceptualize(s);
                } catch (Narsese.NarseseException e) {
                    e.printStackTrace();
                }
                Vis.conceptWindow(s, nar);
            }
        }.surface(), // new WindowButton("log", () -> Vis.logConsole(nar, 80, 25, new FloatParam(0f))),
        new PushButton("dump", () -> {
            try {
                nar.output(Files.createTempFile(a.toString(), "" + System.currentTimeMillis()).toFile(), false);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }), new PushButton("clear", () -> {
            nar.runLater(NAR::clear);
        }), new PushButton("prune", () -> {
            nar.runLater(() -> {
                DoubleHistogram i = new DoubleHistogram(2);
                nar.tasks(true, false, false, false).forEach(t -> i.recordValue(t.conf()));
                float confThresh = (float) i.getValueAtPercentile(25);
                nar.tasks(true, false, false, false).filter(t -> t.conf() < confThresh).forEach(Task::delete);
            });
        }), new WindowToggleButton("top", () -> new ConsoleTerminal(new nars.TextUI(nar).session(10f))), new WindowToggleButton("concept graph", () -> {
            DynamicConceptSpace sg;
            SpaceGraphPhys3D s = new SpaceGraphPhys3D<>(sg = new DynamicConceptSpace(nar, () -> nar.exe.active().iterator(), 128, 16));
            EdgeDirected fd = new EdgeDirected();
            s.dyn.addBroadConstraint(fd);
            fd.attraction.set(fd.attraction.get() * 8);
            s.add(new SubOrtho(// window(
            grid(new AutoSurface<>(fd), new AutoSurface<>(sg.vis))) {
            }.posWindow(0, 0, 1f, 0.2f));
            // ,  400, 400);
            // .pos(0, 0, 0.5f, 0.5f)
            s.camPos(0, 0, 90);
            return s;
        }), a instanceof NAgentX ? new WindowToggleButton("vision", () -> grid(((NAgentX) a).sensorCam.stream().map(cs -> new AspectAlign(new CameraSensorView(cs, a).withControls(), AspectAlign.Align.Center, cs.width, cs.height)).toArray(Surface[]::new))) : grid())), // 
        900, 600);
    });
}
Also used : Bitmap2DSensor(nars.util.signal.Bitmap2DSensor) IntConsumer(java.util.function.IntConsumer) AspectAlign(spacegraph.space2d.container.AspectAlign) Auvent(net.beadsproject.beads.core.Auvent) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface) RealTime(nars.time.RealTime) nars.$.$$(nars.$.$$) DoubleHistogram(org.HdrHistogram.DoubleHistogram) SpaceGraphPhys3D(spacegraph.space3d.SpaceGraphPhys3D) Vis(nars.gui.Vis) Bitmap2D(jcog.signal.Bitmap2D) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) Term(nars.term.Term) nars.video(nars.video) ConsoleTerminal(spacegraph.space2d.widget.console.ConsoleTerminal) Loop(jcog.exe.Loop) UGen(net.beadsproject.beads.core.UGen) BufferedImage(java.awt.image.BufferedImage) Util(jcog.Util) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) Nullable(org.jetbrains.annotations.Nullable) WaveFactory(net.beadsproject.beads.data.WaveFactory) WorkerMultiExec(nars.exe.WorkerMultiExec) SpaceGraph(spacegraph.SpaceGraph) EmotionPlot(nars.gui.EmotionPlot) Tense(nars.time.Tense) net.beadsproject.beads.ugens(net.beadsproject.beads.ugens) Focus(nars.exe.Focus) Surface(spacegraph.space2d.Surface) Function(java.util.function.Function) Supplier(java.util.function.Supplier) nars.$.$(nars.$.$) WindowToggleButton(spacegraph.space2d.widget.meta.WindowToggleButton) SubOrtho(spacegraph.space2d.hud.SubOrtho) Gridding.grid(spacegraph.space2d.container.Gridding.grid) EdgeDirected(spacegraph.space2d.container.EdgeDirected) FloatProcedure(org.eclipse.collections.api.block.procedure.primitive.FloatProcedure) Inperience(nars.op.mental.Inperience) Files(java.nio.file.Files) PushButton(spacegraph.space2d.widget.button.PushButton) DynamicConceptSpace(nars.gui.graph.DynamicConceptSpace) IOException(java.io.IOException) AudioContext(net.beadsproject.beads.core.AudioContext) IntObjectPair(org.eclipse.collections.api.tuple.primitive.IntObjectPair) java.awt(java.awt) TextEdit(spacegraph.space2d.widget.console.TextEdit) BELIEF(nars.Op.BELIEF) ConjClustering(nars.op.stm.ConjClustering) CaffeineIndex(nars.index.term.map.CaffeineIndex) DynamicConceptSpace(nars.gui.graph.DynamicConceptSpace) DoubleHistogram(org.HdrHistogram.DoubleHistogram) IOException(java.io.IOException) SpaceGraphPhys3D(spacegraph.space3d.SpaceGraphPhys3D) EdgeDirected(spacegraph.space2d.container.EdgeDirected) WindowToggleButton(spacegraph.space2d.widget.meta.WindowToggleButton) AspectAlign(spacegraph.space2d.container.AspectAlign) EmotionPlot(nars.gui.EmotionPlot) TextEdit(spacegraph.space2d.widget.console.TextEdit) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface) ConsoleTerminal(spacegraph.space2d.widget.console.ConsoleTerminal) PushButton(spacegraph.space2d.widget.button.PushButton) SubOrtho(spacegraph.space2d.hud.SubOrtho)

Example 3 with AutoSurface

use of spacegraph.space2d.widget.meta.AutoSurface in project narchy by automenta.

the class TestTimeGraphVis method main.

public static void main(String[] args) {
    // NAR n = NARS.threadSafe();
    TestTimeGraphVis cs = new TestTimeGraphVis();
    SpaceGraphPhys3D sg = cs.show(1400, 1000, true);
    sg.add(new SubOrtho(grid(// new AutoSurface<>(sg.dyn.broadConstraints.get(0) /* FD hack */),
    new AutoSurface<>(cs.vis))).posWindow(0, 0, 1f, 0.2f));
    cs.commit(dt());
// {
// MapNodeGraph<Object, Object> h = new MapNodeGraph<>();
// h.addEdge(h.addNode("y"), "yx", h.addNode("x"));
// 
// ObjectGraph o = new ObjectGraph(h);
// cs.commit(o);
// }
}
Also used : AutoSurface(spacegraph.space2d.widget.meta.AutoSurface) SubOrtho(spacegraph.space2d.hud.SubOrtho) SpaceGraphPhys3D(spacegraph.space3d.SpaceGraphPhys3D)

Example 4 with AutoSurface

use of spacegraph.space2d.widget.meta.AutoSurface in project narchy by automenta.

the class TrackXY method main.

public static void main(String[] args) {
    boolean nars = true;
    boolean rl = false;
    int dur = 1;
    NARS nb = new NARS().exe(new UniExec(64)).time(new CycleTime().dur(dur)).index(// new HijackConceptIndex(4 * 1024, 4)
    new CaffeineIndex(32 * 1024));
    NAR n = nb.get();
    n.termVolumeMax.set(20);
    // n.priDefault(BELIEF, 0.2f);
    // n.priDefault(GOAL, 0.5f);
    n.activationRate.set(0.2f);
    // n.forgetRate.set(0.9f);
    TrackXY t = new TrackXY(4, 4);
    n.on(t);
    int experimentTime = 8048;
    n.synch();
    if (rl) {
        new RLBooster(t, // HaiQ::new,
        HaiQae::new, // RandomAgent::new,
        1);
        t.curiosity.set(0);
    }
    if (nars) {
        // Param.DEBUG = true;
        // n.log();
        // for (String action : new String[]{"up", "down", "left", "right"}) {
        // //n.goal($.the(action), Tense.Present, 0f, 0.1f);
        // n.goal($.the(action), Tense.Present, 1f, 0.1f);
        // }
        Deriver d = new Deriver(Derivers.rules(// 1,
        1, 8, n, // "list.nal",
        "motivation.nal"), n);
        d.conceptsPerIteration.set(32);
        n.timeFocus.set(2);
        ConjClustering cjB = new ConjClustering(n, BELIEF, // (tt)->true,
        (tt) -> tt.isInput(), 4, 16);
        // ConjClustering cjG = new ConjClustering(n, GOAL,
        // (tt)->true,
        // //(tt) -> tt.isInput(),
        // 5, 16);
        // Implier ii = new Implier(t , 0, 1);
        // ArithmeticIntroduction ai = new ArithmeticIntroduction(4, n);
        window(new Gridding(new AutoSurface(d), new AutoSurface(cjB)), 400, 300);
        n.onTask(tt -> {
            if (tt instanceof DerivedTask && tt.isGoal()) {
                System.out.println(tt.proof());
            }
        });
    }
    // n.log();
    // n.startFPS(fps);
    // t.runFPS(fps);
    n.onCycle(t);
    final double[] rewardSum = { 0 };
    n.onCycle(() -> {
        rewardSum[0] += t.reward;
    });
    n.runLater(() -> {
        window(Vis.top(n), 800, 250);
        NAgentX.chart(t);
        window(new CameraSensorView(t.cam, n) {

            @Override
            protected void paint(GL2 gl, int dtMS) {
                super.paint(gl, dtMS);
                RectFloat2D at = cellRect(t.sx, t.sy, 0.5f, 0.5f);
                gl.glColor4f(1, 0, 0, 0.9f);
                Draw.rect(gl, at.move(x(), y(), 0.01f));
            }
        }.withControls(), 800, 800);
    });
    n.run(experimentTime);
// n.startFPS(10f);
// t.runFPS(10f);
// System.out.println(
// 
// n4(rewardSum[0] / n.time()) + " avg reward");
// System.exit(0);
}
Also used : HaiQae(jcog.learn.ql.HaiQae) RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) RLBooster(nars.op.RLBooster) GL2(com.jogamp.opengl.GL2) DerivedTask(nars.task.DerivedTask) UniExec(nars.exe.UniExec) CaffeineIndex(nars.index.term.map.CaffeineIndex) CameraSensorView(nars.video.CameraSensorView) CycleTime(nars.time.CycleTime) Deriver(nars.derive.Deriver) Gridding(spacegraph.space2d.container.Gridding) ConjClustering(nars.op.stm.ConjClustering) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface)

Aggregations

AutoSurface (spacegraph.space2d.widget.meta.AutoSurface)4 Loop (jcog.exe.Loop)2 HaiQae (jcog.learn.ql.HaiQae)2 XoRoShiRo128PlusRandom (jcog.math.random.XoRoShiRo128PlusRandom)2 CaffeineIndex (nars.index.term.map.CaffeineIndex)2 ConjClustering (nars.op.stm.ConjClustering)2 SpaceGraph (spacegraph.SpaceGraph)2 Gridding (spacegraph.space2d.container.Gridding)2 SubOrtho (spacegraph.space2d.hud.SubOrtho)2 SpaceGraphPhys3D (spacegraph.space3d.SpaceGraphPhys3D)2 GL2 (com.jogamp.opengl.GL2)1 java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Random (java.util.Random)1 Function (java.util.function.Function)1 IntConsumer (java.util.function.IntConsumer)1 Supplier (java.util.function.Supplier)1 Util (jcog.Util)1