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

15
LINES

< > BotCompany Repo | #1030110 // chiSquared_histogramsWithSum1

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

Libraryless. Click here for Pure Java version (2571L/16K).

// returns 0 for identical, 1 for completely different
static <A> double chiSquared_histogramsWithSum1(Map<A, Double> map1, Map<A, Double> map2) {
  if (empty(map1) || empty(map2)) ret Double.NaN;
  double sum = 0;
  for (A key : joinSets(keys(map1), keys(map2))) {
    double mi = or0(map1.get(key));
    double ni = or0(map2.get(key));
    double item = sqr(ni-mi)/(mi+ni);
    ifdef chiSquared_histogramsWithSum1_debug
      printVars_str(+key, +mi, +ni, +item);
    endifdef
    sum += item;
  }
  ret sum/2;
}

Author comment

Began life as a copy of #1030107

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030110
Snippet name: chiSquared_histogramsWithSum1
Eternal ID of this version: #1030110/6
Text MD5: 1e062e0920d5e60bb79834991cbad836
Transpilation MD5: 62a2cbdfed8f2c67eb4f49517f51b4ec
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-09 12:56:05
Source code size: 530 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 217 / 292
Version history: 5 change(s)
Referenced in: [show references]