58 fSumOfWeights = -9999;
59 fTransitionPoint = -9999;
78 SetTransitionPoint(evs);
88 for(
UInt_t i = 0; i<evs.size(); i++)
89 sumOfWeights+=evs[i].weight;
110 while(i<evs.size()-1 && temp <= sumOfWeights*whichQuantile){
111 temp += evs[i].weight;
116 if(whichQuantile == 0) i=0;
119 if(abs)
return TMath::Abs(evs[i].trueValue-evs[i].predictedValue);
120 else return evs[i].trueValue-evs[i].predictedValue;
128 fTransitionPoint = CalculateQuantile(evs, fQuantile, fSumOfWeights,
true);
132 if(fTransitionPoint == 0){
134 for(
UInt_t i=0; i<evs.size(); i++){
137 fTransitionPoint = residual;
144 if(fTransitionPoint == 0){
155 fSumOfWeights = CalculateSumOfWeights(evs);
164 if(fSumOfWeights == -9999){
165 std::vector<LossFunctionEventInfo> evs;
168 SetSumOfWeights(evs);
169 SetTransitionPoint(evs);
175 if(residual <= fTransitionPoint) loss = 0.5*residual*residual;
177 else loss = fQuantile*residual - 0.5*fQuantile*fQuantile;
188 SetSumOfWeights(evs);
189 SetTransitionPoint(evs);
192 for(
UInt_t i=0; i<evs.size(); i++)
193 netloss+=CalculateLoss(evs[i]);
206 SetSumOfWeights(evs);
207 SetTransitionPoint(evs);
210 for(
UInt_t i=0; i<evs.size(); i++)
211 netloss+=CalculateLoss(evs[i]);
212 return netloss/fSumOfWeights;
230 std::vector<LossFunctionEventInfo> evinfovec;
231 for (
auto &
e: evinfomap){
236 SetSumOfWeights(evinfovec);
237 Double_t weightedMedian = CalculateQuantile(evinfovec, 0.5, fSumOfWeights,
false);
240 boostWeights.push_back(weightedMedian);
241 for (
auto &
e: evinfomap ) {
243 e.second.predictedValue += weightedMedian;
252 std::vector<LossFunctionEventInfo> eventvec;
253 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++){
254 eventvec.push_back(
LossFunctionEventInfo(evinfomap[*
e].trueValue, evinfomap[*
e].predictedValue, (*e)->GetWeight()));
260 SetSumOfWeights(eventvec);
261 SetTransitionPoint(eventvec);
263 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++) {
274 if(
TMath::Abs(residual) <= fTransitionPoint)
return residual;
275 else return fTransitionPoint*(residual<0?-1.0:1.0);
288 Double_t sumOfWeights = CalculateSumOfWeights(evs);
290 Double_t residualMedian = CalculateQuantile(evs,0.5,sumOfWeights,
false);
291 for(
UInt_t j=0;j<evs.size();j++){
292 Double_t residual = evs[j].trueValue - evs[j].predictedValue;
293 diff = residual-residualMedian;
295 shift+=1.0/evs.size()*((diff<0)?-1.0:1.0)*
TMath::Min(fTransitionPoint,
fabs(diff));
300 return (residualMedian + shift);
318 loss = residual*residual;
327 for(
UInt_t i=0; i<evs.size(); i++)
328 netloss+=CalculateLoss(evs[i]);
340 for(
UInt_t i=0; i<evs.size(); i++){
341 sumOfWeights+=evs[i].weight;
342 netloss+=CalculateLoss(evs[i]);
345 return netloss/sumOfWeights;
362 std::vector<LossFunctionEventInfo> evinfovec;
363 for (
auto &
e: evinfomap){
371 boostWeights.push_back(weightedMean);
372 for (
auto &
e: evinfomap ) {
374 e.second.predictedValue += weightedMean;
383 std::vector<LossFunctionEventInfo> eventvec;
384 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++){
385 eventvec.push_back(
LossFunctionEventInfo(evinfomap[*
e].trueValue, evinfomap[*
e].predictedValue, (*e)->GetWeight()));
388 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++) {
411 for(
UInt_t j=0;j<evs.size();j++){
412 sumOfWeights += evs[j].weight;
413 Double_t residual = evs[j].trueValue - evs[j].predictedValue;
414 weightedResidualSum += evs[j].weight*residual;
416 Double_t weightedMean = weightedResidualSum/sumOfWeights;
444 for(
UInt_t i=0; i<evs.size(); i++)
445 netloss+=CalculateLoss(evs[i]);
455 for(
UInt_t i=0; i<evs.size(); i++){
456 sumOfWeights+=evs[i].weight;
457 netloss+=CalculateLoss(evs[i]);
459 return netloss/sumOfWeights;
474 std::vector<LossFunctionEventInfo> evinfovec;
475 for (
auto &
e: evinfomap){
482 boostWeights.push_back(weightedMedian);
483 for (
auto &
e: evinfomap ) {
485 e.second.predictedValue += weightedMedian;
494 std::vector<LossFunctionEventInfo> eventvec;
495 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++){
496 eventvec.push_back(
LossFunctionEventInfo(evinfomap[*
e].trueValue, evinfomap[*
e].predictedValue, (*e)->GetWeight()));
499 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++) {
511 return (residual<0?-1.0:1.0);
528 for(
UInt_t j=0; j<evs.size(); j++)
529 sumOfWeights+=evs[j].weight;
534 while(i<evs.size() && temp <= sumOfWeights*0.5){
535 temp += evs[i].weight;
538 if (i >= evs.size())
return 0.;
541 return evs[i].trueValue-evs[i].predictedValue;
Double_t CalculateMeanLoss(std::vector< LossFunctionEventInfo > &evs)
absolute deviation, determine the mean loss for a collection of events
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
Double_t CalculateLoss(LossFunctionEventInfo &e)
absolute deviation, determine the loss for a single event
void Init(std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap, std::vector< double > &boostWeights)
absolute deviation BDT, initialize the targets and prepare for the regression
Short_t Min(Short_t a, Short_t b)
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
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)
least squares BDT, set the targets for a collection of events
Double_t CalculateLoss(LossFunctionEventInfo &e)
least squares , determine the loss for a single event
Double_t Target(LossFunctionEventInfo &e)
absolute deviation BDT, set the target for a single event
Double_t Target(LossFunctionEventInfo &e)
huber BDT, set the target for a single event
void Init(std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap, std::vector< double > &boostWeights)
huber BDT, initialize the targets and prepare for the regression
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
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 ...
Double_t CalculateSumOfWeights(std::vector< LossFunctionEventInfo > &evs)
huber, determine the quantile for a given input
HuberLossFunction()
huber constructor
Double_t CalculateNetLoss(std::vector< LossFunctionEventInfo > &evs)
least squares , determine the net loss for a collection of events
Double_t CalculateQuantile(std::vector< LossFunctionEventInfo > &evs, Double_t whichQuantile, Double_t sumOfWeights, bool abs)
huber, determine the quantile for a given input
void SetTarget(UInt_t itgt, Float_t value)
set the target value (dimension itgt) to value
void Init(std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap, std::vector< double > &boostWeights)
least squares BDT, initialize the targets and prepare for the regression
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
void Init(std::vector< LossFunctionEventInfo > &evs)
figure out the residual that determines the separation between the "core" and the "tails" of the resi...
void SetTransitionPoint(std::vector< LossFunctionEventInfo > &evs)
huber, determine the transition point using the values for fQuantile and fSumOfWeights which presumab...
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Double_t CalculateNetLoss(std::vector< LossFunctionEventInfo > &evs)
huber, determine the net loss for a collection of events
~HuberLossFunction()
huber destructor
Double_t CalculateMeanLoss(std::vector< LossFunctionEventInfo > &evs)
huber, determine the mean loss for a collection of events
Double_t fTransitionPoint
void SetSumOfWeights(std::vector< LossFunctionEventInfo > &evs)
huber, set the sum of weights given a collection of events
Double_t CalculateMeanLoss(std::vector< LossFunctionEventInfo > &evs)
least squares , determine the mean loss for a collection of events
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 ...
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Double_t CalculateLoss(LossFunctionEventInfo &e)
huber, determine the loss for a single event
Double_t CalculateNetLoss(std::vector< LossFunctionEventInfo > &evs)
absolute deviation, determine the net loss for a collection of events
Double_t Target(LossFunctionEventInfo &e)
least squares BDT, set the target for a single event