#include <stdexcept>
#include <iomanip>
#include <assert.h>
#include <cstdlib>
#include "TMVA/BinarySearchTreeNode.h"
#include "TMVA/Event.h"
#include "TMVA/MsgLogger.h"
#include "TMVA/Tools.h"
ClassImp(TMVA::BinarySearchTreeNode)
TMVA::BinarySearchTreeNode::BinarySearchTreeNode( const Event* e, UInt_t )
: TMVA::Node(),
fEventV ( std::vector<Float_t>() ),
fTargets ( std::vector<Float_t>() ),
fWeight ( e==0?0:e->GetWeight() ),
fClass ( e==0?0:e->GetClass() ),
fSelector( -1 )
{
if (e!=0) {
for (UInt_t ivar=0; ivar<e->GetNVariables(); ivar++) fEventV.push_back(e->GetValue(ivar));
for (std::vector<Float_t>::const_iterator it = e->GetTargets().begin(); it < e->GetTargets().end(); it++ ) {
fTargets.push_back( (*it) );
}
}
}
TMVA::BinarySearchTreeNode::BinarySearchTreeNode( BinarySearchTreeNode* parent, char pos ) :
TMVA::Node(parent,pos),
fEventV ( std::vector<Float_t>() ),
fTargets ( std::vector<Float_t>() ),
fWeight ( 0 ),
fClass ( 0 ),
fSelector( -1 )
{
}
TMVA::BinarySearchTreeNode::BinarySearchTreeNode ( const BinarySearchTreeNode &n,
BinarySearchTreeNode* parent ) :
TMVA::Node(n),
fEventV ( n.fEventV ),
fTargets ( n.fTargets ),
fWeight ( n.fWeight ),
fClass ( n.fClass ),
fSelector( n.fSelector )
{
this->SetParent( parent );
if (n.GetLeft() == 0 ) this->SetLeft(NULL);
else this->SetLeft( new BinarySearchTreeNode( *((BinarySearchTreeNode*)(n.GetLeft())),this));
if (n.GetRight() == 0 ) this->SetRight(NULL);
else this->SetRight( new BinarySearchTreeNode( *((BinarySearchTreeNode*)(n.GetRight())),this));
}
TMVA::BinarySearchTreeNode::~BinarySearchTreeNode()
{
}
Bool_t TMVA::BinarySearchTreeNode::GoesRight( const TMVA::Event& e ) const
{
if (e.GetValue(fSelector) > GetEventV()[fSelector]) return true;
else return false;
}
Bool_t TMVA::BinarySearchTreeNode::GoesLeft(const TMVA::Event& e) const
{
if (e.GetValue(fSelector) <= GetEventV()[fSelector]) return true;
else return false;
}
Bool_t TMVA::BinarySearchTreeNode::EqualsMe(const TMVA::Event& e) const
{
Bool_t result = true;
for (UInt_t i=0; i<GetEventV().size(); i++) {
result&= (e.GetValue(i) == GetEventV()[i]);
}
return result;
}
void TMVA::BinarySearchTreeNode::Print( std::ostream& os ) const
{
os << "< *** " << std::endl << " node.Data: ";
std::vector<Float_t>::const_iterator it=fEventV.begin();
os << fEventV.size() << " vars: ";
for (;it!=fEventV.end(); it++) os << " " << std::setw(10) << *it;
os << " EvtWeight " << std::setw(10) << fWeight;
os << std::setw(10) << "Class: " << GetClass() << std::endl;
os << "Selector: " << this->GetSelector() <<std::endl;
os << "My address is " << long(this) << ", ";
if (this->GetParent() != NULL) os << " parent at addr: " << long(this->GetParent()) ;
if (this->GetLeft() != NULL) os << " left daughter at addr: " << long(this->GetLeft());
if (this->GetRight() != NULL) os << " right daughter at addr: " << long(this->GetRight()) ;
os << " **** > "<< std::endl;
}
void TMVA::BinarySearchTreeNode::PrintRec( std::ostream& os ) const
{
os << this->GetDepth() << " " << this->GetPos() << " " << this->GetSelector()
<< " data: " << std::endl;
std::vector<Float_t>::const_iterator it=fEventV.begin();
os << fEventV.size() << " vars: ";
for (;it!=fEventV.end(); it++) os << " " << std::setw(10) << *it;
os << " EvtWeight " << std::setw(10) << fWeight;
os << std::setw(10) << "Class: " << GetClass() << std::endl;
if (this->GetLeft() != NULL)this->GetLeft()->PrintRec(os) ;
if (this->GetRight() != NULL)this->GetRight()->PrintRec(os);
}
Bool_t TMVA::BinarySearchTreeNode::ReadDataRecord( std::istream& is, UInt_t )
{
Int_t itmp;
std::string tmp;
UInt_t depth, selIdx, nvar;
Char_t pos;
TString sigbkgd;
Float_t evtValFloat;
is >> itmp;
if ( itmp==-1 ) { return kFALSE; }
depth=(UInt_t)itmp;
is >> pos >> selIdx;
this->SetDepth(depth);
this->SetPos(pos);
this->SetSelector(selIdx);
is >> nvar;
fEventV.clear();
for (UInt_t ivar=0; ivar<nvar; ivar++) {
is >> evtValFloat; fEventV.push_back(evtValFloat);
}
is >> tmp >> fWeight;
is >> sigbkgd;
fClass = (sigbkgd=="S" || sigbkgd=="Signal")?0:1;
return kTRUE;
}
void TMVA::BinarySearchTreeNode::ReadAttributes(void* node, UInt_t )
{
gTools().ReadAttr(node, "selector", fSelector );
gTools().ReadAttr(node, "weight", fWeight );
std::string sb;
gTools().ReadAttr(node, "type", sb);
if (sb=="Signal" || sb=="0")
fClass=0;
if (sb=="1")
fClass=1;
Int_t nvars;
gTools().ReadAttr(node, "NVars",nvars);
fEventV.resize(nvars);
}
void TMVA::BinarySearchTreeNode::AddAttributesToNode(void* node) const {
gTools().AddAttr(node, "selector", fSelector );
gTools().AddAttr(node, "weight", fWeight );
gTools().AddAttr(node, "type", GetClass());
gTools().AddAttr(node, "NVars", fEventV.size());
}
void TMVA::BinarySearchTreeNode::AddContentToNode( std::stringstream& s ) const
{
std::ios_base::fmtflags ff = s.flags();
s.precision( 16 );
for (UInt_t i=0; i<fEventV.size(); i++) s << std::scientific << " " << fEventV[i];
for (UInt_t i=0; i<fTargets.size(); i++) s << std::scientific << " " << fTargets[i];
s.flags(ff);
}
void TMVA::BinarySearchTreeNode::ReadContent( std::stringstream& s )
{
Float_t temp=0;
for (UInt_t i=0; i<fEventV.size(); i++){
s >> temp;
fEventV[i]=temp;
}
while (s >> temp) fTargets.push_back(temp);
}
BinarySearchTreeNode.cxx:1 BinarySearchTreeNode.cxx:2 BinarySearchTreeNode.cxx:3 BinarySearchTreeNode.cxx:4 BinarySearchTreeNode.cxx:5 BinarySearchTreeNode.cxx:6 BinarySearchTreeNode.cxx:7 BinarySearchTreeNode.cxx:8 BinarySearchTreeNode.cxx:9 BinarySearchTreeNode.cxx:10 BinarySearchTreeNode.cxx:11 BinarySearchTreeNode.cxx:12 BinarySearchTreeNode.cxx:13 BinarySearchTreeNode.cxx:14 BinarySearchTreeNode.cxx:15 BinarySearchTreeNode.cxx:16 BinarySearchTreeNode.cxx:17 BinarySearchTreeNode.cxx:18 BinarySearchTreeNode.cxx:19 BinarySearchTreeNode.cxx:20 BinarySearchTreeNode.cxx:21 BinarySearchTreeNode.cxx:22 BinarySearchTreeNode.cxx:23 BinarySearchTreeNode.cxx:24 BinarySearchTreeNode.cxx:25 BinarySearchTreeNode.cxx:26 BinarySearchTreeNode.cxx:27 BinarySearchTreeNode.cxx:28 BinarySearchTreeNode.cxx:29 BinarySearchTreeNode.cxx:30 BinarySearchTreeNode.cxx:31 BinarySearchTreeNode.cxx:32 BinarySearchTreeNode.cxx:33 BinarySearchTreeNode.cxx:34 BinarySearchTreeNode.cxx:35 BinarySearchTreeNode.cxx:36 BinarySearchTreeNode.cxx:37 BinarySearchTreeNode.cxx:38 BinarySearchTreeNode.cxx:39 BinarySearchTreeNode.cxx:40 BinarySearchTreeNode.cxx:41 BinarySearchTreeNode.cxx:42 BinarySearchTreeNode.cxx:43 BinarySearchTreeNode.cxx:44 BinarySearchTreeNode.cxx:45 BinarySearchTreeNode.cxx:46 BinarySearchTreeNode.cxx:47 BinarySearchTreeNode.cxx:48 BinarySearchTreeNode.cxx:49 BinarySearchTreeNode.cxx:50 BinarySearchTreeNode.cxx:51 BinarySearchTreeNode.cxx:52 BinarySearchTreeNode.cxx:53 BinarySearchTreeNode.cxx:54 BinarySearchTreeNode.cxx:55 BinarySearchTreeNode.cxx:56 BinarySearchTreeNode.cxx:57 BinarySearchTreeNode.cxx:58 BinarySearchTreeNode.cxx:59 BinarySearchTreeNode.cxx:60 BinarySearchTreeNode.cxx:61 BinarySearchTreeNode.cxx:62 BinarySearchTreeNode.cxx:63 BinarySearchTreeNode.cxx:64 BinarySearchTreeNode.cxx:65 BinarySearchTreeNode.cxx:66 BinarySearchTreeNode.cxx:67 BinarySearchTreeNode.cxx:68 BinarySearchTreeNode.cxx:69 BinarySearchTreeNode.cxx:70 BinarySearchTreeNode.cxx:71 BinarySearchTreeNode.cxx:72 BinarySearchTreeNode.cxx:73 BinarySearchTreeNode.cxx:74 BinarySearchTreeNode.cxx:75 BinarySearchTreeNode.cxx:76 BinarySearchTreeNode.cxx:77 BinarySearchTreeNode.cxx:78 BinarySearchTreeNode.cxx:79 BinarySearchTreeNode.cxx:80 BinarySearchTreeNode.cxx:81 BinarySearchTreeNode.cxx:82 BinarySearchTreeNode.cxx:83 BinarySearchTreeNode.cxx:84 BinarySearchTreeNode.cxx:85 BinarySearchTreeNode.cxx:86 BinarySearchTreeNode.cxx:87 BinarySearchTreeNode.cxx:88 BinarySearchTreeNode.cxx:89 BinarySearchTreeNode.cxx:90 BinarySearchTreeNode.cxx:91 BinarySearchTreeNode.cxx:92 BinarySearchTreeNode.cxx:93 BinarySearchTreeNode.cxx:94 BinarySearchTreeNode.cxx:95 BinarySearchTreeNode.cxx:96 BinarySearchTreeNode.cxx:97 BinarySearchTreeNode.cxx:98 BinarySearchTreeNode.cxx:99 BinarySearchTreeNode.cxx:100 BinarySearchTreeNode.cxx:101 BinarySearchTreeNode.cxx:102 BinarySearchTreeNode.cxx:103 BinarySearchTreeNode.cxx:104 BinarySearchTreeNode.cxx:105 BinarySearchTreeNode.cxx:106 BinarySearchTreeNode.cxx:107 BinarySearchTreeNode.cxx:108 BinarySearchTreeNode.cxx:109 BinarySearchTreeNode.cxx:110 BinarySearchTreeNode.cxx:111 BinarySearchTreeNode.cxx:112 BinarySearchTreeNode.cxx:113 BinarySearchTreeNode.cxx:114 BinarySearchTreeNode.cxx:115 BinarySearchTreeNode.cxx:116 BinarySearchTreeNode.cxx:117 BinarySearchTreeNode.cxx:118 BinarySearchTreeNode.cxx:119 BinarySearchTreeNode.cxx:120 BinarySearchTreeNode.cxx:121 BinarySearchTreeNode.cxx:122 BinarySearchTreeNode.cxx:123 BinarySearchTreeNode.cxx:124 BinarySearchTreeNode.cxx:125 BinarySearchTreeNode.cxx:126 BinarySearchTreeNode.cxx:127 BinarySearchTreeNode.cxx:128 BinarySearchTreeNode.cxx:129 BinarySearchTreeNode.cxx:130 BinarySearchTreeNode.cxx:131 BinarySearchTreeNode.cxx:132 BinarySearchTreeNode.cxx:133 BinarySearchTreeNode.cxx:134 BinarySearchTreeNode.cxx:135 BinarySearchTreeNode.cxx:136 BinarySearchTreeNode.cxx:137 BinarySearchTreeNode.cxx:138 BinarySearchTreeNode.cxx:139 BinarySearchTreeNode.cxx:140 BinarySearchTreeNode.cxx:141 BinarySearchTreeNode.cxx:142 BinarySearchTreeNode.cxx:143 BinarySearchTreeNode.cxx:144 BinarySearchTreeNode.cxx:145 BinarySearchTreeNode.cxx:146 BinarySearchTreeNode.cxx:147 BinarySearchTreeNode.cxx:148 BinarySearchTreeNode.cxx:149 BinarySearchTreeNode.cxx:150 BinarySearchTreeNode.cxx:151 BinarySearchTreeNode.cxx:152 BinarySearchTreeNode.cxx:153 BinarySearchTreeNode.cxx:154 BinarySearchTreeNode.cxx:155 BinarySearchTreeNode.cxx:156 BinarySearchTreeNode.cxx:157 BinarySearchTreeNode.cxx:158 BinarySearchTreeNode.cxx:159 BinarySearchTreeNode.cxx:160 BinarySearchTreeNode.cxx:161 BinarySearchTreeNode.cxx:162 BinarySearchTreeNode.cxx:163 BinarySearchTreeNode.cxx:164 BinarySearchTreeNode.cxx:165 BinarySearchTreeNode.cxx:166 BinarySearchTreeNode.cxx:167 BinarySearchTreeNode.cxx:168 BinarySearchTreeNode.cxx:169 BinarySearchTreeNode.cxx:170 BinarySearchTreeNode.cxx:171 BinarySearchTreeNode.cxx:172 BinarySearchTreeNode.cxx:173 BinarySearchTreeNode.cxx:174 BinarySearchTreeNode.cxx:175 BinarySearchTreeNode.cxx:176 BinarySearchTreeNode.cxx:177 BinarySearchTreeNode.cxx:178 BinarySearchTreeNode.cxx:179 BinarySearchTreeNode.cxx:180 BinarySearchTreeNode.cxx:181 BinarySearchTreeNode.cxx:182 BinarySearchTreeNode.cxx:183 BinarySearchTreeNode.cxx:184 BinarySearchTreeNode.cxx:185 BinarySearchTreeNode.cxx:186 BinarySearchTreeNode.cxx:187 BinarySearchTreeNode.cxx:188 BinarySearchTreeNode.cxx:189 BinarySearchTreeNode.cxx:190 BinarySearchTreeNode.cxx:191 BinarySearchTreeNode.cxx:192 BinarySearchTreeNode.cxx:193 BinarySearchTreeNode.cxx:194 BinarySearchTreeNode.cxx:195 BinarySearchTreeNode.cxx:196 BinarySearchTreeNode.cxx:197 BinarySearchTreeNode.cxx:198 BinarySearchTreeNode.cxx:199 BinarySearchTreeNode.cxx:200 BinarySearchTreeNode.cxx:201 BinarySearchTreeNode.cxx:202 BinarySearchTreeNode.cxx:203 BinarySearchTreeNode.cxx:204 BinarySearchTreeNode.cxx:205 BinarySearchTreeNode.cxx:206 BinarySearchTreeNode.cxx:207 BinarySearchTreeNode.cxx:208 BinarySearchTreeNode.cxx:209 BinarySearchTreeNode.cxx:210 BinarySearchTreeNode.cxx:211 BinarySearchTreeNode.cxx:212 BinarySearchTreeNode.cxx:213 BinarySearchTreeNode.cxx:214 BinarySearchTreeNode.cxx:215 BinarySearchTreeNode.cxx:216 BinarySearchTreeNode.cxx:217 BinarySearchTreeNode.cxx:218 BinarySearchTreeNode.cxx:219 BinarySearchTreeNode.cxx:220 BinarySearchTreeNode.cxx:221 BinarySearchTreeNode.cxx:222 BinarySearchTreeNode.cxx:223 BinarySearchTreeNode.cxx:224 BinarySearchTreeNode.cxx:225 BinarySearchTreeNode.cxx:226 BinarySearchTreeNode.cxx:227 BinarySearchTreeNode.cxx:228 BinarySearchTreeNode.cxx:229 BinarySearchTreeNode.cxx:230 BinarySearchTreeNode.cxx:231 BinarySearchTreeNode.cxx:232 BinarySearchTreeNode.cxx:233 BinarySearchTreeNode.cxx:234 BinarySearchTreeNode.cxx:235 BinarySearchTreeNode.cxx:236 BinarySearchTreeNode.cxx:237 BinarySearchTreeNode.cxx:238 BinarySearchTreeNode.cxx:239 BinarySearchTreeNode.cxx:240 BinarySearchTreeNode.cxx:241 BinarySearchTreeNode.cxx:242 BinarySearchTreeNode.cxx:243 BinarySearchTreeNode.cxx:244 BinarySearchTreeNode.cxx:245 BinarySearchTreeNode.cxx:246 BinarySearchTreeNode.cxx:247 BinarySearchTreeNode.cxx:248 BinarySearchTreeNode.cxx:249 BinarySearchTreeNode.cxx:250 BinarySearchTreeNode.cxx:251 BinarySearchTreeNode.cxx:252 BinarySearchTreeNode.cxx:253 BinarySearchTreeNode.cxx:254 BinarySearchTreeNode.cxx:255 BinarySearchTreeNode.cxx:256 BinarySearchTreeNode.cxx:257 BinarySearchTreeNode.cxx:258