Search in sources :

Example 6 with Gridding

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

the class ExampleBackgroundRemovalStationary method main.

public static void main(String[] args) {
    WebCam c = new WebCam();
    Tex output = new Tex();
    SpaceGraph.window(new Gridding(c.view(), output.view()), 800, 800);
    // String fileName = UtilIO.pathExample("background/horse_jitter.mp4"); // degraded performance because of jitter
    // String fileName = UtilIO.pathExample("tracking/chipmunk.mjpeg"); // Camera moves.  Stationary will fail here
    // Comment/Uncomment to switch input image type
    ImageType imageType = ImageType.single(GrayF32.class);
    // ImageType imageType = ImageType.il(3, InterleavedF32.class);
    // ImageType imageType = ImageType.il(3, InterleavedU8.class);
    // Configuration for Gaussian model.  Note that the threshold changes depending on the number of image bands
    // 12 = gray scale and 40 = color
    ConfigBackgroundGaussian configGaussian = new ConfigBackgroundGaussian(40, 0.0005f);
    configGaussian.initialVariance = 100;
    configGaussian.minimumDifference = 10f;
    // Comment/Uncomment to switch algorithms
    BackgroundModelStationary background = // FactoryBackgroundModel.stationaryBasic(new ConfigBackgroundBasic(35, 0.005f), imageType);
    FactoryBackgroundModel.stationaryGaussian(configGaussian, imageType);
    // Declare storage for segmented image.  1 = moving foreground and 0 = background
    GrayU8 segmented = new GrayU8(c.width, c.height);
    GrayF32 input = new GrayF32(c.width, c.height);
    BufferedImage segmentedVis = new BufferedImage(c.width, c.height, BufferedImage.TYPE_INT_RGB);
    new Loop(10f) {

        @Override
        public boolean next() {
            BufferedImage img = c.image;
            if (img != null) {
                ConvertBufferedImage.convertFrom(img, input, true);
                // long before = System.nanoTime();
                background.segment(input, segmented);
                background.updateBackground(input);
                byte[] b = segmented.data;
                for (int i = 0; i < b.length; i++) {
                    if (b[i] != 0)
                        b[i] = 127;
                }
                output.update(// segmented
                ConvertBufferedImage.convertTo(segmented, segmentedVis));
            }
            // }
            return true;
        }
    };
}
Also used : Loop(jcog.exe.Loop) Gridding(spacegraph.space2d.container.Gridding) BackgroundModelStationary(boofcv.alg.background.BackgroundModelStationary) GrayF32(boofcv.struct.image.GrayF32) Tex(spacegraph.video.Tex) WebCam(spacegraph.video.WebCam) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ImageType(boofcv.struct.image.ImageType) ConfigBackgroundGaussian(boofcv.factory.background.ConfigBackgroundGaussian)

Example 7 with Gridding

use of spacegraph.space2d.container.Gridding 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 8 with Gridding

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

the class TensorRL1 method noiseChip.

static void noiseChip(PhyWall p) {
    {
        final Random rng = new XoRoShiRo128PlusRandom(1);
        final TensorFunc randomVector = Tensor.randomVectorGauss(16, 0, 1, rng);
        final FloatRange lerpRate = new FloatRange(0.01f, 0, 1f);
        final TensorLERP lerpVector = new TensorLERP(randomVector, lerpRate);
        p.put(new Gridding(0.25f, // ),
        new LabeledPane("rng", new AutoUpdateMatrixView(lerpVector.data)), new LabeledPane("lerp", new XYSlider().on((x, y) -> {
            lerpRate.set(x);
        })), new LabeledPane("out", new Port() {

            @Override
            public void prePaint(int dtMS) {
                super.prePaint(dtMS);
                lerpVector.update();
                out(lerpVector.data);
            }
        })), 0.5f, 0.5f);
    }
}
Also used : Gridding(spacegraph.space2d.container.Gridding) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) Random(java.util.Random) XoRoShiRo128PlusRandom(jcog.math.random.XoRoShiRo128PlusRandom) TensorFunc(jcog.math.tensor.TensorFunc) AutoUpdateMatrixView(spacegraph.space2d.widget.meter.AutoUpdateMatrixView) XYSlider(spacegraph.space2d.widget.slider.XYSlider) FloatRange(jcog.math.FloatRange) Port(spacegraph.space2d.widget.windo.Port) LabeledPane(spacegraph.space2d.widget.text.LabeledPane) TensorLERP(jcog.math.tensor.TensorLERP)

Example 9 with Gridding

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

the class GUI method main.

