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).

1  
sclass BodyOfEvidence<Src> {
2  
  // values are: WithProbability(strengthOfEvidence, probabilityOfTheory)
3  
  // will only hold one piece of evidence per src object
4  
  Map<Src, WithProbability<Double>> examples = syncMap();
5  
  double strengthSum, probabilitySum;
6  
  
7  
  O mutex() { ret examples; }
8  
  
9  
  double currentProbabilityGuess() {
10  
    synchronized(mutex()) {
11  
      ret doubleRatio(probabilitySum, strengthSum);
12  
    }
13  
  }
14  
  
15  
  S renderProbabilityGuess() {
16  
    ret "Current probability guess (evidence count " + n2(l(examples)) + "): " + formatDouble3X(currentProbabilityGuess()) + " with strength " + formatDouble3(strengthSum);
17  
  }
18  
  
19  
  bool hasEvidenceFromSource(Src src) { ret examples.containsKey(src); }
20  
  
21  
  bool addEvidence(Src src, double probabilityOfTheory, double strengthOfEvidence) {
22  
    synchronized(mutex()) {
23  
      if (hasEvidenceFromSource(src)) false;
24  
      examples.put(src, withProbability(strengthOfEvidence, probabilityOfTheory));
25  
      probabilitySum += probabilityOfTheory*strengthOfEvidence;
26  
      strengthSum += strengthOfEvidence;
27  
      true;
28  
    }
29  
  }
30  
  
31  
  S toStringWithEvidence() {
32  
    ret toString() + "\n\n"
33  
      + pnlToString(mapToList(examples, (src, e) ->
34  
        (e! == 0.5 ? "     " : e! > 0.5 ? "   PRO" : " CONTRA")
35  
        + ": " + e + " - " + src));
36  
  }
37  
}

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: 119 / 259
Version history: 6 change(s)
Referenced in: [show references]