4 #include <boost/filesystem/path.hpp>     5 #include <boost/date_time/posix_time/posix_time.hpp>     7 #include <ISM/utility/TableHelper.hpp>    21 using boost::posix_time::ptime;
    22 using boost::posix_time::time_duration;
    23 using boost::filesystem::path;
    65     nh.
setParam(
"scene_model_type", 
"ocm");
    67     nh.
setParam(
"workspace_volume", 8.0);
    68     nh.
setParam(
"static_break_ratio", 1.01);
    70     nh.
setParam(
"intermediate_results", 
false);
    75     nh.
setParam(
"synthetic_samples", 10);
    76     nh.
setParam(
"interval_position", 0.25);
    77     nh.
setParam(
"interval_orientation", 10);
    78     nh.
setParam(
"orientation_plot_path", 
"UNDEFINED");
    79     nh.
setParam(
"max_angle_deviation", 45);
    89     nh.
setParam(
"targeting_help", 
false);
    93     nh.
setParam(
"starting_topologies_type", 
"BestStarOrFullyMeshed");
    94     nh.
setParam(
"number_of_starting_topologies", 1);
    95     nh.
setParam(
"neighbourhood_function", 
"TopologyManager");
    96     nh.
setParam(
"remove_relations", 
true);
    98     nh.
setParam(
"maximum_neighbour_count", 100);
   100     nh.
setParam(
"cost_function", 
"WeightedSum");
   101     nh.
setParam(
"false_positives_weight", 5);
   102     nh.
setParam(
"avg_recognition_time_weight", 1);
   103     nh.
setParam(
"false_negatives_weight", 5);
   105     nh.
setParam(
"test_set_generator_type", 
"relative");
   106     nh.
setParam(
"test_set_count", 1000);
   107     nh.
setParam(
"object_missing_in_test_set_probability", 0);
   109     nh.
setParam(
"loaded_test_set_count", 1000);
   110     nh.
setParam(
"write_valid_test_sets_filename", 
"");
   111     nh.
setParam(
"write_invalid_test_sets_filename", 
"");
   113     nh.
setParam(
"conditional_probability_algorithm", 
"minimum");
   114     nh.
setParam(
"revisit_topologies", 
true);
   115     nh.
setParam(
"flexible_recognition_threshold", 
false);
   116     nh.
setParam(
"quit_after_test_set_evaluation", 
false);
   117     nh.
setParam(
"get_worst_star_topology", 
false);
   119     nh.
setParam(
"hill_climbing_random_walk_probability", 0);
   120     nh.
setParam(
"hill_climbing_random_restart_probability", 0.2);
   122     nh.
setParam(
"record_hunt_initial_acceptable_cost_delta", 0.02);
   123     nh.
setParam(
"record_hunt_cost_delta_decrease_factor", 0.01);
   125     nh.
setParam(
"simulated_annealing_start_temperature", 1);
   126     nh.
setParam(
"simulated_annealing_end_temperature", 0.005);
   127     nh.
setParam(
"simulated_annealing_repetitions_before_update", 8);
   128     nh.
setParam(
"simulated_annealing_temperature_factor", 0.9);
   131     nh.
setParam(
"optimization_history_output", 
"txt");
   132     nh.
setParam(
"create_runtime_log", 
false);
   134     nh.
setParam(
"visualize_inference", 
false);
   138    nh.
setParam(
"object_topic", 
"/stereo/objects");
   139    nh.
setParam(
"scene_graph_topic", 
"/scene_graphs");
   140    nh.
setParam(
"evidence_timeout", 100);
   143 void writeFile(
const std::string & directoryPath, 
const std::string & filenName, std::ostringstream & content)
   145     std::string filePath = directoryPath + 
"/" + filenName;
   147     std::ios_base::iostate exceptionMask = file.exceptions() | std::ios::failbit | std::ios::badbit;
   148     file.exceptions(exceptionMask);
   152         file << content.str();
   156     catch (std::ios_base::failure& e)
   158         std::cerr << 
"std::ios_base::failure" << std::endl;
   159         std::cerr << e.what() << 
