licornea_tools
cg_compare_straight_depths.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <utility>
3 #include <vector>
4 #include <cmath>
5 #include <algorithm>
6 #include <fstream>
7 #include <set>
8 #include <map>
10 #include "../lib/args.h"
11 #include "../lib/misc.h"
12 
13 using namespace tlz;
14 
15 constexpr bool verbose = true;
16 
17 int main(int argc, const char* argv[]) {
18  get_args(argc, argv, "depths1.json depths2.json [depths.txt]");
21  std::string out_depths_filename = out_filename_opt_arg("");
22 
23  // find common features
24  std::set<std::string> common_features;
25  for(const auto& kv : depths1) {
26  const std::string& feature_name = kv.first;
27  if(depths2.find(feature_name) != depths2.end()) common_features.insert(feature_name);
28  }
29  std::cout << "depths1 count: " << depths1.size() << std::endl;
30  std::cout << "depths2 count: " << depths2.size() << std::endl;
31  std::cout << "common count: " << common_features.size() << std::endl;
32 
33  // calculate rms error
34  real rms_error = 0.0;
35  for(const std::string& feature_name : common_features) {
36  real d1 = depths1.at(feature_name);
37  real d2 = depths2.at(feature_name);
38  rms_error += sq(d1 - d2);
39  }
40  rms_error = std::sqrt(rms_error / common_features.size());
41  std::cout << "rms_error: " << rms_error << std::endl;
42 
43  // print to file
44  if(! out_depths_filename.empty()) {
45  std::ofstream stream(out_depths_filename);
46  stream << std::setprecision(10);
47  for(const std::string& feature_name : common_features) {
48  real d1 = depths1.at(feature_name);
49  real d2 = depths2.at(feature_name);
50  stream << feature_name << ' ' << d1 << ' ' << d2 << '\n';
51  }
52  }
53 }
Numeric sq(Numeric n)
Compute square of a number.
Definition: misc.h:17
std::string out_filename_opt_arg(const std::string &def)
Definition: args.cc:110
std::map< std::string, straight_depth > straight_depths
double real
Definition: common.h:16
constexpr bool verbose
straight_depths straight_depths_arg()
int main(int argc, const char *argv[])
void get_args(int argc, const char *argv[], const std::string &usage)
Definition: args.cc:49