diff --git a/rogueviz/embeddings/coords.cpp b/rogueviz/embeddings/coords.cpp new file mode 100644 index 00000000..8e4c2549 --- /dev/null +++ b/rogueviz/embeddings/coords.cpp @@ -0,0 +1,99 @@ + +namespace rogueviz { + +namespace embeddings { + + enum class fmt { hyperb, poincare, bhyper }; + + string format_names[3] = { "hyperboloid trailing", "Poincare", "hyperboloid leading" }; + + fmt coord_format; + + struct coord_embedding : public untiled_embedding { + vector coords; + + hyperpoint as_hyperpoint(int id) override { + return coords[id]; + } + + virtual string name() { return "coordinates: " + format_names[(int) coord_format]; } + + ld zero_distance(int id) { return hdist0(coords[id]); } + + ld distance(int i, int j) { + return precise_hdist(coords[i], coords[j]); + } + + void save(fhstream& f) override { + int i = 0; + for(auto& co: coords) { + println(f, vdata[i++].name); + switch(coord_format) { + case fmt::hyperb: + for(int i=0; i (); + int N = isize(vdata); + pe->coords.resize(N); + + if(fn == "-") { + for(int i=0; icoords[i] = current->as_hyperpoint(i); + } + return enable_embedding(pe); + } + + fhstream f(fn, "rt"); + if(!f.f) return file_error(fn); + + for(int i=0; i(f); + if(s == "") throw hr_exception("data failure"); + int id = rogueviz::labeler.at(s); + auto& co = pe->coords[id]; + switch(coord_format) { + case fmt::hyperb: + for(int i=0; i(f); + break; + case fmt::bhyper: + co[MDIM-1] = scan(f); + for(int i=0; i(f); + break; + case fmt::poincare: + hyperpoint h1; + for(int i=0; i(f); + co = perspective_to_space(h1, 1); + break; + } + co = normalize(co); + } + + enable_embedding(pe); + } + + int a_coord = + arg::add3("-el-coord", [] { arg::shift(); read_coord(arg::args()); }) + + arg::add3("-ec-hyperb", [] { coord_format = fmt::hyperb; }) + + arg::add3("-ec-bhyper", [] { coord_format = fmt::bhyper; }) + + arg::add3("-ec-poincare", [] { coord_format = fmt::poincare; }); + + } +} \ No newline at end of file diff --git a/rogueviz/embeddings/embeddings.cpp b/rogueviz/embeddings/embeddings.cpp index 48b85c8f..fb2060c2 100644 --- a/rogueviz/embeddings/embeddings.cpp +++ b/rogueviz/embeddings/embeddings.cpp @@ -114,6 +114,7 @@ int a = arg::add3("-edgelist", [] { arg::shift(); read_edgelist(arg::args()); }) } #include "polar.cpp" +#include "coords.cpp" #include "loglik.cpp" #include "routing.cpp"