sclass BodyOfEvidence { // values are: WithProbability(strengthOfEvidence, probabilityOfTheory) // will only hold one piece of evidence per src object Map> examples = syncMap(); double strengthSum, probabilitySum; O mutex() { ret examples; } double currentProbabilityGuess() { synchronized(mutex()) { ret doubleRatio(probabilitySum, strengthSum); } } S renderProbabilityGuess() { ret "Current probability guess (evidence count " + n2(l(examples)) + "): " + formatDouble3X(currentProbabilityGuess()) + " with strength " + formatDouble3(strengthSum); } bool hasEvidenceFromSource(Src src) { ret examples.containsKey(src); } bool addEvidence(Src src, double probabilityOfTheory, double strengthOfEvidence) { synchronized(mutex()) { if (hasEvidenceFromSource(src)) false; examples.put(src, withProbability(strengthOfEvidence, probabilityOfTheory)); probabilitySum += probabilityOfTheory*strengthOfEvidence; strengthSum += strengthOfEvidence; true; } } S toStringWithEvidence() { ret toString() + "\n\n" + pnlToString("EVIDENCE", multiMapToPairs(examples)); } }