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

59
LINES

< > BotCompany Repo | #1005875 // Distinguisher - works on a set of analyzer functions returning a float

JavaX fragment (include)

1  
sclass Distinguisher {
2  
  new TreeMap<S, O> functions;
3  
  bool verbose;
4  
  
5  
  // function -> ranges in same order as objects
6  
  Map<S, L<Range>> rangesByFunction = new TreeMap;
7  
  
8  
  void addFunction(S name, O f) {
9  
    functions.put(name, f);
10  
  }
11  
12  
  // index = class index of this object (0 or 1)
13  
  // object = the object to analyze using the functions
14  
  void analyze(int index, O object) {
15  
    for (S fname : keys(functions)) {
16  
      O f = functions.get(fname);
17  
      L<Range> l = rangesByFunction.get(fname);
18  
      if (l == null)
19  
        rangesByFunction.put(fname, l = new L);
20  
      float val = 0f;
21  
      try {
22  
        val = toFloat(callF(f, object));
23  
      } catch e { printShortException(e); }
24  
      if (verbose)
25  
        print(fname + " " + index + " => " + val);
26  
      listSet(l, index, addToRange(get(l, index), val), null);
27  
    }
28  
  }
29  
  
30  
  void analyze(L objects) {
31  
    for i over objects: analyze(i, objects.get(i));
32  
  }
33  
  
34  
  bool good() {
35  
    ret quality() > 0;
36  
  }
37  
  
38  
  L<S> goodDiscriminators() {
39  
    ret [S f in keys(rangesByFunction) | isGoodDiscriminator(f)];
40  
  }
41  
  
42  
  // quality = number of working discriminators
43  
  int quality() {
44  
    ret l(goodDiscriminators());
45  
  }
46  
  
47  
  bool isGoodDiscriminator(S f) {
48  
    ret !rangesOverlap(rangesByFunction.get(f));
49  
  }
50  
  
51  
  void printStuff() {
52  
    for (S key : keys(rangesByFunction)) {
53  
      if (isGoodDiscriminator(key))
54  
        print("good! " + key);
55  
      else
56  
        print("bad: " + key);
57  
    }
58  
  }
59  
}

Author comment

Began life as a copy of #1005852

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: #1005875
Snippet name: Distinguisher - works on a set of analyzer functions returning a float
Eternal ID of this version: #1005875/2
Text MD5: 0d87e72a502872ae56d95a68be0bffd6
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-08-14 02:25:47
Source code size: 1514 bytes / 59 lines
Pitched / IR pitched: No / No
Views / Downloads: 505 / 853
Version history: 1 change(s)
Referenced in: [show references]