22 #include "TStopwatch.h"
36 events = std::vector< std::vector<Event*> >(1);
59 for(
unsigned int i=0;
i <
trees.size();
i++)
72 Event*
e = trainingEvents[0];
77 events = std::vector< std::vector<Event*> >();
79 for(
unsigned int i=0;
i<e->
data.size();
i++)
81 events.push_back(trainingEvents);
132 std::cout << std::endl <<
"Listing Events... " << std::endl;
134 for(
unsigned int i=0;
i <
e.size();
i++)
136 std::cout << std::endl <<
"Variable " <<
i <<
" vector contents: " << std::endl;
137 for(
unsigned int j=0;
j<
e[
i].size();
j++)
139 e[
i][
j]->outputEvent();
165 return e1->
id < e2->
id;
176 for(
unsigned int i=0;
i<
e.size();
i++)
199 std::vector<double>
v(
events.size(), 0);
203 for(
unsigned int j=0;
j <
trees.size();
j++)
208 double max = *std::max_element(
v.begin(),
v.end());
211 for(
unsigned int i=0;
i <
v.size();
i++)
218 std::vector< std::pair<double, Int_t> >
w(
events.size());
220 for(
unsigned int i=0;
i<
v.size();
i++)
222 w[
i] = std::pair<double, Int_t>(
v[
i],
i);
226 std::sort(
w.begin(),
w.end());
229 for(
int i=(
v.size()-1);
i>=0;
i--)
246 std::ofstream splitvaluefile;
247 splitvaluefile.open(savefilename);
251 std::vector<std::vector<double>>
v(
events.size(), std::vector<double>());
256 for(
unsigned int j=0;
j<
trees.size();
j++)
258 trees[
j]->getSplitValues(v);
262 for(
unsigned int i=0;
i<v.size();
i++)
270 for(
unsigned int i=1;
i<v.size();
i++)
273 for(
unsigned int j=0;
j<v[
i].size();
j++)
275 std::stringstream
ss;
277 ss << std::scientific << v[
i][
j];
279 splitValues+=ss.str().c_str();
282 splitValues=splitValues(1,splitValues.Length());
283 splitvaluefile << splitValues << std::endl << std::endl;;
300 for(std::list<Node*>::iterator it=tn.begin(); it!=tn.end(); it++)
303 std::vector<Event*>&
v = (*it)->getEvents()[0];
306 double fit = l->
fit(v);
309 fit = learningRate*fit;
312 (*it)->setFitValue(fit);
316 for(
unsigned int j=0;
j<v.size();
j++)
324 (*it)->getEvents() = std::vector< std::vector<Event*> >();
340 for(std::list<Node*>::iterator it=tn.begin(); it!=tn.end(); it++)
342 std::vector<Event*>&
v = (*it)->getEvents()[0];
343 double fit = (*it)->getFitValue();
347 for(
unsigned int j=0;
j<v.size();
j++)
354 (*it)->getEvents() = std::vector< std::vector<Event*> >();
381 for(
unsigned int i=0;
i< (unsigned) treeLimit;
i++)
385 trees.push_back(tree);
392 std::ostringstream
ss;
393 ss << savetreesdirectory <<
"/" <<
i <<
".xml";
395 const char*
c = s.c_str();
414 if(numtrees >
trees.size())
417 numtrees =
trees.size();
421 for(
unsigned int i=0;
i < numtrees;
i++)
452 if(numtrees >
trees.size())
455 numtrees =
trees.size();
459 for(
unsigned int i=0;
i < numtrees;
i++)
490 trees = std::vector<Tree*>(numTrees);
494 for(
unsigned int i=0;
i < numTrees;
i++)
498 std::stringstream
ss;
499 ss << directory <<
"/" <<
i <<
".xml";
520 size_t subSampleSize = fraction*
events[0].size();
552 trees = std::vector<Tree*>(treeLimit);
566 for(
unsigned int i=0;
i< (unsigned) treeLimit;
i++)
571 trees[
i]->buildTree(nodeLimit);
581 std::ostringstream
ss;
582 ss <<
"trees/" << i <<
".xml";
584 const char*
c = s.c_str();
Node * filterEvent(Event *e)
void doRegression(Int_t nodeLimit, Int_t treeLimit, double learningRate, LossFunction *l, const char *savetreesdirectory, bool saveTrees)
std::vector< std::vector< Event * > > events
virtual Double_t fit(std::vector< Event * > &v)=0
void saveSplitValues(const char *savefilename)
virtual Double_t target(Event *e)=0
void predictEvents(std::vector< Event * > &eventsp, unsigned int trees)
void predictEvent(Event *e, unsigned int trees)
Tree * getTree(unsigned int i)
void doStochasticRegression(Int_t nodeLimit, Int_t treeLimit, double learningRate, double fraction, LossFunction *l)
bidiiter shuffle(bidiiter begin, bidiiter end, size_t num_random)
void buildTree(Int_t nodeLimit)
U second(std::pair< T, U > const &p)
static Int_t sortingIndex
void loadForestFromXML(const char *directory, unsigned int numTrees)
void updateEvents(Tree *tree)
void sortEventVectors(std::vector< std::vector< Event * > > &e)
bool compareEvents(Event *e1, Event *e2)
void updateRegTargets(Tree *tree, double learningRate, LossFunction *l)
std::vector< Tree * > trees
std::vector< std::vector< Event * > > subSample
std::list< Node * > & getTerminalNodes()
void filterEvents(std::vector< Event * > &tEvents)
void listEvents(std::vector< std::vector< Event * > > &e)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void appendCorrection(std::vector< Event * > &eventsp, Int_t treenum)
void rankVariables(std::vector< int > &rank)
void setTrainingEvents(std::vector< Event * > &trainingEvents)
void saveToXML(const char *filename)
std::vector< Event * > getTrainingEvents()
bool compareEventsById(Event *e1, Event *e2)
std::vector< Double_t > data
void prepareRandomSubsample(double fraction)