!752 static BWImage bw; static Thread producer; static Reproducing rp; static ImageSurface imageSurface; !include #1004562 // column prediction p { rp = new Reproducing; bw = loadBWImage("#1004541"); //bw = makeTriangle(); imageSurface = showBWImage(bw); rp.bw = bw; //rp.imageSurfaceToUpdateWithBest = showImage(bw.getBufferedImage()); //rp.startProduction = r { produce() }; //rp.search(); //showColumnErrors("LookLeft(width=8)"); produce(); while licensed { S desc = grabFromQueue(rp.newProducts); Predictor p = makePredictor(desc); float[][] cols = rp.getCols(); double score = testColumnRange(p, cols, 0, 15, l(cols)); print(desc); print(" " + score); imageSurface.setImage(renderPrediction(desc, cols)); } } static void produce() { cancelThread(producer); producer = new Thread(r { // STRATEGY! rp.push("RepeatColumn"); rp.push("ShiftDown"); rp.push("LookLeft(width=7)"); rp.push("LookLeft(width=8)"); rp.push("LookLeft(width=9)"); rp.push("LookLeft(width=10)"); }, "Producer"); producer.start(); } sclass RepeatColumn extends Predictor { float[] nextColumn(float[] x) { ret x; } } sclass ShiftDown extends Predictor { float[] nextColumn(float[] f) { if (f == null) null; float[] g = copyColumn(f); for (int i = 1; i < l(f); i++) g[i] = f[i-1]; ret g; } } sclass LookLeft extends Predictor { int width; // how far to look left float[][] buf; int x; float[] nextColumn(float[] f) { if (f == null) null; if (buf == null) buf = new float[width][]; // exchange with data in rotating buffer // (will return null until buffer is filled) float[] g = buf[x]; buf[x] = f; x = (x+1) % width; ret g; } } static BWImage makeTriangle() { int w = 30, h = w; BWImage img = new BWImage(w, h); for y to h: for x to w: img.setPixel(x, y, x < y ? 1 : 0); ret img; }