"\n";
   165     double sumSquares = 0;
   166     for (
double value : values)
   168         sumSquares += (value - average) * (value - average);
   171     double variance = sumSquares / values.size();
   173     return std::sqrt(variance);
   176 void createHistogram(
const std::vector<double>& values, 
const unsigned int intervals, 
const std::string & fileName)
   178     double minValue = std::numeric_limits<double>::max();
   179     double maxValue = std::numeric_limits<double>::min();
   181     for (
double value : values)
   183         minValue = std::min(minValue, value);
   184         maxValue = std::max(maxValue, value);
   187     double diff = maxValue - minValue;
   188     double factor = intervals / diff;
   190     std::vector<unsigned int> histogram(intervals, 0);
   192     for (
double value : values)
   194         histogram[std::min((
unsigned int) std::floor((value - minValue) * factor), intervals)]++;
   197     std::ostringstream oss;
   198     oss << 
"Intervall in seconds, Number Testsets" << std::endl;
   199     for (
unsigned int i = 0; i < intervals; ++i)
   201         double lower = minValue + (i * 1 / factor);
   202         double upper = lower + 1 / factor;
   204         oss << lower << 
"-" << upper << 
", " << histogram[i] << std::endl;
   212     std::stringstream error;
   217         ptime t1(boost::posix_time::microsec_clock::local_time());
   220         sceneLearningEngine->readLearnerInput();
   221         sceneLearningEngine->generateSceneModel();
   222         sceneLearningEngine->saveSceneModel();
   224         ptime t2(boost::posix_time::microsec_clock::local_time());
   227     catch (std::exception& e)
   229         std::cerr << e.what() << std::endl;
   230         error << 
", Error: " << e.what();
   234     long secs = td.total_seconds() % 60;
   235     long mins = std::floor(td.total_seconds() / 60.);
   237     os << 
", " << mins << 
"." << secs << error.str() << std::endl;
   246             std::string demoName = 
"demoRecording_" + std::to_string(
objectCounts[i]) + 
"_" + std::to_string(
timestepCounts[j]) + 
".sqlite";
   247             std::string demoRecordingPath = 
outputPath + 
"/" + demoName;
   259     if(!boost::filesystem::exists(testSetFolderPath))
   260         boost::filesystem::create_directories(testSetFolderPath);
   267         testSets.push_back(validTestSetsPath.string());
   268         testSets.push_back(invalidTestSetsPath.string());
   274     std::ostringstream os;
   275     os << 
"Scene, Training duration" << std::endl;
   283         std::string additionalInfo = 
"";
   286         std::string sceneModelName = demoName + 
"_" + 
treeAlgorithm + additionalInfo;
   287         std::cout << 
"Learning model " << 
outputPath << 
"/" << run << 
"/" << sceneModelName << 
".xml" << std::endl;
   288         nh.
setParam(
"scene_model_name", sceneModelName);
   294         std::string subfolder = 
outputPath + 
"/" + std::to_string(run) + 
"/" + demoName + 
"/";
   295         nh.
setParam(
"xml_file_path", subfolder);
   296         nh.
setParam(
"optimization_history_file_path", subfolder);
   297         std::cout << 
"Writing partial models and optimization histories into folder " << subfolder << 
"/" << demoName << std::endl;
   310     TableHelperPtr localTableHelper(
new TableHelper(fileName));
   311     std::vector<ObjectSetPtr> testSet;
   312     if (!localTableHelper)
   313         throw std::runtime_error(
"No local table helper!");
   314     if (!localTableHelper->getRecordedPattern(patternName))
   315         throw std::runtime_error(
"No recorded pattern for pattern name " + patternName);
   316     testSet = localTableHelper->getRecordedPattern(patternName)->objectSets;
   317     std::cout << 
"Read test sets for pattern " << patternName << std::endl;
   320     catch (soci::soci_error& se)
   322         std::cerr << 
"Soci error " << se.what() << std::endl;
   335         std::stringstream out;
   336         out << falsePositives << 
" false positives, " << falseNegatives << 
", falseNegatives, " << averageRecognitionRuntime << 
"s average recognition runtime";
   348     double fullRecognitionRuntime = 0;
   351     if (!valid) in = 
"in";
   352     std::cout << 
"Evaluating " << ts.size() << 
" " << in << 
"valid test sets for pattern " << patternName << std::endl;
   357     model->initializeVisualizer(mVisualizer);
   360     for (
unsigned int testSetNumber = 0; testSetNumber < ts.size(); testSetNumber++)
   362         ObjectSetPtr testSet = ts[testSetNumber];
   364             throw std::runtime_error(
"Test set pointer invalid");
   365         std::vector<SceneIdentifier> sceneList;
   366         double actualRecognitionThreshold = 0.5;
   372         for (
unsigned int i = 0; i < testSet->objects.size(); i++)
   375             model->integrateEvidence(
object);
   377         model->updateModel();
   378         model->getSceneListWithProbabilities(sceneList);
   381         double recognitionRuntime = end.
