/** * @file ClassificationResults.cpp // refactor-nice.pl: check this substitution // old: * @brief vector of ClassificationResult * @brief std::vector of ClassificationResult * @author Erik Rodner * @date 02/13/2008 */ #include "core/image/ImageT.h" #include "core/vector/VectorT.h" #include "core/vector/MatrixT.h" #include #include #include #include "vislearning/cbaselib/ClassificationResults.h" #include "vislearning/cbaselib/LocalizationAnalysis.h" using namespace OBJREC; using namespace std; using namespace NICE; ClassificationResults::ClassificationResults() { } ClassificationResults::~ClassificationResults() { } void ClassificationResults::writeWEKA ( const std::string & filename, int classno ) const { ofstream ofs ( filename.c_str(), ios::out ); int instno = 0; for ( const_iterator i = begin(); i != end() ; i++, instno++ ) { const ClassificationResult & r = *i; double confidence = r.scores.get(classno); ofs << instno << ", " << r.classno_groundtruth << ", " < > resultsFlat; uint countPositives = 0; uint countNegatives = 0; for ( const_iterator i = begin(); i != end(); i++ ) { const ClassificationResult & r = *i; double confidence = r.scores.get(1); uint classno_groundtruth = r.classno_groundtruth; resultsFlat.push_back ( pair ( confidence, classno_groundtruth ) ); if ( classno_groundtruth == 1 ) countPositives++; if ( classno_groundtruth == 0 ) countNegatives++; } if ( countPositives <= 0 ) fthrow(Exception, "No positive ground truth examples"); if ( countNegatives <= 0 ) fthrow(Exception, "No negative ground truth examples"); vector thresholds, x, y; if ( type == PERF_AUC ) la.calcROCCurve ( resultsFlat, countPositives, countNegatives, thresholds, x, y ); else la.calcRecallPrecisionCurve ( resultsFlat, countPositives, thresholds, x, y ); if ( type == PERF_AUC ) return la.calcAreaUnderROC ( x, y ); else if ( type == PERF_AVG_PRECISION_11_POINT ) return la.calcAveragePrecision ( x, y ); else return la.calcAveragePrecisionPrecise ( x, y ); }