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*> >();
81 for(
unsigned int i=0;
i<e->
data.size();
i++)
83 events.push_back(trainingEvents);
134 std::cout << std::endl <<
"Listing Events... " << std::endl;
136 for(
unsigned int i=0;
i <
e.size();
i++)
138 std::cout << std::endl <<
"Variable " <<
i <<
" vector contents: " << std::endl;
139 for(
unsigned int j=0;
j<
e[
i].size();
j++)
141 e[
i][
j]->outputEvent();
167 return e1->
id < e2->
id;
178 for(
unsigned int i=0;
i<
e.size();
i++)
201 std::vector<double>
v(
events.size(), 0);
205 for(
unsigned int j=0;
j <
trees.size();
j++)
210 double max = *std::max_element(
v.begin(),
v.end());
213 for(
unsigned int i=0;
i <
v.size();
i++)
220 std::vector< std::pair<double, Int_t> >
w(
events.size());
222 for(
unsigned int i=0;
i<
v.size();
i++)
224 w[
i] = std::pair<double, Int_t>(
v[
i],
i);
228 std::sort(
w.begin(),
w.end());
231 for(
int i=(
v.size()-1);
i>=0;
i--)
248 std::ofstream splitvaluefile;
249 splitvaluefile.open(savefilename);
253 std::vector<std::vector<double>>
v(
events.size(), std::vector<double>());
258 for(
unsigned int j=0;
j<
trees.size();
j++)
260 trees[
j]->getSplitValues(v);
264 for(
unsigned int i=0;
i<v.size();
i++)
272 for(
unsigned int i=1;
i<v.size();
i++)
275 for(
unsigned int j=0;
j<v[
i].size();
j++)
277 std::stringstream
ss;
279 ss << std::scientific << v[
i][
j];
281 splitValues+=ss.str().c_str();
284 splitValues=splitValues(1,splitValues.Length());
285 splitvaluefile << splitValues << std::endl << std::endl;;
302 for(std::list<Node*>::iterator it=tn.begin(); it!=tn.end(); it++)
305 std::vector<Event*>&
v = (*it)->getEvents()[0];
308 double fit = l->
fit(v);
311 fit = learningRate*fit;
314 (*it)->setFitValue(fit);
318 for(
unsigned int j=0;
j<v.size();
j++)
326 (*it)->getEvents() = std::vector< std::vector<Event*> >();
342 for(std::list<Node*>::iterator it=tn.begin(); it!=tn.end(); it++)
344 std::vector<Event*>&
v = (*it)->getEvents()[0];
345 double fit = (*it)->getFitValue();
349 for(
unsigned int j=0;
j<v.size();
j++)
356 (*it)->getEvents() = std::vector< std::vector<Event*> >();
383 for(
unsigned int i=0;
i< (unsigned) treeLimit;
i++)
387 trees.push_back(tree);
394 std::ostringstream
ss;
395 ss << savetreesdirectory <<
"/" <<
i <<
".xml";
397 const char*
c = s.c_str();
416 if(numtrees >
trees.size())
419 numtrees =
trees.size();
423 for(
unsigned int i=0;
i < numtrees;
i++)
454 if(numtrees >
trees.size())
457 numtrees =
trees.size();
461 for(
unsigned int i=0;
i < numtrees;
i++)
492 trees = std::vector<Tree*>(numTrees);
496 for(
unsigned int i=0;
i < numTrees;
i++)
500 std::stringstream
ss;
501 ss << directory <<
"/" <<
i <<
".xml";
522 size_t subSampleSize = fraction*
events[0].size();
554 trees = std::vector<Tree*>(treeLimit);
567 for(
unsigned int i=0;
i< (unsigned) treeLimit;
i++)
572 trees[
i]->buildTree(nodeLimit);
582 std::ostringstream
ss;
583 ss <<
"trees/" << i <<
".xml";
585 const char*
c = s.c_str();
Node * filterEvent(Event *e)
std::vector< Event * > getTrainingEvents()
void prepareRandomSubsample(double fraction)
void rankVariables(std::vector< int > &rank)
std::vector< Tree * > trees
void doRegression(Int_t nodeLimit, Int_t treeLimit, double learningRate, L1TLossFunction *l, const char *savetreesdirectory, bool saveTrees)
void loadL1TForestFromXML(const char *directory, unsigned int numTrees)
void updateEvents(Tree *tree)
virtual Double_t fit(std::vector< Event * > &v)=0
void doStochasticRegression(Int_t nodeLimit, Int_t treeLimit, double learningRate, double fraction, L1TLossFunction *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 listEvents(std::vector< std::vector< Event * > > &e)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void setTrainingEvents(std::vector< Event * > &trainingEvents)
void appendCorrection(std::vector< Event * > &eventsp, Int_t treenum)
std::vector< std::vector< Event * > > events
void sortEventVectors(std::vector< std::vector< Event * > > &e)
void updateRegTargets(Tree *tree, double learningRate, L1TLossFunction *l)
bool compareEvents(Event *e1, Event *e2)
std::vector< std::vector< Event * > > subSample
Tree * getTree(unsigned int i)
std::list< Node * > & getTerminalNodes()
void predictEvents(std::vector< Event * > &eventsp, unsigned int trees)
void predictEvent(Event *e, unsigned int trees)
void filterEvents(std::vector< Event * > &tEvents)
void saveSplitValues(const char *savefilename)
virtual Double_t target(Event *e)=0
void saveToXML(const char *filename)
bool compareEventsById(Event *e1, Event *e2)
std::vector< Double_t > data