1 | !636 |
2 | !standard functions |
3 | !quicknew |
4 | |
5 | abstract class Predict {
|
6 | abstract String predict(List<String> history); // it's passed in reverse |
7 | } |
8 | |
9 | main {
|
10 | static class PLast extends Predict {
|
11 | String predict(List<String> history) {
|
12 | return history.isEmpty() ? "" : history.get(0); |
13 | } |
14 | } |
15 | |
16 | psvm {
|
17 | // example line: 2015-08-12 05:29:10 - http://tinybrain.de:8080/tb/my-actions.php |
18 | String src = loadSnippet("#2000518");
|
19 | new List<String> actions; |
20 | for (String line : toLines(src)) {
|
21 | int i = line.indexOf(" - http:");
|
22 | if (i >= 0) |
23 | actions.add(line.substring(i+3).trim()); |
24 | } |
25 | |
26 | //System.out.println(actions); |
27 | |
28 | new List<Predict> predictors; |
29 | predictors.add(new PLast); |
30 | |
31 | new Collector globalCollector; |
32 | |
33 | for (int splitPoint = 0; splitPoint < actions.size()-1; splitPoint++) {
|
34 | List<String> history = actions.subList(splitPoint+1, actions.size()); |
35 | String current = actions.get(splitPoint); |
36 | //new Collector collector; |
37 | for (Predict p : predictors) {
|
38 | String prediction = ""; |
39 | try {
|
40 | prediction = p.predict(history); |
41 | } catch (Throwable e) {
|
42 | // silent exception |
43 | } |
44 | |
45 | int score = current.equals(prediction) ? 1 : 0; |
46 | //collector.add(p, prediction, score, splitPoint); |
47 | globalCollector.add(p, prediction, score, splitPoint); } |
48 | } |
49 | } |
50 | |
51 | static class Collector {
|
52 | new (Hash)Map<Predict, Integer> scores; |
53 | |
54 | void add(Predict p, String prediction, int score, int splitPoint) {
|
55 | Integer score = scores.get(p); |
56 | score = (score == null ? 0 : score) + score; |
57 | scores.put(p, score); |
58 | } |
59 | |
60 | } |
61 | } |
Began life as a copy of #1000563
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1000564 |
| Snippet name: | Predict actions from history (developing) |
| Eternal ID of this version: | #1000564/1 |
| Text MD5: | e4e53c59d052767f18894c25a3e6b59e |
| Author: | stefan |
| Category: | |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-08-14 18:03:18 |
| Source code size: | 1757 bytes / 61 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 944 / 900 |
| Referenced in: | [show references] |