00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef BEOBOT_GSNAV_RESULT_H_DEFINED
00038 #define BEOBOT_GSNAV_RESULT_H_DEFINED
00039
00040 #include "Image/Image.H"
00041 #include "Image/MathOps.H"
00042
00043
00044
00045
00046 class GSnavResult
00047 {
00048 public:
00049
00050
00051 std::vector<double> segError;
00052 std::vector<uint> segCount;
00053 std::vector<uint> eSegCount;
00054
00055 std::vector<uint> nSegObject;
00056 std::vector<uint> nSegObjectSearch;
00057
00058 std::vector<uint> nSegObjectFound;
00059 std::vector<uint> nSegObjectFoundSearch;
00060
00061 std::vector<uint> nSegObjectNotFound;
00062 std::vector<uint> nSegObjectNotFoundSearch;
00063
00064
00065 std::vector<double> error;
00066 double stdevError;
00067
00068 std::vector<uint> nObject;
00069 double stdevNObject;
00070 std::vector<uint> nObjectSearch;
00071
00072 std::vector<uint> nObjectFound;
00073 double stdevNObjectFound;
00074 std::vector<uint> nObjectFoundSearch;
00075
00076 std::vector<uint> nObjectNotFound;
00077 double stdevNObjectNotFound;
00078 std::vector<uint> nObjectNotFoundSearch;
00079
00080
00081 uint nsegment;
00082 std::string savePrefix;
00083
00084
00085 double terror; uint tcount;
00086 uint tfobj; uint tfsearch;
00087 uint tnfobj; uint tnfsearch;
00088 uint tobj; uint tsearch;
00089 uint itsSearchCount;
00090
00091 inline void combine(std::string inSavePrefix);
00092 inline void read(std::string inSavePrefix, uint inNsegment);
00093 inline void createSummaryResult();
00094 inline void getSearchResult(std::vector<uint> index);
00095 };
00096
00097
00098 inline void GSnavResult::combine(std::string inSavePrefix)
00099 {
00100 savePrefix = inSavePrefix;
00101
00102
00103 std::string resFName = savePrefix + sformat("_results.txt");
00104 std::string resGSfName = savePrefix + sformat("_GS_results.txt");
00105 FILE *rfp; LINFO("res files: %s", resFName.c_str());
00106 if((rfp = fopen(resFName.c_str(),"rb")) == NULL)LFATAL("not found");
00107 FILE *gfp; LINFO("GS res files: %s", resGSfName.c_str());
00108 if((gfp = fopen(resGSfName.c_str(),"rb")) == NULL)LFATAL("not found");
00109
00110
00111 std::vector<std::string> rfpLines;
00112 char inLine[200];
00113 while(fgets(inLine, 200, rfp) != NULL)
00114 {
00115 rfpLines.push_back(std::string(inLine));
00116 }
00117
00118
00119 uint lind = 0;
00120 std::vector<std::string> cfpLines;
00121
00122 std::string resCfName = savePrefix + sformat("_comb_results.txt");
00123 FILE *rFile = fopen(resCfName.c_str(), "at");
00124 if (rFile == NULL) LFATAL("can't create res file: %s",
00125 resCfName.c_str());
00126
00127 while(fgets(inLine, 200, gfp) != NULL)
00128 {
00129
00130 char tLine[200]; uint cind;
00131 sscanf(inLine, "%d %s", &cind, tLine);
00132 LDEBUG("%6d <<%s>>", cind, tLine);
00133
00134
00135 for(uint i = lind; i < cind; i++)
00136 {
00137 cfpLines.push_back(rfpLines[i]);
00138 LDEBUG("%s", rfpLines[i].c_str());
00139 fputs(rfpLines[i].c_str(), rFile);
00140 }
00141
00142
00143 std::string temp(inLine);
00144 std::string::size_type lzpos = rfpLines[cind].find_last_of('0');
00145 std::string::size_type pos = temp.find_first_not_of(' ');
00146 temp = temp.substr(pos);
00147 pos = temp.find_first_of(' ');
00148 temp = rfpLines[cind].substr(0, lzpos) + temp.substr(pos+1);
00149 cfpLines.push_back(temp);
00150 LDEBUG("[%d] %s", itsSearchCount, temp.c_str());
00151
00152 fputs(temp.c_str(), rFile);
00153
00154 lind = cind+1;
00155 }
00156 fclose (rFile);
00157 }
00158
00159
00160 inline void GSnavResult::read(std::string inSavePrefix, uint inNsegment)
00161 {
00162 savePrefix = inSavePrefix;
00163 nsegment = inNsegment;
00164
00165
00166
00167 std::string resFName = savePrefix + sformat("_results.txt");
00168 FILE *fp; LINFO("result file: %s", resFName.c_str());
00169 if((fp = fopen(resFName.c_str(),"rb")) == NULL)LFATAL("not found");
00170
00171
00172 segError.resize(nsegment);
00173 segCount.resize(nsegment);
00174 eSegCount.resize(nsegment);
00175
00176 nSegObject.resize(nsegment);
00177 nSegObjectSearch.resize(nsegment);
00178
00179 nSegObjectFound.resize(nsegment);
00180 nSegObjectFoundSearch.resize(nsegment);
00181
00182 nSegObjectNotFound.resize(nsegment);
00183 nSegObjectNotFoundSearch.resize(nsegment);
00184
00185 for(uint i = 0; i < nsegment; i++) segError[i] = 0.0F;
00186 for(uint i = 0; i < nsegment; i++) segCount[i] = 0;
00187 for(uint i = 0; i < nsegment; i++) eSegCount[i] = 0;
00188
00189 for(uint i = 0; i < nsegment; i++) nSegObjectFound[i] = 0;
00190 for(uint i = 0; i < nsegment; i++) nSegObjectFoundSearch[i] = 0;
00191
00192 for(uint i = 0; i < nsegment; i++) nSegObjectNotFound[i] = 0;
00193 for(uint i = 0; i < nsegment; i++) nSegObjectNotFoundSearch[i] = 0;
00194
00195
00196 char inLine[200];
00197 itsSearchCount = 0;
00198 while(fgets(inLine, 200, fp) != NULL)
00199 {
00200 int index; uint ninput;
00201 uint snumGT; float ltravGT;
00202 uint snumRes; float ltravRes; float err;
00203
00204
00205 char tLine[200];
00206 sscanf(inLine, "%d %d %f %d %f %f %d %s", &index,
00207 &snumGT, <ravGT, &snumRes, <ravRes, &err, &ninput, tLine);
00208 LDEBUG("%6d %6d %10.6f %6d %10.6f %10.6f %6d", index,
00209 snumGT, ltravGT, snumRes, ltravRes, err, ninput);
00210
00211 if(ninput != 0) itsSearchCount++;
00212
00213 segError[snumGT] += double(err);
00214 segCount[snumGT]++;
00215 error.push_back(err);
00216
00217 if(snumGT != snumRes) eSegCount[snumGT]++;
00218
00219
00220 uint nFound = 0; uint nFoundSearch = 0;
00221 uint nNFound = 0; uint nNotFoundSearch = 0;
00222 std::string line(inLine);
00223 for(uint i = 0; i < ninput; i++)
00224 {
00225
00226 int pos = line.find_last_of(' ');
00227 uint tnsearch = atoi(line.substr(pos+1).c_str());
00228 line = line.substr(0, pos);
00229 line = line.substr(0, line.find_last_not_of(' ')+1);
00230
00231 pos = line.find_last_of(' ');
00232 bool tfound = !(line.substr(pos+1).compare("1"));
00233 line = line.substr(0, pos);
00234 line = line.substr(0, line.find_last_not_of(' ')+1);
00235
00236 LDEBUG("%d %d", tfound, tnsearch);
00237
00238 if(tfound)
00239 {
00240 nSegObjectFound[snumGT]++;
00241 nSegObjectFoundSearch[snumGT] += tnsearch;
00242 nFound++;
00243 nFoundSearch += tnsearch;
00244 }
00245 else
00246 {
00247 nSegObjectNotFound[snumGT]++;
00248 nSegObjectNotFoundSearch[snumGT] += tnsearch;
00249 nNFound++;
00250 nNotFoundSearch += tnsearch;
00251 }
00252
00253 LDEBUG("%d %d - %d %d",
00254 nSegObjectFound[snumGT], nSegObjectFoundSearch[snumGT],
00255 nSegObjectNotFound[snumGT], nSegObjectNotFoundSearch[snumGT]);
00256 }
00257
00258
00259 nObjectFound.push_back(nFound);
00260 nObjectNotFound.push_back(nNFound);
00261 nObject.push_back(nFound + nNFound);
00262
00263 nObjectFoundSearch.push_back(nFoundSearch);
00264 nObjectNotFoundSearch.push_back(nNotFoundSearch);
00265 nObjectSearch.push_back(nFoundSearch + nNotFoundSearch);
00266 }
00267 fclose(fp);
00268
00269
00270 terror = 0.0; tcount = 0;
00271 tfobj = 0; tfsearch = 0;
00272 tnfobj = 0; tnfsearch = 0;
00273 tobj = 0; tsearch = 0;
00274 for(uint i = 0; i < nsegment; i++)
00275 {
00276 terror+= segError[i];
00277 tcount+= segCount[i];
00278
00279
00280 nSegObject[i] = nSegObjectFound[i] + nSegObjectNotFound[i];
00281 nSegObjectSearch[i] =
00282 nSegObjectFoundSearch[i] + nSegObjectNotFoundSearch[i];
00283
00284 tfobj += nSegObjectFound[i];
00285 tfsearch += nSegObjectFoundSearch[i];
00286 tnfobj += nSegObjectNotFound[i];
00287 tnfsearch += nSegObjectNotFoundSearch[i];
00288 tobj += nSegObject[i];
00289 tsearch += nSegObjectSearch[i];
00290 }
00291
00292
00293 Image<double> t1(1,nObjectFound.size(),NO_INIT);
00294 for(uint i = 0; i < nObjectFound.size(); i++)
00295 t1.setVal(0, i, double(nObjectFound[i]));
00296 stdevNObjectFound = stdev(t1);
00297
00298 for(uint i = 0; i < nObjectNotFound.size(); i++)
00299 t1.setVal(0, i, double(nObjectNotFound[i]));
00300 stdevNObjectNotFound = stdev(t1);
00301
00302 for(uint i = 0; i < nObjectFound.size(); i++)
00303 t1.setVal(0, i, double(nObject[i]));
00304 stdevNObject = stdev(t1);
00305
00306 Image<double> t2(1,error.size(),NO_INIT);
00307 for(uint i = 0; i < error.size(); i++) t2.setVal(0, i, error[i]);
00308 stdevError = stdev(t2);
00309 }
00310
00311
00312 inline void GSnavResult::createSummaryResult()
00313 {
00314 std::string sresFName = savePrefix + sformat("_summary_results.txt");
00315 FILE *rfp; LINFO("result file: %s", sresFName.c_str());
00316 if((rfp = fopen(sresFName.c_str(),"wt")) == NULL)LFATAL("not found");
00317
00318
00319 for(uint i = 0; i < nsegment; i++)
00320 {
00321 std::string line(sformat("[%6d]: 0 0.0 0",i));
00322 if(segCount[i] > 0)
00323 {
00324 line = sformat
00325 ("[%6d]: %6d %10.6f %6d -- %6d %10d: %10.3f + %6d %10d: %10.3f"
00326 " = %6d %10d %10.3f",
00327 i, segCount[i], segError[i]/segCount[i], eSegCount[i],
00328 nSegObjectFound[i], nSegObjectFoundSearch[i],
00329 nSegObjectFoundSearch[i]/double(nSegObjectFound[i]),
00330 nSegObjectNotFound[i], nSegObjectNotFoundSearch[i],
00331 nSegObjectNotFoundSearch[i]/double(nSegObjectNotFound[i]),
00332 nSegObject[i], nSegObjectSearch[i],
00333 double(nSegObjectSearch[i])/nSegObject[i]);
00334 }
00335 LINFO("%s",line.c_str());
00336 line += std::string("\n");
00337 fputs(line.c_str(), rfp);
00338 }
00339
00340
00341 std::string lline =
00342 sformat
00343 ("total : %6d %10.6f -- %6d %10d: %10.3f + %6d %10d: %10.3f"
00344 " = %6d %10d %10.3f",
00345 tcount, terror/tcount, tfobj, tfsearch, tfsearch/double(tfobj),
00346 tnfobj, tnfsearch, tnfsearch/double(tnfobj),
00347 tobj, tsearch, tsearch/double(tobj));
00348 LINFO("%s", lline.c_str());
00349 LINFO("search count: %d: %f + %f = %f",
00350 itsSearchCount, double(tfobj)/itsSearchCount,
00351 double(tnfobj)/itsSearchCount, double(tobj)/itsSearchCount);
00352 lline += std::string("\n");
00353 fputs(lline.c_str(), rfp);
00354 fclose (rfp);
00355 }
00356
00357
00358 inline void GSnavResult::getSearchResult(std::vector<uint> index)
00359 {
00360 uint tfObj = 0; uint tfSearch = 0;
00361 uint tnfObj = 0; uint tnfSearch = 0;
00362 uint tObj = 0; uint tSearch = 0;
00363
00364
00365 for(uint i = 0; i < index.size(); i++)
00366 {
00367 tfObj += nObjectFound[index[i]];
00368 tnfObj += nObjectNotFound[index[i]];
00369 tObj += nObject[index[i]];
00370
00371 tfSearch += nObjectFoundSearch[index[i]];
00372 tnfSearch += nObjectNotFoundSearch[index[i]];
00373 tSearch += nObjectSearch[index[i]];
00374 }
00375
00376
00377 LINFO("%6d %10d: %10.3f + %6d %10d: %10.3f = %6d %10d %10.3f| ",
00378 tfObj, tfSearch, tfSearch/float(tfObj),
00379 tnfObj, tnfSearch, tnfSearch/float(tnfObj),
00380 tObj, tSearch, tSearch/float(tObj));
00381 }
00382
00383
00384
00385
00386
00387
00388 class GSnav_M_Result
00389 {
00390 public:
00391
00392
00393 std::vector<double> bbmtTime;
00394 double meanBbmtTime, minBbmtTime, maxBbmtTime, stdevBbmtTime;
00395
00396 std::vector<double> dorsalTime;
00397 double meanDorsalTime, minDorsalTime, maxDorsalTime, stdevDorsalTime;
00398
00399 std::vector<double> ventralTime;
00400 double meanVentralTime, minVentralTime, maxVentralTime, stdevVentralTime;
00401
00402 std::vector<double> inputTime;
00403 double meanInputTime, minInputTime, maxInputTime, stdevInputTime;
00404
00405
00406 std::vector<uint> ventralSearchEndFrame;
00407 std::vector<uint> ventralSearchNumFrame;
00408 std::vector<double> ventralSearchTime;
00409 double meanVentralSearchTime, minVentralSearchTime,
00410 maxVentralSearchTime, stdevVentralSearchTime;
00411
00412
00413 std::string savePrefix;
00414
00415 inline void read(std::string inSavePrefix);
00416 };
00417
00418
00419 inline void GSnav_M_Result::read(std::string inSavePrefix)
00420 {
00421 savePrefix = inSavePrefix;
00422
00423
00424 std::string resFName = savePrefix + sformat("_M_results.txt");
00425 FILE *fp; LINFO("result file: %s", resFName.c_str());
00426 if((fp = fopen(resFName.c_str(),"rb")) == NULL)LFATAL("not found");
00427
00428
00429 char inLine[200];
00430 while(fgets(inLine, 200, fp) != NULL)
00431 {
00432 uint index; float bTime, dTime, vTime, iTime;
00433 int rCL, rNL; bool resetNL;
00434
00435
00436 sscanf(inLine, "%d %f %d %d %f %f %f",
00437 &index, &bTime, &rCL, &rNL, &dTime, &vTime, &iTime);
00438 LDEBUG("%5d %11.5f %d %d %11.5f %11.5f %11.5f",
00439 index, bTime, rCL, rNL, dTime, vTime, iTime);
00440 if(rNL > 0) resetNL = true; else resetNL = false;
00441
00442
00443 bbmtTime.push_back(bTime);
00444 dorsalTime.push_back(dTime);
00445 ventralTime.push_back(vTime);
00446 inputTime.push_back(iTime);
00447
00448
00449 if(resetNL)
00450 {
00451 LDEBUG("[%4"ZU"]: %d line: %s",
00452 ventralSearchEndFrame.size(), index-1, inLine);
00453
00454 ventralSearchEndFrame.push_back(index-1);
00455
00456 if(ventralSearchNumFrame.size() == 0)
00457 ventralSearchNumFrame.push_back(0);
00458 else
00459 {
00460 uint tNum = ventralSearchNumFrame.back();
00461 ventralSearchNumFrame.push_back(index-1 - tNum);
00462 }
00463 ventralSearchTime.push_back(vTime);
00464 }
00465 }
00466
00467
00468 bbmtTime.pop_back();
00469 dorsalTime.erase(dorsalTime.begin());
00470 ventralTime.erase(ventralTime.begin());
00471
00472 ventralSearchEndFrame.erase(ventralSearchEndFrame.begin());
00473 ventralSearchNumFrame.erase(ventralSearchNumFrame.begin());
00474 ventralSearchTime.erase(ventralSearchTime.begin());
00475
00476
00477 Image<double> t1(1, bbmtTime.size(),NO_INIT);
00478 for(uint i = 0; i < bbmtTime.size(); i++)
00479 t1.setVal(0, i, double(bbmtTime[i]));
00480 meanBbmtTime = mean(t1);
00481 getMinMax(t1, minBbmtTime, maxBbmtTime);
00482 stdevBbmtTime = stdev(t1);
00483
00484 Image<double> t2(1, dorsalTime.size(),NO_INIT);
00485 for(uint i = 0; i < dorsalTime.size(); i++)
00486 t2.setVal(0, i, double(dorsalTime[i]));
00487 meanDorsalTime = mean(t2);
00488 getMinMax(t2, minDorsalTime, maxDorsalTime);
00489 stdevDorsalTime = stdev(t2);
00490
00491 Image<double> t3(1, ventralSearchTime.size(),NO_INIT);
00492 for(uint i = 0; i < ventralSearchTime.size(); i++)
00493 t3.setVal(0, i, double(ventralSearchTime[i]));
00494 meanVentralSearchTime = mean(t3);
00495 getMinMax(t3, minVentralSearchTime, maxVentralSearchTime);
00496 stdevVentralSearchTime = stdev(t3);
00497
00498 Image<double> t4(1, inputTime.size(),NO_INIT);
00499 for(uint i = 0; i < inputTime.size(); i++)
00500 t4.setVal(0, i, double(inputTime[i]));
00501 meanInputTime = mean(t4);
00502 getMinMax(t4, minInputTime, maxInputTime);
00503 stdevInputTime = stdev(t4);
00504 }
00505
00506 #endif
00507
00508
00509
00510
00511
00512