GEDLIB  1.0
train_ml.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2018 by David B. Blumenthal *
4  * *
5  * This file is part of GEDLIB. *
6  * *
7  * GEDLIB is free software: you can redistribute it and/or modify it *
8  * under the terms of the GNU Lesser General Public License as published *
9  * by the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * GEDLIB is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU Lesser General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with GEDLIB. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 
31 #include "util.hpp"
32 
33 void train_on_dataset(const std::string & dataset, bool train_svm) {
34 
35  // Initialize environment.
36  std::cout << "\n=== " << dataset << " ===\n";
37  std::cout << "\tInitializing the environment ...\n";
39  util::setup_environment(dataset, true, env);
40 
41  // Train RingML and BipartiteML with DNN.
42  env.set_method(ged::Options::GEDMethod::RING_ML, util::init_options(dataset, "ring_ml_dnn", "ring_ml", true, false, 16) + util::ground_truth_option(dataset) + " --ml-method DNN --save-ground-truth " + util::config_prefix(dataset) + "ground_truth.data");
43  env.init_method();
44  env.set_method(ged::Options::GEDMethod::BIPARTITE_ML, util::init_options(dataset, "bipartite_ml_BIPARTITE_dnn", "bipartite_ml_BIPARTITE", true, false, 16) + " --ml-method DNN --load-ground-truth " + util::config_prefix(dataset) + "ground_truth.data");
45  env.init_method();
46 
47  // Train RingML and BipartiteML with OneClassSVM.
48  env.set_method(ged::Options::GEDMethod::RING_ML, util::init_options(dataset, "ring_ml_one_class_svm", "ring_ml_one_class", true, false, 16) + util::ground_truth_option(dataset) + " --ml-method ONE_CLASS_SVM --load-ground-truth " + util::config_prefix(dataset) + "ground_truth.data");
49  env.init_method();
50  env.set_method(ged::Options::GEDMethod::BIPARTITE_ML, util::init_options(dataset, "bipartite_ml_BIPARTITE_one_class_svm", "bipartite_ml_BIPARTITE_one_class", true, false, 16) + " --ml-method ONE_CLASS_SVM --load-ground-truth " + util::config_prefix(dataset) + "ground_truth.data");
51  env.init_method();
52 
53  // Train RingML and BipartiteML with SVM.
54  if (train_svm) {
55  env.set_method(ged::Options::GEDMethod::RING_ML, util::init_options(dataset, "ring_ml_svm", "ring_ml", false, true, 16) + util::ground_truth_option(dataset) + " --ml-method SVM --load-ground-truth " + util::config_prefix(dataset) + "ground_truth.data");
56  env.init_method();
57  env.set_method(ged::Options::GEDMethod::BIPARTITE_ML, util::init_options(dataset, "bipartite_ml_BIPARTITE_svm", "bipartite_ml_BIPARTITE", false, true, 16) + " --ml-method SVM --load-ground-truth " + util::config_prefix(dataset) + "ground_truth.data");
58  env.init_method();
59  }
60 }
61 
62 int main(int argc, char* argv[]) {
63  std::vector<std::string> datasets;
64  bool train_svm{true};
65  int i{1};
66  if (argc > 1) {
67  std::string first_option(argv[i]);
68  if (first_option == "--no-svm") {
69  train_svm = false;
70  i++;
71  }
72  else {
73  std::cout << "first option = \"" << first_option << "\"\n";
74  }
75  }
76  for (; i < argc; i++) {
77  datasets.push_back(std::string(argv[i]));
78  util::check_dataset(datasets.back());
79  }
80  if (datasets.empty()) {
81  util::setup_datasets(datasets);
82  }
83  for (auto dataset : datasets) {
84  try {
85  train_on_dataset(dataset, train_svm);
86  }
87  catch (const std::exception & error) {
88  std::cerr << error.what() << ". " << "Error on " << dataset << ".\n";
89  }
90  }
91  return 0;
92 }
void init_method()
Initializes the method specified by call to set_method().
Definition: ged_env.ipp:521
Provides utility functions for tests of PR submission.
Selects ged::BipartiteML.
void set_method(Options::GEDMethod method, const std::string &options=std::string(""))
Sets the GEDMethod to be used by run_method().
Definition: ged_env.ipp:384
Provides the API of GEDLIB.
Definition: ged_data.hpp:48