64 fSumOfWeights = -9999;
65 fTransitionPoint = -9999;
84 SetTransitionPoint(evs);
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;
148 fTransitionPoint = CalculateQuantile(evs, fQuantile, fSumOfWeights,
true);
152 if(fTransitionPoint == 0){
154 for(
UInt_t i=0; i<evs.size(); i++){
157 fTransitionPoint = residual;
164 if(fTransitionPoint == 0){
175 fSumOfWeights = CalculateSumOfWeights(evs);
184 if(fSumOfWeights == -9999){
185 std::vector<LossFunctionEventInfo> evs{
e};
186 SetSumOfWeights(evs);
187 SetTransitionPoint(evs);
193 if(residual <= fTransitionPoint) loss = 0.5*residual*residual;
195 else loss = fQuantile*residual - 0.5*fQuantile*fQuantile;
196 return e.weight*loss;
206 SetSumOfWeights(evs);
207 SetTransitionPoint(evs);
210 for(
UInt_t i=0; i<evs.size(); i++)
211 netloss+=CalculateLoss(evs[i]);
224 SetSumOfWeights(evs);
225 SetTransitionPoint(evs);
228 for(
UInt_t i=0; i<evs.size(); i++)
229 netloss+=CalculateLoss(evs[i]);
230 return netloss/fSumOfWeights;
249 std::vector<LossFunctionEventInfo> evinfovec(evinfomap.size());
250 for (
auto &
e: evinfomap){
255 SetSumOfWeights(evinfovec);
256 Double_t weightedMedian = CalculateQuantile(evinfovec, 0.5, fSumOfWeights,
false);
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());
287 SetSumOfWeights(eventvec);
288 SetTransitionPoint(eventvec);
293 const_cast<TMVA::Event*
>(ev)->SetTarget(0, Target(evinfomap[ev]));
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;
326 if(
TMath::Abs(residual) <= fTransitionPoint)
return residual;
327 else return fTransitionPoint*(residual<0?-1.0:1.0);
340 Double_t sumOfWeights = CalculateSumOfWeights(evs);
342 Double_t residualMedian = CalculateQuantile(evs,0.5,sumOfWeights,
false);
343 for(
UInt_t j=0;j<evs.size();j++){
344 Double_t residual = evs[j].trueValue - evs[j].predictedValue;
345 diff = residual-residualMedian;
347 shift+=1.0/evs.size()*((diff<0)?-1.0:1.0)*
TMath::Min(fTransitionPoint,fabs(diff));
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++)
381 netloss+=CalculateLoss(evs[i]);
393 for(
UInt_t i=0; i<evs.size(); i++){
394 sumOfWeights+=evs[i].weight;
395 netloss+=CalculateLoss(evs[i]);
398 return netloss/sumOfWeights;
416 std::vector<LossFunctionEventInfo> evinfovec(evinfomap.size());
417 for (
auto &
e: evinfomap){
422 Double_t weightedMean = Fit(evinfovec);
425 boostWeights.push_back(weightedMean);
426 for (
auto &
e: evinfomap ) {
428 e.second.predictedValue += weightedMean;
441 const_cast<TMVA::Event*
>(ev)->SetTarget(0, Target(evinfomap[ev]));
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++)
509 netloss+=CalculateLoss(evs[i]);
519 for(
UInt_t i=0; i<evs.size(); i++){
520 sumOfWeights+=evs[i].weight;
521 netloss+=CalculateLoss(evs[i]);
523 return netloss/sumOfWeights;
539 std::vector<LossFunctionEventInfo> evinfovec(evinfomap.size());
540 for (
auto &
e: evinfomap){
544 Double_t weightedMedian = Fit(evinfovec);
547 boostWeights.push_back(weightedMedian);
548 for (
auto &
e: evinfomap ) {
550 e.second.predictedValue += weightedMedian;
562 const_cast<TMVA::Event*
>(ev)->SetTarget(0, Target(evinfomap[ev]));
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;
A pseudo container class which is a generator of indices.
Double_t Fit(std::vector< LossFunctionEventInfo > &evs)
absolute deviation BDT, determine the fit value for the terminal node based upon the events in the te...
void SetTargets(std::vector< const TMVA::Event * > &evs, std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap)
absolute deviation BDT, set the targets for a collection of events
void Init(std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap, std::vector< double > &boostWeights)
absolute deviation BDT, initialize the targets and prepare for the regression
Double_t Target(LossFunctionEventInfo &e)
absolute deviation BDT, set the target for a single event
Double_t CalculateNetLoss(std::vector< LossFunctionEventInfo > &evs)
absolute deviation, determine the net loss for a collection of events
Double_t CalculateMeanLoss(std::vector< LossFunctionEventInfo > &evs)
absolute deviation, determine the mean loss for a collection of events
Double_t CalculateLoss(LossFunctionEventInfo &e)
absolute deviation, determine the loss for a single event
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
unsigned int GetPoolSize() const
auto MapReduce(F func, ROOT::TSeq< INTEGER > args, R redfunc) -> typename std::result_of< F(INTEGER)>::type
Wrap TExecutor::MapReduce functions.
Double_t Target(LossFunctionEventInfo &e)
huber BDT, set the target for a single event
Double_t Fit(std::vector< LossFunctionEventInfo > &evs)
huber BDT, determine the fit value for the terminal node based upon the events in the terminal node
void Init(std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap, std::vector< double > &boostWeights)
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)
huber BDT, set the targets for a collection of events
HuberLossFunction()
huber constructor
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 CalculateNetLoss(std::vector< LossFunctionEventInfo > &evs)
huber, determine the net loss for a collection of events
Double_t CalculateLoss(LossFunctionEventInfo &e)
huber, determine the loss for a single event
~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
Double_t CalculateMeanLoss(std::vector< LossFunctionEventInfo > &evs)
huber, determine the mean loss for a collection of events
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 SetTargets(std::vector< const TMVA::Event * > &evs, std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap)
least squares BDT, set the targets for a collection of events
Double_t Target(LossFunctionEventInfo &e)
least squares BDT, set the target for a single event
Double_t Fit(std::vector< LossFunctionEventInfo > &evs)
huber BDT, determine the fit value for the terminal node based upon the events in the terminal node
void Init(std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap, std::vector< double > &boostWeights)
least squares BDT, initialize the targets and prepare for the regression
Double_t CalculateNetLoss(std::vector< LossFunctionEventInfo > &evs)
least squares , determine the net loss for a collection of events
Double_t CalculateMeanLoss(std::vector< LossFunctionEventInfo > &evs)
least squares , determine the mean loss for a collection of events
Double_t CalculateLoss(LossFunctionEventInfo &e)
least squares , determine the loss for a single event
Short_t Min(Short_t a, Short_t b)