CMS 3D CMS Logo

SprTrainedDecisionTree.cc

Go to the documentation of this file.
00001 // $Id: SprTrainedDecisionTree.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/SprTrainedDecisionTree.hh"
00005 
00006 #include <stdio.h>
00007 #include <cassert>
00008 
00009 using namespace std;
00010 
00011 
00012 double SprTrainedDecisionTree::response(const std::vector<double>& v) const
00013 {
00014   // go through signal nodes
00015   for( int i=0;i<nodes1_.size();i++ ) {
00016     bool accepted = true;
00017     for( SprBox::const_iterator iter=nodes1_[i].begin();
00018          iter!=nodes1_[i].end();iter++ ) {
00019       unsigned d = iter->first;
00020       assert( d < v.size() );
00021       if( v[d]<iter->second.first || v[d]>iter->second.second ) {
00022         accepted = false;
00023         break;
00024       }
00025     }
00026     if( accepted ) return 1;
00027   }
00028   return 0;
00029 }
00030 
00031 
00032 int SprTrainedDecisionTree::nBox(const std::vector<double>& v) const
00033 {
00034   // go through signal nodes
00035   for( int i=0;i<nodes1_.size();i++ ) {
00036     bool accepted = true;
00037     for( SprBox::const_iterator iter=nodes1_[i].begin();
00038          iter!=nodes1_[i].end();iter++ ) {
00039       unsigned d = iter->first;
00040       assert( d < v.size() );
00041       if( v[d]<iter->second.first || v[d]>iter->second.second ) {
00042         accepted = false;
00043         break;
00044       }
00045     }
00046     if( accepted ) return i;
00047   }
00048   return -1;
00049 }
00050 
00051 
00052 void SprTrainedDecisionTree::print(std::ostream& os) const
00053 {
00054   os << "Trained DecisionTree " << SprVersion << endl;
00055   os << "Nodes: " << nodes1_.size() << " nodes." << endl;
00056   for( int i=0;i<nodes1_.size();i++ ) {
00057     const SprBox& limits = nodes1_[i];
00058     int size = limits.size();
00059     os << "Node " << i << " Size " << size << endl;
00060     for( SprBox::const_iterator iter=limits.begin();
00061          iter!=limits.end();iter++ ) {
00062       char s [200];
00063       sprintf(s,"Dimension %4i    Limits %15g %15g",
00064               iter->first,iter->second.first,iter->second.second);
00065       os << s << endl;
00066     }
00067   }
00068 }

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