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)

sclass Distinguisher {
  new TreeMap<S, O> functions;
  bool verbose;
  
  // function -> ranges in same order as objects
  Map<S, L<Range>> rangesByFunction = new TreeMap;
  
  void addFunction(S name, O f) {
    functions.put(name, f);
  }

  // index = class index of this object (0 or 1)
  // object = the object to analyze using the functions
  void analyze(int index, O object) {
    for (S fname : keys(functions)) {
      O f = functions.get(fname);
      L<Range> l = rangesByFunction.get(fname);
      if (l == null)
        rangesByFunction.put(fname, l = new L);
      float val = 0f;
      try {
        val = toFloat(callF(f, object));
      } catch e { printShortException(e); }
      if (verbose)
        print(fname + " " + index + " => " + val);
      listSet(l, index, addToRange(get(l, index), val), null);
    }
  }
  
  void analyze(L objects) {
    for i over objects: analyze(i, objects.get(i));
  }
  
  bool good() {
    ret quality() > 0;
  }
  
  L<S> goodDiscriminators() {
    ret [S f in keys(rangesByFunction) | isGoodDiscriminator(f)];
  }
  
  // quality = number of working discriminators
  int quality() {
    ret l(goodDiscriminators());
  }
  
  bool isGoodDiscriminator(S f) {
    ret !rangesOverlap(rangesByFunction.get(f));
  }
  
  void printStuff() {
    for (S key : keys(rangesByFunction)) {
      if (isGoodDiscriminator(key))
        print("good! " + key);
      else
        print("bad: " + key);
    }
  }
}

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: 563 / 917
Version history: 1 change(s)
Referenced in: [show references]