23 #include <ISM/TableHelper.hpp> 24 #include <ISM/Recognizer.hpp> 26 #define ISM_DATA "/media/share/data" 31 void drawISM(
string model,
string patternName, map<
string, map<string, unsigned> >graphVizData,
unsigned testsPerformed,
unsigned timeSteps)
33 if (testsPerformed == 0)
38 stringstream filePath;
39 filePath<<std::string(
ISM_DATA)+
"/evaluation/gedeck_evaluation/complexity/"<<patternName<<
"_"<<model<<
"_ISMWithVotes.dot";
42 vector<pair<string, string> > alreadyTakenCombinations;
43 ios_base::iostate exceptionMask = file.exceptions() | ios::failbit | ios::badbit;
44 file.exceptions(exceptionMask);
49 file<<
"digraph "<<model<<
" {\n";
50 for (
auto type : graphVizData)
52 for (
auto voteIt : type.second)
54 file<<voteIt.first<<
"[shape=\"box\"];\n";
58 for (
auto typeIt : graphVizData)
60 for (
auto voteIt : typeIt.second)
62 if (find(alreadyTakenCombinations.begin(), alreadyTakenCombinations.end(), make_pair(voteIt.first, typeIt.first)) == alreadyTakenCombinations.end())
65 file<<voteIt.first<<
" -> "<<typeIt.first<<
"[ label=\" ∪" 66 <<(unsigned)((((
double)voteIt.second) / testsPerformed) / timeSteps)<<
"|→" 68 <<(unsigned)(((
double)voteIt.second) / testsPerformed)
70 <<
"\", decorate=\"true\", labelfoat=\"true\", labelfontcolor=\"red\", dir=\"back\"];\n";
71 alreadyTakenCombinations.push_back(make_pair(voteIt.first, typeIt.first));
79 catch (ios_base::failure& e)
86 void addVizData(std::map<std::string, std::map<std::string, unsigned> >& graphVizData,
const RecognizerPtr& recognizer)
88 std::map<ObjectPtr, std::vector<VotedPosePtr> > votingCache = recognizer->getVotingCache();
89 for (
auto it : votingCache)
91 for (
auto voteIt : it.second)
93 ++graphVizData[it.first->getType()][voteIt->vote->patternName];
99 int main (
int argc,
char**argv)
101 std::vector<std::pair<std::string, std::string> > modeldbs =
103 std::make_pair(
"best", std::string(
ISM_DATA)+
"/evaluation/gedeck_evaluation/sourcedbs/record.sqlite.optedTrainer_example_1_best"),
104 std::make_pair(
"best_naive", std::string(
ISM_DATA)+
"/evaluation/gedeck_evaluation/sourcedbs/record.sqlite.optedTrainer_example_1_best_naive"),
105 std::make_pair(
"star", std::string(
ISM_DATA)+
"/evaluation/gedeck_evaluation/sourcedbs/record.sqlite.optedTrainer_example_1_star"),
106 std::make_pair(
"fully_meshed", std::string(
ISM_DATA)+
"/evaluation/gedeck_evaluation/sourcedbs/record.sqlite.optedTrainer_example_1_fullyMeshed"),
107 std::make_pair(
"fully_meshed_naive",std::string(
ISM_DATA)+
"/evaluation/gedeck_evaluation/sourcedbs/record.sqlite.optedTrainer_example_1_fullyMeshed_naive")
110 output.open(std::string(
ISM_DATA)+
"/evaluation/gedeck_evaluation/output.csv");
111 output<<
"model, avgTime, falsePositives\n";
112 for (
auto model : modeldbs)
114 std::map<std::string, std::map<std::string, unsigned> > vizData;
115 cout<<
"trying to open db file\n";
116 TableHelperPtr validSetsTable(
new TableHelper(std::string(
ISM_DATA)+
"/evaluation/gedeck_evaluation/sourcedbs/record.sqlite.optedTrainer_example_1_validTestSets"));
117 cout<<
"could open valid sets\n";
118 auto validPatterns = validSetsTable->getRecordedPattern(
"optedTrainer_example_1");
119 vector<ObjectSetPtr> validSets;
120 if (validPatterns != 0)
122 validSets = validPatterns->objectSets;
124 struct timeval start, end;
126 TableHelperPtr invalidSetsTable(
new TableHelper(std::string(
ISM_DATA)+
"/evaluation/gedeck_evaluation/sourcedbs/record.sqlite.optedTrainer_example_1_invalidTestSets"));
127 cout<<
"could open invalid sets\n ";
128 auto invalidPatterns = invalidSetsTable->getRecordedPattern(
"optedTrainer_example_1");
129 vector<ObjectSetPtr> invalidSets;
130 if (invalidPatterns != 0)
132 invalidSets = invalidPatterns->objectSets;
134 cout<<invalidSets.size()<<endl;
135 RecognizerPtr recog(
new Recognizer(model.second, 0.03, 10,
false));
136 cout<<
"could create recognizer\n";
137 for (
auto validSet : validSets)
139 if (model.first ==
"fully_meshed_naive")
143 cout<<
".";cout.flush();
144 gettimeofday(&start, NULL);
145 auto res = recog->recognizePattern(validSet, 0.0, 1);
146 gettimeofday(&end, NULL);
147 time += ((end.tv_sec - start.tv_sec) * 1000) + ((end.tv_usec - start.tv_usec) / 1000);
151 for (
auto invalidSet : invalidSets)
153 cout<<
".";cout.flush();
154 gettimeofday(&start, NULL);
155 auto res = recog->recognizePattern(invalidSet, 0.0, 1);
156 gettimeofday(&end, NULL);
157 time += ((end.tv_sec - start.tv_sec) * 1000) + ((end.tv_usec - start.tv_usec) / 1000);
159 if (res.size() > 0 && res[0]->getConfidence() == 1 && res[0]->getPatternName() ==
"optedTrainer_example_1")
163 if (model.first ==
"fully_meshed_naive")
169 if (model.first ==
"fully_meshed_naive")
171 drawISM(model.first,
"optedTrainer_example_1", vizData, 1, 112.0);
172 avg = ((double)time) / 1.0;
176 drawISM(model.first,
"optedTrainer_example_1", vizData, validSets.size() + invalidSets.size(), 112.0);
177 avg = ((double)time) / (validSets.size() + invalidSets.size());
180 output<<model.first<<
","<<avg<<
","<<fps<<endl;
void addVizData(std::map< std::string, std::map< std::string, unsigned > > &graphVizData, const RecognizerPtr &recognizer)
int main(int argc, char **argv)
void drawISM(string model, string patternName, map< string, map< string, unsigned > >graphVizData, unsigned testsPerformed, unsigned timeSteps)