CMS 3D CMS Logo

SprTrainedBinarySplit.cc

Go to the documentation of this file.
00001 //$Id: SprTrainedBinarySplit.cc,v 1.2 2007/09/21 22:32:10 narsky Exp $
00002 
00003 #include "PhysicsTools/StatPatternRecognition/interface/SprExperiment.hh"
00004 #include "PhysicsTools/StatPatternRecognition/interface/SprTrainedBinarySplit.hh"
00005 #include "PhysicsTools/StatPatternRecognition/interface/SprUtils.hh"
00006 
00007 #include <stdio.h>
00008 #include <utility>
00009 #include <cassert>
00010 
00011 using namespace std;
00012 
00013 
00014 SprTrainedBinarySplit::SprTrainedBinarySplit(unsigned d, 
00015                                              const SprCut& inputCut) 
00016   :  
00017   SprAbsTrainedClassifier(), 
00018   d_(d), 
00019   inputCut_(inputCut) 
00020 {
00021   // set cut on classifier output
00022   this->setCut(SprUtils::lowerBound(0.5));
00023 }
00024 
00025 SprTrainedBinarySplit::SprTrainedBinarySplit(const SprTrainedBinarySplit& 
00026                                              other)
00027   : 
00028   SprAbsTrainedClassifier(other),
00029   d_(other.d_),
00030   inputCut_(other.inputCut_)
00031 {}
00032 
00033 
00034 double SprTrainedBinarySplit::response(const std::vector<double>& v) const
00035 {
00036   // sanity check
00037   assert( d_ < v.size() );
00038 
00039   // cut
00040   int accept = 1;
00041   if( !inputCut_.empty() ) {
00042     for( int i=0;i<inputCut_.size();i++ ) {
00043       if( v[d_]<inputCut_[i].first || v[d_]>inputCut_[i].second ) {
00044         accept = 0;
00045         break;
00046       }
00047     }
00048   }
00049 
00050   // exit
00051   return accept;
00052 }
00053 
00054 
00055 void SprTrainedBinarySplit::print(std::ostream& os) const
00056 {
00057   os << "Trained BinarySplit " << SprVersion << endl;
00058   os << "Dimension: " << d_ << endl;
00059   os << "Cut: " << inputCut_.size() << endl;
00060   for( int i=0;i<inputCut_.size();i++ ) {
00061     char s [200];
00062     sprintf(s,"%10g %10g",inputCut_[i].first,inputCut_[i].second);
00063     os << s << endl;
00064   }
00065 }
00066 

Generated on Tue Jun 9 17:42:04 2009 for CMSSW by  doxygen 1.5.4