combinatorialTrainer.cpp
Go to the documentation of this file.
1 
18 #define BOOST_NO_SCOPED_ENUMS
19 
20 #include <ros/ros.h>
21 #include <std_msgs/Empty.h>
22 #include <std_msgs/UInt32.h>
23 #include <std_msgs/String.h>
24 #include <visualization_msgs/MarkerArray.h>
25 
26 #include <boost/filesystem/path.hpp>
27 #include <boost/shared_ptr.hpp>
28 #include <boost/bind.hpp>
29 #include <boost/date_time/posix_time/posix_time.hpp>
30 #include <boost/date_time/posix_time/posix_time_io.hpp>
31 #include <boost/algorithm/string.hpp>
32 
33 #include <string>
34 #include <chrono>
35 
36 #include <ISM/combinatorial_trainer/CombinatorialTrainer.hpp>
37 #include <ISM/combinatorial_trainer/CombinatorialTrainerParameters.hpp>
38 #include <ISM/common_type/RecognitionResult.hpp>
39 #include <ISM/utility/Util.hpp>
40 
41 using boost::filesystem::path;
42 
44 {
45 
46 private:
48 
49 public:
50  CombinatorialTrainer() : mNh("~")
51  {
52  ISM::CombinatorialTrainerParameters params;
54 
55  ISM::TableHelperPtr table_helper = ISM::TableHelperPtr(new ISM::TableHelper(params.general.dbfilename));
56  if(!table_helper->recordDataExists())
57  {
58  ISM::printRed("The database \"" + params.general.dbfilename + "\" doesn't contain any recordings!\n");
59  exit(0);
60  }
61 
62 
63  ISM::CombinatorialTrainerPtr combinatorialTrainer = ISM::CombinatorialTrainerPtr(new ISM::CombinatorialTrainer(params));
64  combinatorialTrainer->learn();
65  }
66 
67  void getCombinatorialTrainerParameters(const ros::NodeHandle& node_handle, ISM::CombinatorialTrainerParameters* params)
68  {
69  readParameter(node_handle, "dbfilename", &params->general.dbfilename, "");
70  readParameter(node_handle, "outputDataPath", &params->general.outputDataPath, "");
71  readParameter(node_handle, "testSetCount", &params->general.testSetCount, 0u);
72  readParameter(node_handle, "useClassifier", &params->general.useClassifier, false);
73  readParameter(node_handle, "loadValidTestSetsFrom", &params->general.loadValidTestSetsFrom, "");
74  readParameter(node_handle, "loadInvalidTestSetsFrom", &params->general.loadInvalidTestSetsFrom, "");
75  readParameter(node_handle, "storeValidTestSetsTo", &params->general.storeValidTestSetsTo, "");
76  readParameter(node_handle, "storeInvalidTestSetsTo", &params->general.storeInvalidTestSetsTo, "");
77  readParameter(node_handle, "loadStartTopologiesFrom", &params->general.loadStartTopologiesFrom, "");
78  readParameter(node_handle, "storeFullyMeshedISM", &params->general.storeFullyMeshedISM, false);
79  readParameter(node_handle, "storeStartTopologyISM", &params->general.storeStartTopologyISM, false);
80 
81  readParameter(node_handle, "evaluatorId", &params->evaluator.evaluatorId, 0);
82  readParameter(node_handle, "bin_size", &params->evaluator.binSize, 0.08);
83  readParameter(node_handle, "maxAngleDeviation", &params->evaluator.maxAngleDeviation, 10);
84  readParameter(node_handle, "confidenceThreshold", &params->evaluator.confidenceThreshold, 0.99);
85  readParameter(node_handle, "testForFalseNegatives", &params->evaluator.testForFalseNegatives, false);
86 
87  readParameter(node_handle, "topologyGeneratorId", &params->topologyGenerator.topologyGeneratorId, 0);
88  readParameter(node_handle, "swapRelations", &params->topologyGenerator.swapRelations, true);
89  readParameter(node_handle, "removeRelations", &params->topologyGenerator.removeRelations, true);
90  readParameter(node_handle, "maxNeighbourCount", &params->topologyGenerator.maxNeighbourCount, -1);
91 
92  readParameter(node_handle, "treeValidatorId", &params->treeValidator.treeValidatorId, 0);
93  readParameter(node_handle, "maxTreeHeight", &params->treeValidator.maxTreeHeight, 2);
94 
95  readParameter(node_handle, "optimizationAlgorithmId", &params->optimizationAlgorithm.optimizationAlgorithmId, 0);
96  readParameter(node_handle, "randomRestartProbability", &params->optimizationAlgorithm.randomRestartProbability, 0);
97  readParameter(node_handle, "randomWalkProbability", &params->optimizationAlgorithm.randomWalkProbability, 0);
98  readParameter(node_handle, "startFromRandomTopology", &params->optimizationAlgorithm.startFromRandomTopology, false);
99 
100  readParameter(node_handle, "startTemperature", &params->optimizationAlgorithm.startTemperature, 0);
101  readParameter(node_handle, "endTemperature", &params->optimizationAlgorithm.endTemperature, 0);
102  readParameter(node_handle, "temperatureFactor", &params->optimizationAlgorithm.temperatureFactor, 0);
103  readParameter(node_handle, "repetitionsBeforeUpdated", &params->optimizationAlgorithm.repetitionsBeforeUpdated, 0);
104 
105  readParameter(node_handle, "initialAcceptableCostDelta", &params->optimizationAlgorithm.initialAcceptableCostDelta, 0);
106  readParameter(node_handle, "costDeltaDecreaseFactor", &params->optimizationAlgorithm.costDeltaDecreaseFactor , 0);
107  readParameter(node_handle, "costFunctionId", &params->costFunction.costFunctionId, 0);
108  readParameter(node_handle, "alpha", &params->costFunction.alpha, 1);
109  readParameter(node_handle, "beta", &params->costFunction.beta, 1);
110  }
111 
112  void readParameter(const ros::NodeHandle& node_handle, const std::string& parameterName, double* d, const double defaultValue)
113  {
114  node_handle.param<double>(parameterName, *d, defaultValue);
115  ROS_INFO("%s = %.4lf", parameterName.c_str(), *d);
116  }
117 
118  void readParameter(const ros::NodeHandle& node_handle, const std::string& parameterName, std::string* s, const std::string defaultValue)
119  {
120  node_handle.param<std::string>(parameterName, *s, defaultValue);
121  ROS_INFO("%s = %s", parameterName.c_str(), (*s).c_str());
122  }
123 
124  void readParameter(const ros::NodeHandle& node_handle, const std::string& parameterName, int *i, const int defaultValue)
125  {
126  node_handle.param<int>(parameterName, *i, defaultValue);
127  ROS_INFO("%s = %d", parameterName.c_str(), *i);
128  }
129 
130  void readParameter(const ros::NodeHandle& node_handle, const std::string& parameterName, bool *b, const bool defaultValue)
131  {
132  node_handle.param<bool>(parameterName, *b, defaultValue);
133  ROS_INFO("%s = %s", parameterName.c_str(), *b ? "true" : "false");
134  }
135 
136  void readParameter(const ros::NodeHandle& node_handle, const std::string& parameterName, unsigned int *ui, const unsigned int defaultValue)
137  {
138  int tmp;
139  node_handle.param<int>(parameterName, tmp, defaultValue);
140  *ui = boost::lexical_cast<unsigned int>(tmp);
141  ROS_INFO("%s = %u", parameterName.c_str(), *ui);
142  }
143 };
144 
145 int main(int argc, char **argv)
146 {
147  auto unix_timestamp = std::chrono::seconds(std::time(NULL));
148  std::cout << "Start Time: " << unix_timestamp.count() << std::endl;
149 
150  boost::posix_time::time_facet *facet = new boost::posix_time::time_facet("%d-%b-%Y %H:%M:%S");
151  std::cout.imbue(std::locale(std::cout.getloc(), facet));
152  std::cout << boost::posix_time::second_clock::local_time() << std::endl;
153 
154  auto t1 = std::chrono::high_resolution_clock::now();
155 
156  ros::init(argc, argv, "combinatorialTrainer");
158 
159  auto t2 = std::chrono::high_resolution_clock::now();
160  auto duration = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();
161  std::cout << "Duration: " << duration << std::endl;
162 
163  delete otr;
164  delete facet;
165 }
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void getCombinatorialTrainerParameters(const ros::NodeHandle &node_handle, ISM::CombinatorialTrainerParameters *params)
void readParameter(const ros::NodeHandle &node_handle, const std::string &parameterName, bool *b, const bool defaultValue)
void readParameter(const ros::NodeHandle &node_handle, const std::string &parameterName, int *i, const int defaultValue)
#define ROS_INFO(...)
void readParameter(const ros::NodeHandle &node_handle, const std::string &parameterName, std::string *s, const std::string defaultValue)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
void readParameter(const ros::NodeHandle &node_handle, const std::string &parameterName, double *d, const double defaultValue)
int main(int argc, char **argv)
void readParameter(const ros::NodeHandle &node_handle, const std::string &parameterName, unsigned int *ui, const unsigned int defaultValue)


asr_ism
Author(s): Borella Jocelyn, Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Thu Jan 9 2020 07:20:58