!636 !standard functions !quicknew abstract class Predict { abstract String predict(List<String> history); // it's passed in reverse } main { static class PLast extends Predict { String predict(List<String> history) { return history.isEmpty() ? "" : history.get(0); } } psvm { // example line: 2015-08-12 05:29:10 - http://tinybrain.de:8080/tb/my-actions.php String src = loadSnippet("#2000518"); new List<String> actions; for (String line : toLines(src)) { int i = line.indexOf(" - http:"); if (i >= 0) actions.add(line.substring(i+3).trim()); } //System.out.println(actions); new List<Predict> predictors; predictors.add(new PLast); new Collector globalCollector; for (int splitPoint = 0; splitPoint < actions.size()-1; splitPoint++) { List<String> history = actions.subList(splitPoint+1, actions.size()); String current = actions.get(splitPoint); //new Collector collector; for (Predict p : predictors) { String prediction = ""; try { prediction = p.predict(history); } catch (Throwable e) { // silent exception } int score = current.equals(prediction) ? 1 : 0; //collector.add(p, prediction, score, splitPoint); globalCollector.add(p, prediction, score, splitPoint); } } } static class Collector { new (Hash)Map<Predict, Integer> scores; void add(Predict p, String prediction, int score, int splitPoint) { Integer score = scores.get(p); score = (score == null ? 0 : score) + score; scores.put(p, score); } } }
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: | 701 / 646 |
Referenced in: | #3000190 - Answer for stefanreich(>> t 20 questions) #3000382 - Answer for ferdie (>> t = 1, f = 0) #3000383 - Answer for funkoverflow (>> t=1, f=0 okay) |