Belle II Software  release-05-01-25
basf2_mva_teacher.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Keck *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <mva/interface/Interface.h>
12 #include <mva/interface/Options.h>
13 #include <mva/utility/Utility.h>
14 
15 #include <iostream>
16 #include <string>
17 #include <cerrno>
18 
19 namespace po = boost::program_options;
20 using namespace Belle2::MVA;
21 
22 int main(int argc, char* argv[])
23 {
24 
26 
27  GeneralOptions general_options;
28  po::options_description general_description(general_options.getDescription());
29 
30  MetaOptions meta_options;
31  po::options_description meta_description(meta_options.getDescription());
32 
33  // Order of additional options
34  // Loop over all classes from multi-class
35  // Loop over all hyperparameters -> needs also apply functionality from expert
36  // Do sPlot boost
37 
38  std::map<std::string, std::unique_ptr<SpecificOptions>> specific_options;
39 
40  for (auto& interface : AbstractInterface::getSupportedInterfaces()) {
41  specific_options.emplace(interface.second->getName(), interface.second->getOptions());
42  }
43 
44  po::variables_map vm;
45 
46  try {
47  po::options_description cmdline_description;
48  cmdline_description.add(general_description);
49  cmdline_description.add(meta_description);
50 
51  po::parsed_options parsed = po::command_line_parser(argc, argv).options(cmdline_description).allow_unregistered().run();
52  po::store(parsed, vm);
53 
54  if (vm.count("help")) {
55  if (vm.count("method")) {
56  std::string method = vm["method"].as<std::string>();
57  if (specific_options.find(method) != specific_options.end()) {
58  std::cout << specific_options[method]->getDescription() << std::endl;
59  } else {
60  std::cerr << "Provided method is unkown" << std::endl;
61  }
62  } else {
63  std::cout << general_description << std::endl;
64  std::cout << meta_description << std::endl;
65  }
66  return 1;
67  }
68  po::notify(vm);
69 
70  if (vm.count("method")) {
71  std::string method = vm["method"].as<std::string>();
72  if (specific_options.find(method) != specific_options.end()) {
73  cmdline_description.add(specific_options[method]->getDescription());
74  po::parsed_options specific_parsed = po::command_line_parser(argc, argv).options(cmdline_description).run();
75  po::store(specific_parsed, vm);
76  po::notify(vm);
77  } else {
78  std::cerr << "Provided method is unkown" << std::endl;
79  return 1;
80  }
81  } else {
82  std::cerr << "You must provide a method" << std::endl;
83  return 1;
84  }
85  } catch (po::error& err) {
86  std::cerr << "Error: " << err.what() << "\n";
87  return 1;
88  }
89 
90  //Check if method is available
91  if (specific_options.find(general_options.m_method) == specific_options.end()) {
92  std::cerr << "Unkown method " << general_options.m_method << std::endl;
93  }
94 
95  Belle2::MVA::teacher(general_options, *specific_options[general_options.m_method], meta_options);
96 
97  return 0;
98 
99 }
100 
Belle2::MVA::AbstractInterface::getSupportedInterfaces
static std::map< std::string, AbstractInterface * > getSupportedInterfaces()
Returns interfaces supported by the MVA Interface.
Definition: Interface.h:55
main
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:77
Belle2::MVA::GeneralOptions
General options which are shared by all MVA trainings.
Definition: Options.h:64
Belle2::MVA::AbstractInterface::initSupportedInterfaces
static void initSupportedInterfaces()
Static function which initliazes all supported interfaces, has to be called once before getSupportedI...
Definition: Interface.cc:55
Belle2::MVA::MetaOptions
Meta Options which modify the underlying training by doing sPlot, Multiclass and HyperparameterSearch...
Definition: Options.h:112