Libraryless. Click here for Pure Java version (4623L/30K/100K).
1 | !752 |
2 | |
3 | static BWImage bw; |
4 | static Thread producer; |
5 | static Reproducing rp; |
6 | static ImageSurface imageSurface; |
7 | |
8 | !include #1004562 // column prediction |
9 | |
10 | p { |
11 | rp = new Reproducing; |
12 | bw = loadBWImage("#1004541"); |
13 | //bw = makeTriangle(); |
14 | imageSurface = showBWImage(bw); |
15 | rp.bw = bw; |
16 | //rp.imageSurfaceToUpdateWithBest = showImage(bw.getBufferedImage()); |
17 | |
18 | //rp.startProduction = r { produce() }; |
19 | //rp.search(); |
20 | |
21 | //showColumnErrors("LookLeft(width=8)"); |
22 | |
23 | produce(); |
24 | while licensed { |
25 | S desc = grabFromQueue(rp.newProducts); |
26 | Predictor p = makePredictor(desc); |
27 | float[][] cols = rp.getCols(); |
28 | double score = testColumnRange(p, cols, 0, 15, l(cols)); |
29 | print(desc); |
30 | print(" " + score); |
31 | imageSurface.setImage(renderPrediction(desc, cols)); |
32 | } |
33 | } |
34 | |
35 | static void produce() { |
36 | cancelThread(producer); |
37 | producer = new Thread(r { |
38 | // STRATEGY! |
39 | |
40 | rp.push("RepeatColumn"); |
41 | rp.push("ShiftDown"); |
42 | rp.push("LookLeft(width=7)"); |
43 | rp.push("LookLeft(width=8)"); |
44 | rp.push("LookLeft(width=9)"); |
45 | rp.push("LookLeft(width=10)"); |
46 | }, "Producer"); |
47 | producer.start(); |
48 | } |
49 | |
50 | sclass RepeatColumn extends Predictor { |
51 | float[] nextColumn(float[] x) { |
52 | ret x; |
53 | } |
54 | } |
55 | |
56 | sclass ShiftDown extends Predictor { |
57 | float[] nextColumn(float[] f) { |
58 | if (f == null) null; |
59 | float[] g = copyColumn(f); |
60 | for (int i = 1; i < l(f); i++) |
61 | g[i] = f[i-1]; |
62 | ret g; |
63 | } |
64 | } |
65 | |
66 | sclass LookLeft extends Predictor { |
67 | int width; // how far to look left |
68 | float[][] buf; |
69 | int x; |
70 | |
71 | float[] nextColumn(float[] f) { |
72 | if (f == null) null; |
73 | if (buf == null) buf = new float[width][]; |
74 | |
75 | // exchange with data in rotating buffer |
76 | // (will return null until buffer is filled) |
77 | float[] g = buf[x]; |
78 | buf[x] = f; |
79 | x = (x+1) % width; |
80 | ret g; |
81 | } |
82 | } |
83 | |
84 | static BWImage makeTriangle() { |
85 | int w = 30, h = w; |
86 | BWImage img = new BWImage(w, h); |
87 | for y to h: for x to w: |
88 | img.setPixel(x, y, x < y ? 1 : 0); |
89 | ret img; |
90 | } |
Began life as a copy of #1004557
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004563 |
Snippet name: | Try Column Prediction |
Eternal ID of this version: | #1004563/1 |
Text MD5: | 58453f505b4167539312981bf707b68b |
Transpilation MD5: | 137f953a4b0f3610bb7559aaf22788e0 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-08-21 16:22:54 |
Source code size: | 2048 bytes / 90 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 543 / 679 |
Referenced in: | [show references] |