94 auto mapFunc = [&evs](
UInt_t i) {
return evs[i].weight; };
95 auto redFunc = [](
const std::vector<Double_t> &
a) {
return std::accumulate(
a.begin(),
a.end(), 0.0); };
107 for(
UInt_t i = 0; i<evs.size(); i++)
108 sumOfWeights+=evs[i].weight;
124 return TMath::Abs(a.trueValue-a.predictedValue) < TMath::Abs(b.trueValue-b.predictedValue); });
127 return (a.trueValue-a.predictedValue) < (b.trueValue-b.predictedValue); });
130 while(i<evs.size()-1 && temp <= sumOfWeights*whichQuantile){
131 temp += evs[i].weight;
136 if(whichQuantile == 0) i=0;
139 if(abs)
return TMath::Abs(evs[i].trueValue-evs[i].predictedValue);
140 else return evs[i].trueValue-evs[i].predictedValue;
154 for(
UInt_t i=0; i<evs.size(); i++){
185 std::vector<LossFunctionEventInfo> evs{
e};
196 return e.weight*loss;
210 for(
UInt_t i=0; i<evs.size(); i++)
228 for(
UInt_t i=0; i<evs.size(); i++)
249 std::vector<LossFunctionEventInfo> evinfovec(evinfomap.size());
250 for (
auto &
e: evinfomap){
259 boostWeights.push_back(weightedMedian);
260 for (
auto &
e: evinfomap ) {
262 e.second.predictedValue += weightedMedian;
273 std::vector<LossFunctionEventInfo> eventvec(evs.size());
278 auto fcopy = [&eventvec, &evs, &evinfomap](
UInt_t i) {
279 eventvec[i] =
LossFunctionEventInfo(evinfomap[evs[i]].trueValue, evinfomap[evs[i]].predictedValue, evs[i]->GetWeight());
303 std::vector<LossFunctionEventInfo> eventvec(evs.size());
304 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++){
305 eventvec.push_back(
LossFunctionEventInfo(evinfomap[*
e].trueValue, evinfomap[*
e].predictedValue, (*e)->GetWeight()));
311 SetSumOfWeights(eventvec);
312 SetTransitionPoint(eventvec);
314 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++) {
324 Double_t residual =
e.trueValue -
e.predictedValue;
343 for(
UInt_t j=0;j<evs.size();j++){
344 Double_t residual = evs[j].trueValue - evs[j].predictedValue;
345 diff = residual-residualMedian;
352 return (residualMedian + shift);
369 Double_t residual = (
e.trueValue -
e.predictedValue);
371 loss = residual*residual;
372 return e.weight*loss;
380 for(
UInt_t i=0; i<evs.size(); i++)
393 for(
UInt_t i=0; i<evs.size(); i++){
394 sumOfWeights+=evs[i].weight;
398 return netloss/sumOfWeights;
416 std::vector<LossFunctionEventInfo> evinfovec(evinfomap.size());
417 for (
auto &
e: evinfomap){
425 boostWeights.push_back(weightedMean);
426 for (
auto &
e: evinfomap ) {
428 e.second.predictedValue += weightedMean;
450 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++) {
460 Double_t residual =
e.trueValue -
e.predictedValue;
474 for(
UInt_t j=0;j<evs.size();j++){
475 sumOfWeights += evs[j].weight;
476 Double_t residual = evs[j].trueValue - evs[j].predictedValue;
477 weightedResidualSum += evs[j].weight*residual;
479 Double_t weightedMean = weightedResidualSum/sumOfWeights;
498 Double_t residual =
e.trueValue -
e.predictedValue;
508 for(
UInt_t i=0; i<evs.size(); i++)
519 for(
UInt_t i=0; i<evs.size(); i++){
520 sumOfWeights+=evs[i].weight;
523 return netloss/sumOfWeights;
539 std::vector<LossFunctionEventInfo> evinfovec(evinfomap.size());
540 for (
auto &
e: evinfomap){
547 boostWeights.push_back(weightedMedian);
548 for (
auto &
e: evinfomap ) {
550 e.second.predictedValue += weightedMedian;
571 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++) {
582 Double_t residual =
e.trueValue -
e.predictedValue;
584 return (residual<0?-1.0:1.0);
597 return (a.trueValue-a.predictedValue) < (b.trueValue-b.predictedValue); });
601 for(
UInt_t j=0; j<evs.size(); j++)
602 sumOfWeights+=evs[j].weight;
607 while(i<evs.size() && temp <= sumOfWeights*0.5){
608 temp += evs[i].weight;
611 if (i >= evs.size())
return 0.;
614 return evs[i].trueValue-evs[i].predictedValue;
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
double Double_t
Double 8 bytes.
void SetTargets(std::vector< const TMVA::Event * > &evs, std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap) override
absolute deviation BDT, set the targets for a collection of events
void Init(std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap, std::vector< double > &boostWeights) override
absolute deviation BDT, initialize the targets and prepare for the regression
Double_t Fit(std::vector< LossFunctionEventInfo > &evs) override
absolute deviation BDT, determine the fit value for the terminal node based upon the events in the te...
Double_t Target(LossFunctionEventInfo &e) override
absolute deviation BDT, set the target for a single event
Double_t CalculateLoss(LossFunctionEventInfo &e) override
absolute deviation, determine the loss for a single event
Double_t CalculateNetLoss(std::vector< LossFunctionEventInfo > &evs) override
absolute deviation, determine the net loss for a collection of events
Double_t CalculateMeanLoss(std::vector< LossFunctionEventInfo > &evs) override
absolute deviation, determine the mean loss for a collection of events
Executor & GetThreadExecutor()
Get executor class for multi-thread usage In case when MT is not enabled will return a serial executo...
static Config & Instance()
static function: returns TMVA instance
void SetTarget(UInt_t itgt, Float_t value)
set the target value (dimension itgt) to value
void Foreach(Function func, unsigned int nTimes, unsigned nChunks=0)
wrap TExecutor::Foreach
auto MapReduce(F func, ROOT::TSeq< INTEGER > args, R redfunc) -> InvokeResult_t< F, INTEGER >
Wrap TExecutor::MapReduce functions.
Double_t Target(LossFunctionEventInfo &e) override
huber BDT, set the target for a single event
void Init(std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap, std::vector< double > &boostWeights) override
huber BDT, initialize the targets and prepare for the regression
void SetTargets(std::vector< const TMVA::Event * > &evs, std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap) override
huber BDT, set the targets for a collection of events
Double_t Fit(std::vector< LossFunctionEventInfo > &evs) override
huber BDT, determine the fit value for the terminal node based upon the events in the terminal node
HuberLossFunction()
huber constructor
Double_t CalculateLoss(LossFunctionEventInfo &e) override
huber, determine the loss for a single event
void SetSumOfWeights(std::vector< LossFunctionEventInfo > &evs)
huber, set the sum of weights given a collection of events
void SetTransitionPoint(std::vector< LossFunctionEventInfo > &evs)
huber, determine the transition point using the values for fQuantile and fSumOfWeights which presumab...
Double_t CalculateMeanLoss(std::vector< LossFunctionEventInfo > &evs) override
huber, determine the mean loss for a collection of events
Double_t CalculateNetLoss(std::vector< LossFunctionEventInfo > &evs) override
huber, determine the net loss for a collection of events
~HuberLossFunction()
huber destructor
Double_t fTransitionPoint
Double_t CalculateSumOfWeights(const std::vector< LossFunctionEventInfo > &evs)
huber, calculate the sum of weights for the events in the vector
void Init(std::vector< LossFunctionEventInfo > &evs)
figure out the residual that determines the separation between the "core" and the "tails" of the resi...
Double_t CalculateQuantile(std::vector< LossFunctionEventInfo > &evs, Double_t whichQuantile, Double_t sumOfWeights, bool abs)
huber, determine the quantile for a given input
void Init(std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap, std::vector< double > &boostWeights) override
least squares BDT, initialize the targets and prepare for the regression
void SetTargets(std::vector< const TMVA::Event * > &evs, std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap) override
least squares BDT, set the targets for a collection of events
Double_t Target(LossFunctionEventInfo &e) override
least squares BDT, set the target for a single event
Double_t Fit(std::vector< LossFunctionEventInfo > &evs) override
huber BDT, determine the fit value for the terminal node based upon the events in the terminal node
Double_t CalculateMeanLoss(std::vector< LossFunctionEventInfo > &evs) override
least squares , determine the mean loss for a collection of events
Double_t CalculateLoss(LossFunctionEventInfo &e) override
least squares , determine the loss for a single event
Double_t CalculateNetLoss(std::vector< LossFunctionEventInfo > &evs) override
least squares , determine the net loss for a collection of events
TSeq< unsigned int > TSeqU
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.