Search in sources :

Example 1 with AspectAlign

use of spacegraph.space2d.container.AspectAlign 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 2 with AspectAlign

use of spacegraph.space2d.container.AspectAlign in project narchy by automenta.

the class Recog2D method conceptTraining.

Surface conceptTraining(BeliefVector tv, NAR nar) {
    // LinkedHashMap<TaskConcept, BeliefVector.Neuron> out = tv.out;
    Plot2D p;
    int history = 256;
    Gridding g = new Gridding(p = new Plot2D(history, Plot2D.Line).add("Reward", () -> reward), new AspectAlign(new CameraSensorView(sp, this), AspectAlign.Align.Center, sp.width, sp.height), new Gridding(beliefTableCharts(nar, List.of(tv.concepts), 16)), new Gridding(IntStream.range(0, tv.concepts.length).mapToObj(i -> new spacegraph.space2d.widget.text.Label(String.valueOf(i)) {

        @Override
        protected void paintBelow(GL2 gl) {
            Concept c = tv.concepts[i];
            BeliefVector.Neuron nn = tv.neurons[i];
            float freq, conf;
            Truth t = nar.beliefTruth(c, nar.time());
            if (t != null) {
                conf = t.conf();
                freq = t.freq();
            } else {
                conf = nar.confMin.floatValue();
                float defaultFreq = // interpret no-belief as maybe
                0.5f;
                // Float.NaN  //use NaN to force learning of negation as separate from no-belief
                freq = defaultFreq;
            }
            Draw.colorBipolar(gl, 2f * (freq - 0.5f));
            float m = 0.5f * conf;
            Draw.rect(gl, bounds);
            if (tv.verify) {
                float error = nn.error;
                if (error != error) {
                // training phase
                // Draw.rect(gl, m / 2, m / 2, 1 - m, 1 - m);
                } else {
                // verification
                // draw backgroudn/border
                // gl.glColor3f(error, 1f - error, 0f);
                // 
                // float fontSize = 0.08f;
                // gl.glColor3f(1f, 1f, 1f);
                // Draw.text(gl, c.term().toString(), fontSize, m / 2, 1f - m / 2, 0);
                // Draw.text(gl, "err=" + n2(error), fontSize, m / 2, m / 2, 0);
                }
            }
        }
    }).toArray(Surface[]::new)));
    final int[] frames = { 0 };
    onFrame(() -> {
        if (frames[0]++ % imagePeriod == 0) {
            nextImage();
        }
        redraw();
        // if (neural.get()) {
        // if (nar.time() < trainFrames) {
        outs.expect(image);
        if (neural.get()) {
            train.update(mlpLearn, mlpSupport);
        }
        p.update();
    // s.update();
    });
    return g;
}
Also used : GL2(com.jogamp.opengl.GL2) IntStream(java.util.stream.IntStream) Iterables(com.google.common.collect.Iterables) Tense(nars.time.Tense) BeliefTableChart(nars.gui.BeliefTableChart) Bitmap2DSensor(nars.util.signal.Bitmap2DSensor) nars(nars) Rectangle2D(java.awt.geom.Rectangle2D) Surface(spacegraph.space2d.Surface) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AspectAlign(spacegraph.space2d.container.AspectAlign) Draw(spacegraph.video.Draw) MLPMap(jcog.learn.MLPMap) Truth(nars.truth.Truth) Lists(com.google.common.collect.Lists) IntToFloatFunction(org.eclipse.collections.api.block.function.primitive.IntToFloatFunction) Gridding(spacegraph.space2d.container.Gridding) Plot2D(spacegraph.space2d.widget.meter.Plot2D) TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) CameraSensorView(nars.video.CameraSensorView) Term(nars.term.Term) IntFunction(java.util.function.IntFunction) BufferedImage(java.awt.image.BufferedImage) Collection(java.util.Collection) PixelBag(nars.video.PixelBag) Util(jcog.Util) java.awt(java.awt) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Scale(nars.video.Scale) SpaceGraph(spacegraph.SpaceGraph) BELIEF(nars.Op.BELIEF) Termed(nars.term.Termed) TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) GL2(com.jogamp.opengl.GL2) CameraSensorView(nars.video.CameraSensorView) Gridding(spacegraph.space2d.container.Gridding) AspectAlign(spacegraph.space2d.container.AspectAlign) Plot2D(spacegraph.space2d.widget.meter.Plot2D) Truth(nars.truth.Truth)

Aggregations

java.awt (java.awt)2 BufferedImage (java.awt.image.BufferedImage)2 Util (jcog.Util)2 BELIEF (nars.Op.BELIEF)2 Term (nars.term.Term)2 Tense (nars.time.Tense)2 Bitmap2DSensor (nars.util.signal.Bitmap2DSensor)2 SpaceGraph (spacegraph.SpaceGraph)2 Surface (spacegraph.space2d.Surface)2 AspectAlign (spacegraph.space2d.container.AspectAlign)2 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 GL2 (com.jogamp.opengl.GL2)1 Rectangle2D (java.awt.geom.Rectangle2D)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Collection (java.util.Collection)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Function (java.util.function.Function)1