toSec() - start.
toSec();
   383         std::string validity = 
"v";
   384         if (!valid) validity = 
"i";
   385         std::string testSetName = patternName + 
"_" + validity + 
"_" + std::to_string(testSetNumber);
   387         std::pair<std::string, double> result(testSetName, -1);
   389         fullRecognitionRuntime += recognitionRuntime;
   391         double probability = -1;
   394             if (sceneIdentifier.mType == 
"ocm")
   396                 probability = sceneIdentifier.mLikelihood;
   400         if (probability == -1)
   401             throw std::runtime_error(
"Could not find probability for scene ocm in list of scene probabilities.");
   403         if (valid && probability <= actualRecognitionThreshold)
   405         if (!valid && probability > actualRecognitionThreshold)
   418     std::ostringstream os;
   419     os << 
"Scene, Average Recognition Runtime, Standard Deviation of Recognition Runtime" << std::endl;
   426             std::cout << 
"index = " << index << std::endl;
   428             std::cout << 
"demo recording: " << demoRecording.string() << std::endl;
   432             std::string trainedScenePath = 
outputPath + 
"/ProbabilisticSceneModels/" + demoRecording.stem().string() + sceneModelNameSuffix + 
".xml" ;
   434             std::cout << 
"Using model " << trainedScenePath << std::endl;
   437             std::cout << sceneName << std::endl;
   439             std::string validTestSets = 
testSets[index * 2];
   440             std::string invalidTestSets = 
testSets[index * 2 + 1];
   442             std::cout << 
"Loading test sets from " << validTestSets << 
", " << invalidTestSets << std::endl;
   445             std::vector<ObjectSetPtr> invalidSets = 
loadTestSetsFromDB(invalidTestSets, sceneName);
   447             std::cout << 
"Test set loading complete." << std::endl;
   448             std::cout << 
"Model initialized." << std::endl;
   457             double fullRecognitionRuntime = 0;
   461                 fullRecognitionRuntime += validRt.second;
   466                 fullRecognitionRuntime += invalidRt.second;
   475             std::cout << 
"Evaluation complete." << std::endl;
   478             std::vector<double> runtimes;
   480             std::ostringstream runtimesPerSetStream;
   481             runtimesPerSetStream << 
"Testset name, Average recognition runtime" << std::endl;
   482             for (std::pair<std::string, double> valuePair : recognitionRuntimes)
   484                 runtimes.push_back(valuePair.second);
   485                 runtimesPerSetStream << valuePair.first << 
", " << valuePair.second << std::endl;
   492             std::ostringstream falserec;
   493             falserec << 
"scene; false positives; false negatives; sum; average recognition runtime" << std::endl;
   501             std::cout << 
"Histogram created." << std::endl;
   504             std::cout << 
"timestepCounts.size() = " << 
timestepCounts.size() << 
", j = " << j << std::endl;
   518 int main(
int argc, 
char *argv[])
   521   outputPath = packagePath + 
"/data/test/performanceTestRessources";
   524     boost::filesystem::create_directories(
outputPath);
   534   std::vector<std::string> methods = {
   537       "combinatorial_optimization",
   538       "combinatorial_optimization",
   539       "combinatorial_optimization"   541   std::vector<std::string> algos = {
   549   while (
train && i < 1000)
   554       std::string subfolder = 
outputPath + 
"/" + std::to_string(i);
   555       if (!boost::filesystem::exists(subfolder))
   556         boost::filesystem::create_directories(subfolder);
   559           std::string demofolder = subfolder + 
"/" + demoRecording.stem().string();
   560           if (!boost::filesystem::exists(demofolder))
   561               boost::filesystem::create_directories(demofolder);
   567       catch (std::exception& e)
   569           std::ofstream errorfile;
   570           errorfile.open(subfolder + 
"/error.txt");
   571           if (errorfile.is_open())
   573               errorfile << e.what();
   576           std::cerr << e.what();
   582   std::string logFileName = 
"Log_x.txt";
   583   path logFilePath = 
outputPath + 
"/Logfile/" + logFileName;
   584   LogHelper::init(logFilePath, LOG_INFO);
 
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool find(const std::vector< double > &in, double toFind)
ROSLIB_DECL std::string getPath(const std::string &package_name)
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const