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;
}
};
}
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);
}
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);
}
}
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"));
}
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;
}
Aggregations