// analyze the SOM test results // Copyright (C) 2011-2022 Tehora and Zeno Rogue, see 'hyper.cpp' for details #include "kohonen.h" namespace rogueviz { namespace kohonen_test { extern string cg(); extern int data_scale, embed_scale; extern int subdata_value; } double UNKNOWN_RESULT = -3; using namespace kohonen_test; namespace analyzer { using measures::manidata; using measures::MCOUNT; struct maniset { vector names; map mdata; }; maniset origs, embs; void load_maniset(maniset& m, int scale) { FILE *f = fopen((som_test_dir + "edgelists-" + its(scale) + ".txt").c_str(), "r"); while(true) { char buf[200]; if(fscanf(f, "%s", buf) <= 0) break; if(buf[0] != '#') m.names.push_back(buf); auto& md = m.mdata[buf]; int N, M; hr::ignore(fscanf(f, "%d%d", &N, &M)); println(hlog, "reading ", buf, " of size ", N, " and ", M, " edges"); md.size = N; auto& ed = md.edges; for(int i=0; i > vor_edges; void analyze_test() { println(hlog, "loading original manifolds"); load_maniset(origs, data_scale); println(hlog, "loading embedding manifolds"); load_maniset(embs, embed_scale); map>> results; string tablefile = som_test_dir + "table" + cg() + ".csv"; if(1) { fhstream res(tablefile, "rt"); if(!res.f) { println(hlog, "table ", tablefile, " missing"); } else { println(hlog, "reading the old table ", tablefile); string s = scanline(res); while(true) { s = scanline(res); if(s == "") break; int i = 0; while(s[i] != ';') i++; i++; while(s[i] != ';') i++; i++; int id; sscanf(s.c_str()+i, "%d", &id); auto& res = results[s.substr(0, i-1)][id]; for(auto& d: res) d = UNKNOWN_RESULT; sscanf(s.c_str()+i, "%d;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf;%lf", &id, &res[0], &res[1], &res[2], &res[3], &res[4], &res[5], &res[6], &res[7], &res[8], &res[9], &res[10], &res[11]); } } } for(string orig: origs.names) { string dir = som_test_dir + "pairs" + cg(); for(string emb: embs.names) { string fname = dir + "/" + orig + "-" + emb + ".txt"; if(!file_exists(fname)) continue; FILE *f = fopen(fname.c_str(), "rt"); string vorname = dir + "/" + orig + "-" + emb + ".vor"; if(!file_exists(vorname)) continue; FILE *vor = fopen(vorname.c_str(), "rt"); int No = origs.mdata[orig].size; auto& edo = origs.mdata[orig].edges; vector> edo_recreated; int new_results = 0; int current_row = -1; auto& res1 = results[orig + ";" + emb]; for(int it=0; it<100; it++) { bool know_result = res1.count(it); auto& res = res1[it]; if(!know_result) for(int kk=0; kk mapp(No, -2); for(int k=0; k 1e-5) { println(hlog, "ERROR in ", orig, "->", emb, " in ", cg(), " index ", it, " : was ", res[k], " is ", energy); if(subdata_value) res[k] = energy; } } else { res[k] = energy; } } } } next_pair: fclose(f); if(new_results) println(hlog, "computed ", new_results, " new results in ", cg(), " for ", orig, " -> ", emb); } } fhstream o(som_test_dir + "summary" + cg() + ".html", "wt"); println(o, "\n"); if(1) { println(o, "\n"); int manis = 0; for(string orig: origs.names) { print(o, ""); for(string emb: embs.names) print(o, ""); print(o, "\n"); for(int k: {0, 2, 4, 7, 8, 10, 11}) { print(o, ""); for(string emb: embs.names) { ld tenergy = 0; int att = 0; auto& res1 = results[orig + ";" + emb]; for(int it=0; it<100; it++) { if(!res1.count(it)) continue; auto& res = res1[it]; if(res[k] == UNKNOWN_RESULT) continue; att++; tenergy += res[k]; } if(orig == emb) print(o, ""); } print(o, "\n"); } manis++; } print(o, "
", orig, "", emb, "
", measures::catnames[k], ""); else if(manis & 1) print(o, ""); else print(o, ""); if(att == 100) print(o, tenergy * 1. / att); else if(att) print(o, tenergy * 1. / att, "?"); else print(o, "???"); print(o, "
\n"); } print(o, "\n"); fhstream res(som_test_dir + "table" + cg() + ".csv", "wt"); print(res, "orig;emb;index"); for(int i=0; i