Search in sources :

Example 21 with Surface

use of spacegraph.space2d.Surface in project narchy by automenta.

the class TasksView method layoutTimeline.

public void layoutTimeline() {
    final MapNodeGraph<Surface, String> graph = new MapNodeGraph();
    float tScale = 100;
    float tMin = tScale;
    for (Surface cc : children()) {
        // TODO make window content iteration method
        TaskIcon c = (TaskIcon) cc;
        Task t = c.task;
        NodeGraph.MutableNode<Surface, String> tn = graph.addNode(c);
        for (long e : t.stamp()) {
            NodeGraph.Node en = graph.node(evidences.getIfAbsentPutWithKey(e, (ee) -> {
                Surface s = new PushButton("_" + ee);
                // TODO make evidence buttons visibility toggleable
                // children.add(s);
                graph.addNode(s);
                return s;
            }));
            graph.addEdge((NodeGraph.MutableNode) en, "stamp", tn);
        }
        float minH = 30;
        float maxH = 200;
        float h = t.isQuestOrQuestion() ? Util.lerp(t.originality() / 2f, minH, maxH) : Util.lerp(t.originality() * t.conf(), minH, maxH);
        long start, end;
        if (!t.isEternal()) {
            start = t.start();
            end = t.end();
        } else {
            start = t.creation();
            // TODO max time
            end = 10;
        }
        float x1 = start * tScale;
        float x2 = end * tScale;
        if (x2 - x1 < tMin) {
            float x = (x1 + x2) / 2f;
            x1 = x - tMin / 2;
            x2 = x + tMin / 2;
        }
        float y = (float) (Math.random() * 500);
        c.pos(x1, y, x2, y + h);
    }
    graph.print();
    new Thread(() -> {
        int iterations = 300;
        for (int i = 0; i < iterations; i++) {
            layoutForceDirect(graph);
            layout();
            Util.sleep(5);
        }
    }).start();
}
Also used : NodeGraph(jcog.data.graph.NodeGraph) MutableContainer(spacegraph.space2d.container.MutableContainer) PushButton(spacegraph.space2d.widget.button.PushButton) Surface(spacegraph.space2d.Surface) IOException(java.io.IOException) MapNodeGraph(jcog.data.graph.MapNodeGraph) Util(jcog.Util) spacegraph.util.math.v2(spacegraph.util.math.v2) File(java.io.File) Task(nars.Task) TODO(jcog.TODO) Op(nars.Op) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap) SpaceGraph(spacegraph.SpaceGraph) Task(nars.Task) MapNodeGraph(jcog.data.graph.MapNodeGraph) NodeGraph(jcog.data.graph.NodeGraph) MapNodeGraph(jcog.data.graph.MapNodeGraph) Surface(spacegraph.space2d.Surface) PushButton(spacegraph.space2d.widget.button.PushButton)

Example 22 with Surface

use of spacegraph.space2d.Surface 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)

Example 23 with Surface

use of spacegraph.space2d.Surface in project narchy by automenta.

the class PhyWall method snake.