public static void main(String[] args) throws IOException, Narsese.NarseseException {
    NAR nar = NARchy.ui();
    // 10hz alpha
    Loop loop = nar.startFPS(10f);
    // ((NARLoop) loop).throttle.set(0.1f);
    // 1. try to open a Spacegraph openGL window
    logger.info("start SpaceGraph UI");
    // window(new ConsoleTerminal(new TextUI(nar).session(8f)) {
    // {
    // Util.pause(50); term.addInput(KeyStroke.fromString("<pageup>")); //HACK trigger redraw
    // }
    // }, 800, 600);
    PhyWall w = SpaceGraph.wall(800, 600);
    ((ZoomOrtho) w.root()).scaleMin = 100f;
    ((ZoomOrtho) w.root()).scaleMax = 1500;
    w.put(new Gridding(new OmniBox()), 6, 1);
    w.put(Vis.top(nar), 4, 4);
// nar.inputNarsese(new FileInputStream("/home/me/d/sumo_merge.nal"));
}
Also used : Loop(jcog.exe.Loop) Gridding(spacegraph.space2d.container.Gridding) PhyWall(spacegraph.space2d.widget.windo.PhyWall) OmniBox(spacegraph.space2d.widget.meta.OmniBox)

Example 10 with Gridding

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

the class ExeCharts method metaGoalControls.

public static Surface metaGoalControls(NAR n) {
    CheckBox auto = new CheckBox("Auto");
    auto.set(false);
    float[] want = n.emotion.want;
    Gridding g = grid(// Stream.of(auto),
    IntStream.range(0, want.length).mapToObj(w -> new FloatSlider(want[w], -1f, +1f) {

        @Override
        protected void paintWidget(GL2 gl, RectFloat2D bounds) {
            if (auto.on()) {
                value(want[w]);
            }
        }
    }.text(MetaGoal.values()[w].name()).type(BaseSlider.Knob).on((s, v) -> {
        if (!auto.on())
            want[w] = v;
    })).toArray(Surface[]::new));
    return g;
}
Also used : GL2(com.jogamp.opengl.GL2) IntStream(java.util.stream.IntStream) BaseSlider(spacegraph.space2d.widget.slider.BaseSlider) DurService(nars.control.DurService) Causable(nars.exe.Causable) Surface(spacegraph.space2d.Surface) TreeChart(spacegraph.space2d.widget.meter.TreeChart) StringUtils(org.apache.commons.lang3.StringUtils) Draw(spacegraph.video.Draw) Function(java.util.function.Function) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface) Traffic(nars.control.Traffic) Gridding(spacegraph.space2d.container.Gridding) BitmapMatrixView(spacegraph.space2d.widget.meter.BitmapMatrixView) FloatSlider(spacegraph.space2d.widget.slider.FloatSlider) NAgent(nars.NAgent) FasterList(jcog.list.FasterList) FloatRange(jcog.math.FloatRange) nars.$(nars.$) LoopPanel(spacegraph.space2d.widget.meta.LoopPanel) Collectors(java.util.stream.Collectors) Util(jcog.Util) RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) CheckBox(spacegraph.space2d.widget.button.CheckBox) List(java.util.List) Splitting(spacegraph.space2d.container.Splitting) NAR(nars.NAR) Cause(nars.control.Cause) MetaGoal(nars.control.MetaGoal) FloatFunction(org.eclipse.collections.api.block.function.primitive.FloatFunction) Label(spacegraph.space2d.widget.text.Label) Gridding(spacegraph.space2d.container.Gridding) CheckBox(spacegraph.space2d.widget.button.CheckBox) FloatSlider(spacegraph.space2d.widget.slider.FloatSlider) RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) GL2(com.jogamp.opengl.GL2) Surface(spacegraph.space2d.Surface) AutoSurface(spacegraph.space2d.widget.meta.AutoSurface)

Aggregations

Gridding (spacegraph.space2d.container.Gridding)14 GL2 (com.jogamp.opengl.GL2)4 List (java.util.List)4 Util (jcog.Util)4 Loop (jcog.exe.Loop)4 Surface (spacegraph.space2d.Surface)4 AutoSurface (spacegraph.space2d.widget.meta.AutoSurface)4 Random (java.util.Random)3 FloatRange (jcog.math.FloatRange)3 XoRoShiRo128PlusRandom (jcog.math.random.XoRoShiRo128PlusRandom)3 RectFloat2D (jcog.tree.rtree.rect.RectFloat2D)3 Label (spacegraph.space2d.widget.text.Label)3 Draw (spacegraph.video.Draw)3 BufferedImage (java.awt.image.BufferedImage)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IntStream (java.util.stream.IntStream)2 HaiQae (jcog.learn.ql.HaiQae)2 FasterList (jcog.list.FasterList)2 TensorLERP (jcog.math.tensor.TensorLERP)2 CheckBox (spacegraph.space2d.widget.button.CheckBox)2