Search in sources :

Example 1 with RectFloat2D

use of jcog.tree.rtree.rect.RectFloat2D in project narchy by automenta.

the class Ortho method unzoom.

@Override
public void unzoom() {
    synchronized (zoomStack) {
        if (!zoomStack.isEmpty()) {
            RectFloat2D z = zoomStack.removeLast().get();
            scale(z.w, z.h);
            cam.set(z.cx(), z.cy());
        }
    }
}
Also used : RectFloat2D(jcog.tree.rtree.rect.RectFloat2D)

Example 2 with RectFloat2D

use of jcog.tree.rtree.rect.RectFloat2D 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)

Example 3 with RectFloat2D

use of jcog.tree.rtree.rect.RectFloat2D in project narchy by automenta.

the class Ortho method zoom.

@Override
public void zoom(Surface su) {
    synchronized (zoomStack) {
        // /if (!zoomStack.isEmpty()) {
        // if (!zoomStack.getLast().contains(nextZoom)) {
        // zoomStack.clear();
        /*                } else */
        RectFloat2D target;
        // if (!zoomStack.isEmpty() && zoomStack.getLast().gfinger.touching==su) { //zoomStack.size()>1 && zoomStack.getLast().get().equals(su.bounds /* TODO maybe fuzzy equals */)) {
        // zoomStack.removeLast();
        // target = zoomStack.getLast().get();
        // } else {
        {
            if (zoomStack.size() > ZOOM_STACK_MAX) {
                zoomStack.removeFirst();
            }
            // }
            float s = scale.x;
            RectFloat2D curZoom = new RectFloat2D(cam.x - s / 2, cam.y - s / 2, cam.x + s / 2, cam.y + s / 2);
            zoomStack.addLast(() -> curZoom);
            target = su.bounds;
        }
        zoom(target);
    }
}
Also used : RectFloat2D(jcog.tree.rtree.rect.RectFloat2D)

Example 4 with RectFloat2D

use of jcog.tree.rtree.rect.RectFloat2D in project narchy by automenta.

the class Finger method relative.

public static v2 relative(v2 x, Surface c) {
    v2 y = new v2(x);
    RectFloat2D b = c.bounds;
    y.sub(b.x, b.y);
    y.scaled(1f / b.w, 1f / b.h);
    return y;
}
Also used : RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) spacegraph.util.math.v2(spacegraph.util.math.v2)

Example 5 with RectFloat2D

use of jcog.tree.rtree.rect.RectFloat2D in project narchy by automenta.

the class SubOrtho method posWindow.

// public void maximize() {
// 
// posWindow(0, 0, 1, 1);
// }
/**
 * position and size relative to the containing window (1=width, 1=height)
 */
public Ortho posWindow(float x, float y, float w, float h) {
    this.boundsWin = new RectFloat2D(x, y, w, h);
    layout();
    return this;
}
Also used : RectFloat2D(jcog.tree.rtree.rect.RectFloat2D)

Aggregations

RectFloat2D (jcog.tree.rtree.rect.RectFloat2D)8 GL2 (com.jogamp.opengl.GL2)2 Gridding (spacegraph.space2d.container.Gridding)2 AutoSurface (spacegraph.space2d.widget.meta.AutoSurface)2 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 HaiQae (jcog.learn.ql.HaiQae)1 FasterList (jcog.list.FasterList)1 FloatRange (jcog.math.FloatRange)1 nars.$ (nars.$)1 NAR (nars.NAR)1 NAgent (nars.NAgent)1 Cause (nars.control.Cause)1 DurService (nars.control.DurService)1 MetaGoal (nars.control.MetaGoal)1 Traffic (nars.control.Traffic)1 Deriver (nars.derive.Deriver)1