protected Snake snake(Wire wire, Runnable onRemove) {
    Surface source = wire.a;
    Surface target = wire.b;
    assert (source != target);
    float sa = source.bounds.area();
    float ta = target.bounds.area();
    float areaDiff = Math.abs(sa - ta) / (sa + ta);
    // heuristic estimate: larger area difference = shorter snake
    int segments = Util.lerp(areaDiff, 8, 6);
    float EXPAND_SCALE_FACTOR = 4;
    PushButton deleteButton = new PushButton("x");
    Surface menu = new TabPane(ButtonSet.Mode.Multi, Map.of("o", () -> new Gridding(new Label(source.toString()), new Label(target.toString()), deleteButton)), (l) -> new CheckBox(l) {

        @Override
        protected String label(String text, boolean on) {
            // override just display the 'o'
            return text;
        }

        @Override
        public ToggleButton set(boolean expanded) {
            super.set(expanded);
            synchronized (wire) {
                PhyWindow w = parent(PhyWindow.class);
                if (w == null)
                    return this;
                float cx = w.cx();
                float cy = w.cy();
                float ww, hh;
                if (expanded) {
                    // grow
                    ww = w.w() * EXPAND_SCALE_FACTOR;
                    hh = w.h() * EXPAND_SCALE_FACTOR;
                } else {
                    // shrink
                    ww = w.w() / EXPAND_SCALE_FACTOR;
                    hh = w.h() / EXPAND_SCALE_FACTOR;
                }
                w.pos(cx - ww / 2, cy - hh / 2, cx + ww / 2, cy + hh / 2);
            }
            return this;
        }
    });
    PhyWindow menuBody = put(menu, RectFloat2D.mid(source.bounds, target.bounds, 0.1f));
    float mw = menuBody.radius();
    Snake s = new Snake(source, target, segments, 1.618f * 2 * mw, mw) {

        @Override
        public void remove() {
            onRemove.run();
            super.remove();
        }
    };
    s.attach(menuBody.body, segments / 2 - 1);
    deleteButton.click(s::remove);
    int jj = 0;
    for (Joint j : s.joints) {
        float p = ((float) jj) / (segments - 1);
        // custom joint renderer: color coded indicate activity and type of data
        j.setData((ObjectLongProcedure<GL2>) (g, now) -> {
            int TIME_DECAY_MS = 250;
            boolean side = p < 0.5f;
            float activity = wire.activity(side, now, TIME_DECAY_MS);
            // Util.lerp(p, wire.activity(false, now, TIME_DECAY_MS), wire.activity(true, now, TIME_DECAY_MS));
            int th = wire.typeHash(side);
            if (th == 0) {
                g.glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
            } else {
                Draw.colorHash(g, th, 0.9f, 0.5f + 0.5f * activity, 0.5f + 0.4f * activity);
            }
            g.glLineWidth(10f + activity * 10f);
        // Draw.line(g, w.a.cx(), w.a.cy(), w.b.cx(), w.b.cy());
        // return;
        });
        jj++;
    }
    return s;
}
Also used : RayCastInput(spacegraph.space2d.phys.collision.RayCastInput) Random(java.util.Random) ParticleColor(spacegraph.space2d.phys.particle.ParticleColor) ButtonSet(spacegraph.space2d.widget.tab.ButtonSet) TabPane(spacegraph.space2d.widget.tab.TabPane) ParticleSystem(spacegraph.space2d.phys.particle.ParticleSystem) spacegraph.space2d.phys.dynamics.joints(spacegraph.space2d.phys.dynamics.joints) ToggleButton(spacegraph.space2d.widget.button.ToggleButton) Map(java.util.Map) Finger(spacegraph.input.finger.Finger) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) PolygonShape(spacegraph.space2d.phys.collision.shapes.PolygonShape) NodeGraph(jcog.data.graph.NodeGraph) CircleShape(spacegraph.space2d.phys.collision.shapes.CircleShape) MapNodeGraph(jcog.data.graph.MapNodeGraph) Util(jcog.Util) Animated(spacegraph.util.animate.Animated) List(java.util.List) ImmutableDirectedEdge(jcog.data.graph.ImmutableDirectedEdge) GL2(com.jogamp.opengl.GL2) WizardFrame(spacegraph.space2d.widget.meta.WizardFrame) ObjectLongProcedure(org.eclipse.collections.api.block.procedure.primitive.ObjectLongProcedure) Shape(spacegraph.space2d.phys.collision.shapes.Shape) PolygonFixture(spacegraph.space2d.phys.fracture.PolygonFixture) spacegraph.space2d.phys.dynamics(spacegraph.space2d.phys.dynamics) Surface(spacegraph.space2d.Surface) Draw(spacegraph.video.Draw) Supplier(java.util.function.Supplier) Tuple2f(spacegraph.util.math.Tuple2f) EdgeShape(spacegraph.space2d.phys.collision.shapes.EdgeShape) Tuples.pair(org.eclipse.collections.impl.tuple.Tuples.pair) DoubleClicking(spacegraph.input.finger.DoubleClicking) Gridding(spacegraph.space2d.container.Gridding) On(jcog.event.On) AABB(spacegraph.space2d.phys.collision.AABB) RayCastOutput(spacegraph.space2d.phys.collision.RayCastOutput) Pair(org.eclipse.collections.api.tuple.Pair) Ortho(spacegraph.space2d.hud.Ortho) PushButton(spacegraph.space2d.widget.button.PushButton) FasterList(jcog.list.FasterList) Transform(spacegraph.space2d.phys.common.Transform) spacegraph.util.math.v2(spacegraph.util.math.v2) RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) CheckBox(spacegraph.space2d.widget.button.CheckBox) Consumer(java.util.function.Consumer) ArrayIterator(jcog.util.ArrayIterator) FingerDragging(spacegraph.input.finger.FingerDragging) SurfaceBase(spacegraph.space2d.SurfaceBase) ProtoWidget(spacegraph.space2d.widget.meta.ProtoWidget) Collections(java.util.Collections) Label(spacegraph.space2d.widget.text.Label) TabPane(spacegraph.space2d.widget.tab.TabPane) ToggleButton(spacegraph.space2d.widget.button.ToggleButton) Label(spacegraph.space2d.widget.text.Label) GL2(com.jogamp.opengl.GL2) Surface(spacegraph.space2d.Surface) Gridding(spacegraph.space2d.container.Gridding) spacegraph.space2d.phys.dynamics.joints(spacegraph.space2d.phys.dynamics.joints) spacegraph.space2d.phys.dynamics(spacegraph.space2d.phys.dynamics) Collections(java.util.Collections) CheckBox(spacegraph.space2d.widget.button.CheckBox) PushButton(spacegraph.space2d.widget.button.PushButton)

Example 24 with Surface

use of spacegraph.space2d.Surface in project narchy by automenta.

the class WizardFrame method pop.

public void pop() {
    synchronized (this) {
        Surface prev = stack.removeLast();
        if (stack.isEmpty())
            backButton.hide();
        assert (prev != null);
        become(prev);
    }
}
Also used : Surface(spacegraph.space2d.Surface) EmptySurface(spacegraph.space2d.container.EmptySurface)

Aggregations

Surface (spacegraph.space2d.Surface)24 Util (jcog.Util)7 GL2 (com.jogamp.opengl.GL2)5 Gridding (spacegraph.space2d.container.Gridding)5 List (java.util.List)4 FasterList (jcog.list.FasterList)4 Label (spacegraph.space2d.widget.text.Label)4 spacegraph.util.math.v2 (spacegraph.util.math.v2)4 Draw (spacegraph.video.Draw)4 Function (java.util.function.Function)3 IntStream (java.util.stream.IntStream)3 RectFloat2D (jcog.tree.rtree.rect.RectFloat2D)3 CheckBox (spacegraph.space2d.widget.button.CheckBox)3 AutoSurface (spacegraph.space2d.widget.meta.AutoSurface)3 LoopPanel (spacegraph.space2d.widget.meta.LoopPanel)3 java.awt (java.awt)2 Collectors (java.util.stream.Collectors)2 TODO (jcog.TODO)2 MapNodeGraph (jcog.data.graph.MapNodeGraph)2 NodeGraph (jcog.data.graph.NodeGraph)2