Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1032075 // BodyOfEvidence

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4525L/24K).

sclass BodyOfEvidence<Src> {
  // values are: WithProbability(strengthOfEvidence, probabilityOfTheory)
  // will only hold one piece of evidence per src object
  Map<Src, WithProbability<Double>> 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(mapToList(examples, (src, e) ->
        (e! == 0.5 ? "     " : e! > 0.5 ? "   PRO" : " CONTRA")
        + ": " + e + " - " + src));
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032075
Snippet name: BodyOfEvidence
Eternal ID of this version: #1032075/7
Text MD5: 3812ad1f1ee049d3ffcd54ca7d27149f
Transpilation MD5: 4d458bd20abeb258f2cdd9fab0e58762
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-11 12:14:04
Source code size: 1332 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 189 / 351
Version history: 6 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)