Ejemplo n.º 1
0
ErrorStruct StrongClassifier::errorForFeatures(const TrainingData &features, bool printStats) const {

  ErrorStruct e;

  for (int i=0; i<features.size(); i++) {
    FeatureVector feature = *(features.feature(i));
    if (decide(feature)) {
      feature.val() == POS ? e.true_pos++ : e.false_pos++;//it is really positive
    } else {
      feature.val() == NEG ? e.true_neg++ : e.false_neg++;//it is really negative
    }
  }

  // if all 10 samples, 3 is misclassified, error is 3/10
  e.error = (e.false_pos + e.false_neg) / ((float)features.size()); 

  if (printStats) {
    std::cout << e.true_pos << " true positives" << std::endl;
    std::cout << e.false_pos << " false positives" << std::endl;
    std::cout << e.true_neg << " true negatives" << std::endl;
    std::cout << e.false_neg << " false negatives" << std::endl;
    std::cout << e.error * 100 << "% error" << std::endl;
    std::cout << std::endl;
  }

  return e;
}
Ejemplo n.º 2
0
/**************************************
 * Fucntion: is_classifier_correct
 * -------------------------------
 * returns true if weak classifier (wc) correctly identified the 
 * feature vector (fv), false otherwise.
 */
bool AdaBooster::is_classifier_correct(WeakClassifier &wc, FeatureVector &fv){
	
	// check if threshold is greater than (or equal to) feature
	bool guess = ( wc.threshold() >= fv.at(wc.dimension()) );

	// if classifier is flipped, negate guess
	guess = wc.isFlipped() ? !guess : guess;

	// find actual value of point
	bool real = ( fv.val() == POS );

	// return if guess and real agree
	return ( real == guess );

}