Libraryless. Click here for Pure Java version (8317L/48K).
sclass OneColorTheoryChecker { replace Cell with URecognizer.Cell. replace Theory with BodyOfEvidence<S>. new ProbabilisticScheduler scheduler; record OneColorTheory(S text, Cell cell, RGB color) > Theory { toString { ret renderProbabilityGuess() + ": " + dollarVarsMeanFields(text, this); } selfType branch(O... _) { this; } } // create the theory object and initiate the reasoning // you have to step the scheduler afterwards to get results OneColorTheory makeTheory(Cell cell) { var color = cell.averageColor(); var theory = new OneColorTheory("Color of every pixel in $cell is $color.", cell, color); testOneColorTheory(cell, theory); ret theory; } void noteCellColor(Cell cell, OneColorTheory theory) { var desc = "Pixel check at " + cell; if (theory.hasEvidenceFromSource(desc)) return; var strength = doubleRatio(cell.area(), theory.cell.area()); // how much do we have to say about the cell in the theory? var p = colorDistanceToProbability(cell.averageColor(), theory.color); addExampleToTheory(theory, desc, p, strength); } double colorDistanceToProbability(RGB col1, RGB col2) { double sim = colorSimilarity(col1, col2), sqr = sqr(sim); printFunctionCall colorDistanceToProbability(+col1, +col2, +sim, +sqr); ret sqr; } void testOneColorTheory(Cell cell, OneColorTheory theory) { noteCellColor(cell, theory); scheduler.atRelative(dontZoomTooFar(cell), r { for (var split : usefulSplits(cell)) scheduler.atRelative(split.probability(), r { for (var cell : split!) testOneColorTheory(cell, theory.branch(description := "recursion to " + cell)); }); }); } L<WithProbability<Cell[]>> usefulSplits(Cell cell) { ret map withProbability1(llNonNulls(cell.split(0, 2), cell.split(1, 2))); } // probability penalty .25 for zooming in 3 steps double dontZoomTooFar(Cell cell) { ret 0.75; } void addExampleToTheory(Theory theory, S desc, double probabilityOfTheory, double strengthOfEvidence) { theory.addEvidence(desc, probabilityOfTheory, /* scheduler.currentProbability()* */ strengthOfEvidence); } }
Began life as a copy of #1031965
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
Snippet ID: | #1031966 |
Snippet name: | OneColorTheoryChecker [dev.] |
Eternal ID of this version: | #1031966/31 |
Text MD5: | b44d29d36111a5d00d169fe230c47076 |
Transpilation MD5: | 6d7864f2b1f103202b1d7b96f782d9f1 |
Author: | stefan |
Category: | javax / image recognition |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-08-11 12:13:01 |
Source code size: | 2282 bytes / 64 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 221 / 444 |
Version history: | 30 change(s) |
Referenced in: | [show references] |