mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2026-05-14 10:12:11 +00:00
embeddings:: full_evaluation now records data
This commit is contained in:
@@ -10,21 +10,24 @@ int count_directed_edges() {
|
||||
return M;
|
||||
}
|
||||
|
||||
evaltype eval;
|
||||
|
||||
void full_evaluation() {
|
||||
|
||||
println(hlog, "evaluating embedding: " + current->name());
|
||||
eval.current = true;
|
||||
|
||||
try {
|
||||
ld maxradius = 0;
|
||||
for(int i=0; i<isize(rogueviz::vdata); i++) maxradius = max(maxradius, current->zero_distance(i));
|
||||
println(hlog, "maximum radius = ", maxradius);
|
||||
eval.maxradius = 0;
|
||||
for(int i=0; i<get_n(); i++) eval.maxradius = max(eval.maxradius, current->zero_distance(i));
|
||||
println(hlog, "maximum radius = ", eval.maxradius);
|
||||
}
|
||||
catch(hr_exception&) {}
|
||||
|
||||
bool symmetric = count_directed_edges() == 2 * isize(edgeinfos);
|
||||
if(symmetric) full_routing();
|
||||
continuous_ranks();
|
||||
analyze_mdl_symmetric(symmetric);
|
||||
eval.symmetric = count_directed_edges() == 2 * isize(edgeinfos);
|
||||
if(eval.symmetric) eval.routing = full_routing();
|
||||
eval.rank = continuous_ranks();
|
||||
eval.li = analyze_mdl_symmetric(eval.symmetric);
|
||||
}
|
||||
|
||||
struct abstract_embedding : embedding {
|
||||
|
||||
@@ -92,11 +92,13 @@ void force_rvgraph() {
|
||||
}
|
||||
|
||||
void reenable_embedding() {
|
||||
eval.current = false;
|
||||
if(rogueviz::rv_quality >= 1 && among(current->get_dimension(), 2, 3) && current->get_dimension() <= WDIM) force_rvgraph();
|
||||
}
|
||||
|
||||
void enable_embedding(std::shared_ptr<embedding> pe) {
|
||||
current = std::move(pe);
|
||||
eval.current = false;
|
||||
reenable_embedding();
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,26 @@ int count_directed_edges();
|
||||
|
||||
void read_edgelist(const string& fn);
|
||||
void read_polar(const string& fn);
|
||||
|
||||
struct rankinfo {
|
||||
ld ranks = 0, rby = 0, map = 0, n = 0;
|
||||
};
|
||||
|
||||
struct loglik_info {
|
||||
ld loglik, control;
|
||||
long long N, N1, M;
|
||||
bool symmetric;
|
||||
};
|
||||
|
||||
extern struct evaltype {
|
||||
bool current;
|
||||
ld maxradius;
|
||||
iddata routing;
|
||||
rankinfo rank;
|
||||
loglik_info li;
|
||||
bool symmetric;
|
||||
} eval;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace rogueviz {
|
||||
|
||||
namespace embeddings {
|
||||
|
||||
void continuous_ranks() {
|
||||
ld tot_ranks = 0, tot_rby = 0, tot_map = 0, tot_n = 0;
|
||||
rankinfo continuous_ranks() {
|
||||
rankinfo ri;
|
||||
|
||||
int N = get_n();
|
||||
|
||||
@@ -57,15 +57,16 @@ void continuous_ranks() {
|
||||
ltot_n++;
|
||||
}
|
||||
std::unique_lock<std::mutex> lk(lock);
|
||||
tot_rby += ltot_rby;
|
||||
tot_map += ltot_map;
|
||||
tot_ranks += ltot_ranks;
|
||||
tot_n += ltot_n;
|
||||
ri.rby += ltot_rby;
|
||||
ri.map += ltot_map;
|
||||
ri.ranks += ltot_ranks;
|
||||
ri.n += ltot_n;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
println(hlog, "MeanRank = ", tot_ranks / tot_rby, " MAP = ", tot_map / tot_n);
|
||||
println(hlog, "data: ", tie(tot_rby, tot_map, tot_ranks, tot_n, N));
|
||||
println(hlog, "MeanRank = ", ri.ranks / ri.rby, " MAP = ", ri.map / ri.n);
|
||||
println(hlog, "data: ", tie(ri.rby, ri.map, ri.ranks, ri.n, N));
|
||||
return ri;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@ namespace embeddings {
|
||||
|
||||
int tal_limit = 0;
|
||||
|
||||
void analyze_mdl_symmetric(bool symmetric) {
|
||||
loglik_info analyze_mdl_symmetric(bool symmetric) {
|
||||
int dim = current->get_dimension();
|
||||
int N = isize(rogueviz::vdata);
|
||||
int N = get_n();
|
||||
loglik_info li;
|
||||
|
||||
if(dim == 1) return;
|
||||
if(dim == 1) return li;
|
||||
|
||||
vector<ld> center_distances(N);
|
||||
for(int id=0; id<N; id++) center_distances[id] = current->zero_distance(id);
|
||||
@@ -16,13 +17,17 @@ void analyze_mdl_symmetric(bool symmetric) {
|
||||
build_disttable_approx();
|
||||
logistic cont;
|
||||
cont.setRT(0, 1);
|
||||
if(symmetric) fast_loglik_cont(cont, loglik_cont_approx, "lcont", 1, 1e-6);
|
||||
if(symmetric) println(hlog, "loglikelihood = ", format("%.1f", -loglik_cont_approx(cont)));
|
||||
if(symmetric) {
|
||||
fast_loglik_cont(cont, loglik_cont_approx, "lcont", 1, 1e-6);
|
||||
li.loglik = loglik_cont_approx(cont);
|
||||
if(symmetric) println(hlog, "loglikelihood = ", format("%.1f", -li.loglik));
|
||||
}
|
||||
ld N1 = N * (N-1.);
|
||||
ld M = count_directed_edges();
|
||||
if(symmetric) { N1 /= 2; M /= 2; }
|
||||
ld max_radius = 0;
|
||||
for(auto& d: center_distances) max_radius = max(max_radius, d);
|
||||
li.N = N; li.M = M; li.N1 = N1;
|
||||
ld M1 = N1 - M;
|
||||
ld entropy = M * log(M/N1) + M1 * log(M1/N1);
|
||||
println(hlog, "N = ", N, " M = ", M, " radius = ", max_radius, " entropy = ", format("%.1f", -entropy));
|
||||
@@ -53,8 +58,8 @@ void analyze_mdl_symmetric(bool symmetric) {
|
||||
vector<logistic> logistics(N, cont);
|
||||
|
||||
if(!symmetric) {
|
||||
if(tal_limit == 0) { println(hlog, "not computing TAL -- the graph is asymmetric"); return; }
|
||||
if(N >= tal_limit) { println(hlog, "too large graph to compute TAL"); return; }
|
||||
if(tal_limit == 0) { println(hlog, "not computing TAL -- the graph is asymmetric"); return li; }
|
||||
if(N >= tal_limit) { println(hlog, "too large graph to compute TAL"); return li; }
|
||||
|
||||
println(hlog, "computing TAL");
|
||||
bad.resize(N);
|
||||
@@ -134,7 +139,7 @@ void analyze_mdl_symmetric(bool symmetric) {
|
||||
println(hlog, " negloglik = ", extra_info);
|
||||
println(hlog, " control = ", format("%.1f", dist_entropy + sphere_entropy + extra_info));
|
||||
}
|
||||
return dist_entropy + sphere_entropy + extra_info;
|
||||
return li.control = dist_entropy + sphere_entropy + extra_info;
|
||||
};
|
||||
|
||||
ld last_rep = HUGE_VAL;
|
||||
@@ -163,6 +168,8 @@ void analyze_mdl_symmetric(bool symmetric) {
|
||||
}
|
||||
last_rep = cur_rep;
|
||||
}
|
||||
|
||||
return li;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ int get_actual(int src) {
|
||||
return actual[src][current_goal];
|
||||
}
|
||||
|
||||
void full_routing() {
|
||||
iddata full_routing() {
|
||||
iddata result;
|
||||
prepare_pairs();
|
||||
if(1) {
|
||||
@@ -226,6 +226,7 @@ void full_routing() {
|
||||
}
|
||||
println(hlog, "greedy routing: success = ", result.suc / result.tot, " stretch = ", result.routedist / result.suc, " efficiency = ", result.eff / result.tot);
|
||||
println(hlog, "modded routing: success = ", result.msuc / result.tot, " stretch = ", result.mroutedist / result.msuc, " efficiency = ", result.meff / result.tot);
|
||||
return result;
|
||||
}
|
||||
|
||||
int routing_args() {
|
||||
|
||||
Reference in New Issue
Block a user