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

42
LINES

< > BotCompany Repo | #1034534 // AIC_EvaluateParameter

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

Transpiled version (15031L) is out of date.

// A = parameter type
srecord noeq AIC_EvaluateParameter<A>(
  S parameterName,
  Cl<A> parameterValues,
  IVF2<A, AdaptiveIdentifierCompression> applyParameter) {
  
  new AICDemo demo;
  new Map<A, Int> scores;
  new LL<PairS> tokenByToken;
  
  run {
    fOr (param : parameterValues) {
      demo.adapt = aic -> applyParameter.get(param, aic);
      int l = l(demo.compress());
      tokenByToken.add(demo.tokenByToken);
      printVars(+param, +l, escapeWordsUsed := demo.aicComp.escapeWordsUsed);
      demo.decompress();
      if (!demo.decompressedOK)
        fail(parameterName + "=" + param + " breaks the algorithm");
      scores.put(param, l);
    }
    
    printScores();
  }
  
  void printScores {
    print("Best values for " + parameterName + ":");
    pnl(mapSortedByValue(scores));
  }
  
  void printTokenByTokenDiffs(bool printSameLengthEncodings default false) {
    LL<PairS> transposed = transpose(tokenByToken);
    for i over transposed: {
      LPairS row = transposed.get(i);
      LS encodings = pairsB(row);
      S token = pairA(first(row));
      
      if (!printSameLengthEncodings && allEq(map l(encodings))) continue;
      print("Token " + i + ": " + quote(token) + " => " + sfu(encodings));
    }
  }
}

Author comment

Began life as a copy of #1034373

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034534
Snippet name: AIC_EvaluateParameter
Eternal ID of this version: #1034534/11
Text MD5: 3d9df94561f2d17ea280c5ee26ee86f0
Author: stefan
Category: javax / compressing text
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-11 21:07:32
Source code size: 1283 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 188 / 292
Version history: 10 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)