22 #include <boost/program_options.hpp> 28 #include <boost/filesystem.hpp> 37 namespace po = boost::program_options;
38 namespace fs = boost::filesystem;
56 if (fs::exists(filename)) {
77 int main(
int argc,
char** argv) {
78 po::options_description desc(
"Allowed options");
79 desc.add_options()(
"help,h",
"produce help message")
80 (
"database-file,d", po::value<string>()->default_value(
"record.sqlite"),
"database file to use")
81 (
"test-database-file,t", po::value<string>()->default_value(
"test.sqlite"),
"database file write tests to")
82 (
"csv-file,c", po::value<string>()->default_value(
"results.csv"),
"csv file to write results");
85 po::store(po::parse_command_line(argc, argv, desc), vm);
88 if (vm.count(
"help")) {
93 vector<int> setCounts = { 10, 50, 100, 150, 200, 250, 300, 350, 400 };
94 vector<bool> useClusterings = {
true,
false };
96 vector<double> bin_sizes = {
97 0.5, 0.4, 0.3, 0.2, 0.1,
98 0.09, 0.08, 0.07, 0.06, 0.05, 0.04, 0.03, 0.02, 0.01
100 vector<bool> useIds = {
true };
101 vector<bool> useTypes = {
true };
103 queue<TestSpec> tests;
104 stack<TestResult> testResults;
106 for (
const int& setCount : setCounts) {
107 for (
const bool& useClustering : useClusterings) {
108 for (
const int& objectCount : objectCounts) {
109 for (
const double& bin_size : bin_sizes) {
110 for (
const bool& useId : useIds) {
111 for (
const bool& useType : useTypes) {
112 TestSpec t = { setCount, useClustering, objectCount, bin_size, useId, useType };
122 string sourceFile = vm[
"database-file"].as<
string>();
123 string testFile = vm[
"test-database-file"].as<
string>();
125 string csvFilename = vm[
"csv-file"].as<
string>();
128 csvFile.open(csvFilename.c_str());
129 csvFile <<
"setCount,objectCount,bin_size,useClustering,useType,useId,runtime,confidence" << endl;
131 while (!tests.empty()) {
140 set<pair<string, string> > typesAndIds;
148 pair<string, string> p = make_pair(obj->type, obj->observedId);
149 if (typesAndIds.find(p) == typesAndIds.end()) {
150 typesAndIds.insert(p);
155 set<pair<string, string> > typesAndIdsToUse;
156 while (typesAndIdsToUse.size() < (size_t)test.
objectCount) {
157 set<pair<string, string> >::iterator first = typesAndIds.begin();
158 typesAndIdsToUse.insert(*first);
159 typesAndIds.erase(first);
162 cerr <<
"creating test database";
164 string patternNameToUse;
170 pair<string, string> p = make_pair(obj->type, obj->observedId);
171 if (typesAndIdsToUse.find(p) != typesAndIdsToUse.end()) {
179 if (insertedSets >= test.
setCount) {
183 cerr <<
" done" << endl;
196 cerr <<
"recognizing";
200 for (
ObjectPtr& obj : testSet->objects) {
205 obj->observedId =
"";
211 struct timeval start, end;
213 gettimeofday(&start, NULL);
215 vector<RecognitionResultPtr> results = recognizer.
recognizePattern(testSet, 0, 1);
217 gettimeofday(&end, NULL);
219 long mtime, seconds, useconds;
220 seconds = end.tv_sec - start.tv_sec;
221 useconds = end.tv_usec - start.tv_usec;
223 mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5;
228 if (result->patternName == patternName) {
240 testResult.
avgRuntime /= (double) insertedSets;
242 testResults.push(testResult);
const ObjectSetPtr getRecordedObjectSet(int setId) const
void removeFileIfExists(const string &filename)
void printTestResult(const TestResult &r)
void setUseClustering(const bool useClustering)
int insertRecordedObjectSet(const boost::shared_ptr< ObjectSet > &os, const std::string &patternName)
boost::shared_ptr< RecordedPattern > RecordedPatternPtr
int main(int argc, char **argv)
void writeTestResult(const TestResult &r, ofstream &csvFile)
boost::shared_ptr< ObjectSet > ObjectSetPtr
boost::shared_ptr< RecognitionResult > RecognitionResultPtr
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 printTest(const TestSpec &t)
this namespace contains all generally usable classes.
boost::shared_ptr< Object > ObjectPtr
const RecordedPatternPtr getRecordedPattern(const std::string &patternName) const