12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- /**
- * @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 <iostream>
- #include <fstream>
- #include <iomanip>
- #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 << ", " <<setiosflags(ios::fixed)<< setprecision(20)<<confidence << ", " << r.classno << endl;
- }
- ofs.close();
- }
- double ClassificationResults::getBinaryClassPerformance ( int type ) const
- {
- LocalizationAnalysis la;
- vector< pair<double, int> > 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<double, int> ( 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<double> 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 );
- }
|