summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--geom_matching/wasserstein/example/wasserstein_dist_dipha.cpp5
-rw-r--r--geom_matching/wasserstein/include/basic_defs_ws.hpp5
-rw-r--r--geom_matching/wasserstein/include/diagram_reader.h136
3 files changed, 69 insertions, 77 deletions
diff --git a/geom_matching/wasserstein/example/wasserstein_dist_dipha.cpp b/geom_matching/wasserstein/example/wasserstein_dist_dipha.cpp
index a9029fe..cd8c61a 100644
--- a/geom_matching/wasserstein/example/wasserstein_dist_dipha.cpp
+++ b/geom_matching/wasserstein/example/wasserstein_dist_dipha.cpp
@@ -1,6 +1,7 @@
/*
Copyright (c) 2015, M. Kerber, D. Morozov, A. Nigmetov
+Copyright (c) 2018, G. Spreemann
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -49,12 +50,12 @@ int main(int argc, char* argv[])
hera::AuctionParams<double> params;
if (argc < 4 ) {
- std::cerr << "Usage: " << argv[0] << " file1 file2 ph_degree [wasserstein_degree] [relative_error] [internal norm] [initial epsilon] [epsilon_factor] [max_bids_per_round] [gamma_threshold][log_filename_prefix]. By default power is 1.0, relative error is 0.01, internal norm is l_infinity, initall epsilon is chosen automatically, epsilon factor is 5.0, Jacobi variant is used (max bids per round is maximal), gamma_threshold = 0.0." << std::endl;
+ std::cerr << "Usage: " << argv[0] << " file1 file2 ph_dim [wasserstein_degree] [relative_error] [internal norm] [initial epsilon] [epsilon_factor] [max_bids_per_round] [gamma_threshold][log_filename_prefix]. By default power is 1.0, relative error is 0.01, internal norm is l_infinity, initall epsilon is chosen automatically, epsilon factor is 5.0, Jacobi variant is used (max bids per round is maximal), gamma_threshold = 0.0." << std::endl;
return 1;
}
unsigned int dim = std::stoul(argv[3]);
-
+
if (!hera::read_diagram_dipha<double, PairVector>(argv[1], dim, diagramA)) {
std::exit(1);
}
diff --git a/geom_matching/wasserstein/include/basic_defs_ws.hpp b/geom_matching/wasserstein/include/basic_defs_ws.hpp
index de25d48..1750b4e 100644
--- a/geom_matching/wasserstein/include/basic_defs_ws.hpp
+++ b/geom_matching/wasserstein/include/basic_defs_ws.hpp
@@ -1,6 +1,7 @@
/*
Copyright (c) 2015, M. Kerber, D. Morozov, A. Nigmetov
+Copyright (c) 2018, G. Spreemann
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -205,7 +206,7 @@ template <typename T> inline void reverse_endianness(T & x)
uint8_t * p = reinterpret_cast<uint8_t *>(&x);
std::reverse(p, p + sizeof(T));
}
-
+
template <typename T> inline T read_le(std::istream & s)
{
T result;
@@ -215,5 +216,5 @@ template <typename T> inline T read_le(std::istream & s)
#endif
return result;
}
-
+
} // hera
diff --git a/geom_matching/wasserstein/include/diagram_reader.h b/geom_matching/wasserstein/include/diagram_reader.h
index b6ec635..84bf49c 100644
--- a/geom_matching/wasserstein/include/diagram_reader.h
+++ b/geom_matching/wasserstein/include/diagram_reader.h
@@ -1,6 +1,7 @@
/*
Copyright (c) 2015, M. Kerber, D. Morozov, A. Nigmetov
+Copyright (c) 2018, G. Spreemann
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -202,84 +203,73 @@ bool read_diagram_point_set(const std::string& fname, ContType_& result)
return read_diagram_point_set<RealType, ContType_>(fname.c_str(), result, decPrecision);
}
- template<class RealType = double, class ContType_ = std::vector<std::pair<RealType, RealType> > >
- bool read_diagram_dipha(const std::string& fname, unsigned int degree, ContType_& result)
+template<class RealType = double, class ContType_ = std::vector<std::pair<RealType, RealType> > >
+bool read_diagram_dipha(const std::string& fname, unsigned int dim, ContType_& result)
{
- std::ifstream file;
- file.open(fname, std::ios::in | std::ios::binary);
-
- if (!file.is_open())
- {
- #ifndef FOR_R_TDA
- std::cerr << "Could not open file " << fname << "." << std::endl;
- #endif
- return false;
- }
-
- if (read_le<int64_t>(file) != DIPHA_MAGIC)
- {
- #ifndef FOR_R_TDA
- std::cerr << "File " << fname << " is not a valid DIPHA file." << std::endl;
- #endif
- file.close();
- return false;
- }
-
- if (read_le<int64_t>(file) != DIPHA_PERSISTENCE_DIAGRAM)
- {
- #ifndef FOR_R_TDA
- std::cerr << "File " << fname << " is not a valid DIPHA persistence diagram file." << std::endl;
- #endif
- file.close();
- return false;
- }
-
- result.clear();
-
- int n = read_le<int64_t>(file);
-
- for (int i = 0; i < n; ++i)
- {
- int tmp_d = read_le<int64_t>(file);
- double birth = read_le<double>(file);
- double death = read_le<double>(file);
-
- if (death < birth)
- {
- #ifndef FOR_R_TDA
- std::cerr << "File " << fname << " is malformed." << std::endl;
- #endif
- file.close();
- return false;
+ std::ifstream file;
+ file.open(fname, std::ios::in | std::ios::binary);
+
+ if (!file.is_open()) {
+#ifndef FOR_R_TDA
+ std::cerr << "Could not open file " << fname << "." << std::endl;
+#endif
+ return false;
}
-
- int d = 0;
- if (tmp_d < 0)
- {
- d = -tmp_d - 1;
- death = std::numeric_limits<double>::infinity();
+
+ if (read_le<int64_t>(file) != DIPHA_MAGIC) {
+#ifndef FOR_R_TDA
+ std::cerr << "File " << fname << " is not a valid DIPHA file." << std::endl;
+#endif
+ file.close();
+ return false;
+ }
+
+ if (read_le<int64_t>(file) != DIPHA_PERSISTENCE_DIAGRAM) {
+#ifndef FOR_R_TDA
+ std::cerr << "File " << fname << " is not a valid DIPHA persistence diagram file." << std::endl;
+#endif
+ file.close();
+ return false;
}
- else
- d = tmp_d;
-
- if ((unsigned int)d == degree)
- {
- if (death == birth)
- {
- #ifndef FOR_R_TDA
- std::cerr << "Warning: point with 0 persistence ignored in " << fname << "." << std::endl;
- #endif
- }
- else
- {
- result.push_back(std::make_pair(birth, death));
- }
+
+ result.clear();
+
+ int n = read_le<int64_t>(file);
+
+ for (int i = 0; i < n; ++i) {
+ int tmp_d = read_le<int64_t>(file);
+ double birth = read_le<double>(file);
+ double death = read_le<double>(file);
+
+ if (death < birth) {
+#ifndef FOR_R_TDA
+ std::cerr << "File " << fname << " is malformed." << std::endl;
+#endif
+ file.close();
+ return false;
+ }
+
+ int d = 0;
+ if (tmp_d < 0) {
+ d = -tmp_d - 1;
+ death = std::numeric_limits<double>::infinity();
+ } else
+ d = tmp_d;
+
+ if ((unsigned int)d == dim) {
+ if (death == birth) {
+#ifndef FOR_R_TDA
+ std::cerr << "Warning: point with 0 persistence ignored in " << fname << "." << std::endl;
+#endif
+ } else {
+ result.push_back(std::make_pair(birth, death));
+ }
+ }
}
- }
- file.close();
-
- return true;
+ file.close();
+
+ return true;
}