// RogueViz -- SAG embedder: implementation of SAG method evaluation // Copyright (C) 2011-24 Zeno Rogue, see 'hyper.cpp' for details #include "../rogueviz.h" #include "../dhrg/dhrg.h" #include "../leastsquare.cpp" namespace rogueviz { namespace sag { enum eSagMethod { smClosest, smLogistic, smMatch }; eSagMethod method; vector method_names = {"closest", "logistic", "match"}; int method_count = 3; /* parameters for smMatch */ ld match_a = 1, match_b = 0; /* parameters for smLogistic */ dhrg::logistic lgsag(1, 1), lgsag_pre(1, 1); vector loglik_tab_y, loglik_tab_n; dhrg::logistic best; bool opt_debug = false; bool should_good = false; double costat(int vid, int sid) { if(vid < 0) return 0; double cost = 0; switch(method) { case smLogistic: { auto s = sagdist[sid]; for(auto j: edges_yes[vid]) if(sagid[j] >= -1) cost += loglik_tab_y[s[sagid[j]]]; for(auto j: edges_no[vid]) if(sagid[j] >= -1) cost += loglik_tab_n[s[sagid[j]]]; return -cost; } case smMatch: { vertexdata& vd = vdata[vid]; for(int j=0; jweight2 + match_b; ld dist = cdist - expect; cost += dist * dist; } } return cost; } case smClosest: { vertexdata& vd = vdata[vid]; for(int j=0; jweight2; } if(!hubval.empty()) { for(auto sid2: neighbors[sid]) { int vid2 = sagnode[sid2]; if(vid2 >= 0 && (hubval[vid] & hubval[vid]) == 0) cost += hub_penalty; } } return cost; } } throw hr_exception("unknwon SAG method"); } double cost; double best_cost = 1000000000; void compute_cost() { int DN = isize(sagid); cost = 0; for(int i=0; i= sag_edge->visible_from) pedge[sagdist[sagid[ei.i]][sagid[ei.j]] * mul]++; } if(opt_debug) for(int d=0; d