25 #include <boost/program_options.hpp> 31 #include <boost/filesystem.hpp> 40 namespace po = boost::program_options;
41 namespace fs = boost::filesystem;
52 TestSpec(
int setCount,
int objectCount,
bool useClustering,
double bin_size,
double maxAngleDeviation,
int useAPORater)
53 : setCount(setCount), objectCount(objectCount), useClustering(useClustering), bin_size(bin_size),
54 maxAngleDeviation(maxAngleDeviation), useAPORater(useAPORater) {}
65 if (fs::exists(filename)) {
93 void trainNewModel(
const std::string& sourceFile,
const string& testFile,
const int& objectCount,
const int& setCount,
const bool& useClustering)
101 set<pair<string, string> > typesAndIds;
109 std::pair<std::string, std::string> p = make_pair(obj->type, obj->observedId);
110 if (typesAndIds.find(p) == typesAndIds.end())
112 typesAndIds.insert(p);
117 set<pair<string, string> > typesAndIdsToUse;
118 while (typesAndIdsToUse.size() < (size_t)objectCount)
120 set<pair<string, string> >::iterator first = typesAndIds.begin();
121 typesAndIdsToUse.insert(*first);
122 typesAndIds.erase(first);
125 cerr <<
"creating test database";
132 std::pair<std::string, std::string> p = make_pair(obj->type, obj->observedId);
133 if (typesAndIdsToUse.find(p) != typesAndIdsToUse.end())
146 cerr <<
" done" << endl;
151 if (!useClustering) {
162 int main(
int argc,
char** argv) {
163 po::options_description desc(
"Allowed options");
164 desc.add_options()(
"help,h",
"produce help message")
165 (
"database-file,d", po::value<string>()->default_value(
"record.sqlite"),
"database file to use")
166 (
"test-database-file,t", po::value<string>()->default_value(
"test.sqlite"),
"database file write tests to")
167 (
"csv-file,c", po::value<string>()->default_value(
"results.csv"),
"csv file to write results");
169 po::variables_map vm;
170 po::store(po::parse_command_line(argc, argv, desc), vm);
173 if (vm.count(
"help")) {
174 cerr << desc <<
"\n";
178 vector<int> setCounts = { 1, 10, 50, 100, 500};
180 vector<bool> useClusterings = {
true,
false };
182 vector<double> bin_sizes = { 0.01, 0.1, 0.5 };
183 vector<double> maxAngleDeviations = {1.0, 10.0, 45.0};
186 vector<int> useAPORaterVec = { 0, 1 };
188 queue<TestSpec> tests;
189 stack<TestResult> testResults;
191 for (
int setCount : setCounts)
193 for (
int objectCount : objectCounts)
195 for (
bool useClustering : useClusterings)
197 for (
double bin_size : bin_sizes)
199 for (
double maxAngleDeviation : maxAngleDeviations)
201 for (
int useAPORater : useAPORaterVec)
203 TestSpec t =
TestSpec(setCount, objectCount, useClustering, bin_size, maxAngleDeviation, useAPORater);
214 string sourceFile = vm[
"database-file"].as<
string>();
215 string testFile = vm[
"test-database-file"].as<
string>();
217 string csvFilename = vm[
"csv-file"].as<
string>();
220 csvFile.open(csvFilename.c_str());
221 csvFile <<
"setCount, objectCount,useClustering,bin_size,maxAngleDeviation," 222 <<
"useAPORater,avgRuntime,avgConfidence,timeout" 229 cout<<
"generate random record db"<<endl;
231 cout<<
"finished generating"<<endl;
232 delete (recordingsTable);
238 while (!tests.empty()) {
250 TestResult testResult = { test, 0, 0,
false };
252 cerr <<
"recognizing";
259 struct timeval start, end;
261 gettimeofday(&start, NULL);
263 vector<RecognitionResultPtr> results = recognizer.
recognizePattern(testSet, 0, 1);
265 gettimeofday(&end, NULL);
267 long mtime, seconds, useconds;
268 seconds = end.tv_sec - start.tv_sec;
269 useconds = end.tv_usec - start.tv_usec;
271 mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5;
305 testResults.push(testResult);
const ObjectSetPtr getRecordedObjectSet(int setId) const
void setUseClustering(const bool useClustering)
int insertRecordedObjectSet(const boost::shared_ptr< ObjectSet > &os, const std::string &patternName)
boost::shared_ptr< RecordedPattern > RecordedPatternPtr
TestSpec(int setCount, int objectCount, bool useClustering, double bin_size, double maxAngleDeviation, int useAPORater)
void trainNewModel(const std::string &sourceFile, const string &testFile, const int &objectCount, const int &setCount, const bool &useClustering)
void printTest(const TestSpec &t)
void removeFileIfExists(const string &filename)
void generateDemoRecording(std::string dbfile, unsigned objects, unsigned timesteps, bool genRanOrientsAdditionally)
boost::shared_ptr< ObjectSet > ObjectSetPtr
boost::shared_ptr< RecognitionResult > RecognitionResultPtr
void writeTestResult(const TestResult &r, ofstream &csvFile)
const std::vector< RecognitionResultPtr > recognizePattern(const ObjectSetPtr &objectSet, const double filterThreshold=0.0, const int resultsPerPattern=-1, const std::string targetPatternName="")
std::vector< unsigned > objectCounts
std::vector< std::string > getRecordedPatternNames() const
void createTablesIfNecessary() const
this namespace contains all generally usable classes.
void printTestResult(const TestResult &r)
boost::shared_ptr< Object > ObjectPtr
int main(int argc, char **argv)
const RecordedPatternPtr getRecordedPattern(const std::string &patternName) const