Logo ROOT   6.10/09
Reference Guide
LossFunction.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss, Jan Therhaag
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : LossFunction *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header for description) *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
16  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
17  * Jan Therhaag <Jan.Therhaag@cern.ch> - U of Bonn, Germany *
18  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
19  * *
20  * Copyright (c) 2005-2011: *
21  * CERN, Switzerland *
22  * U. of Victoria, Canada *
23  * MPI-K Heidelberg, Germany *
24  * U. of Bonn, Germany *
25  * *
26  * Redistribution and use in source and binary forms, with or without *
27  * modification, are permitted according to the terms listed in LICENSE *
28  * (http://mva.sourceforge.net/license.txt) *
29  **********************************************************************************/
30 
31 /*! \class TMVA::HuberLossFunction
32 \ingroup TMVA
33 
34 Huber Loss Function.
35 
36 */
37 
38 #include "TMVA/LossFunction.h"
39 
40 #include "TMVA/MsgLogger.h"
41 
42 #include "Rtypes.h"
43 #include "TMath.h"
44 
45 #include <iostream>
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// huber constructor
49 
51  fTransitionPoint = -9999;
52  fSumOfWeights = -9999;
53  fQuantile = 0.7; // the quantile value determines the bulk of the data, e.g. 0.7 defines
54  // the core as the first 70% and the tails as the last 30%
55 }
56 
58  fSumOfWeights = -9999;
59  fTransitionPoint = -9999;
60  fQuantile = quantile;
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// huber destructor
65 
67 
68 }
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 /// figure out the residual that determines the separation between the
72 /// "core" and the "tails" of the residuals distribution
73 
74 void TMVA::HuberLossFunction::Init(std::vector<LossFunctionEventInfo>& evs){
75 
76  // Calculate the residual that separates the core and the tails
77  SetSumOfWeights(evs);
78  SetTransitionPoint(evs);
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// huber, determine the quantile for a given input
83 
84 Double_t TMVA::HuberLossFunction::CalculateSumOfWeights(std::vector<LossFunctionEventInfo>& evs){
85 
86  // Calculate the sum of the weights
87  Double_t sumOfWeights = 0;
88  for(UInt_t i = 0; i<evs.size(); i++)
89  sumOfWeights+=evs[i].weight;
90 
91  return sumOfWeights;
92 }
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 /// huber, determine the quantile for a given input
96 
97 Double_t TMVA::HuberLossFunction::CalculateQuantile(std::vector<LossFunctionEventInfo>& evs, Double_t whichQuantile, Double_t sumOfWeights, bool abs){
98 
99  // use a lambda function to tell the vector how to sort the LossFunctionEventInfo data structures
100  // (sort them in ascending order of residual magnitude) if abs is true
101  // otherwise sort them in ascending order of residual
102  if(abs)
103  std::sort(evs.begin(), evs.end(), [](LossFunctionEventInfo a, LossFunctionEventInfo b){
104  return TMath::Abs(a.trueValue-a.predictedValue) < TMath::Abs(b.trueValue-b.predictedValue); });
105  else
106  std::sort(evs.begin(), evs.end(), [](LossFunctionEventInfo a, LossFunctionEventInfo b){
107  return (a.trueValue-a.predictedValue) < (b.trueValue-b.predictedValue); });
108  UInt_t i = 0;
109  Double_t temp = 0.0;
110  while(i<evs.size()-1 && temp <= sumOfWeights*whichQuantile){
111  temp += evs[i].weight;
112  i++;
113  }
114  // edge cases
115  // Output warning for low return values
116  if(whichQuantile == 0) i=0; // assume 0th quantile to mean the 0th entry in the ordered series
117 
118  // usual returns
119  if(abs) return TMath::Abs(evs[i].trueValue-evs[i].predictedValue);
120  else return evs[i].trueValue-evs[i].predictedValue;
121 }
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// huber, determine the transition point using the values for fQuantile and fSumOfWeights
125 /// which presumably have already been set
126 
127 void TMVA::HuberLossFunction::SetTransitionPoint(std::vector<LossFunctionEventInfo>& evs){
129 
130  // if the transition point corresponding to the quantile is 0 then the loss function will not function
131  // the quantile was chosen too low. Let's use the first nonzero residual as the transition point instead.
132  if(fTransitionPoint == 0){
133  // evs should already be sorted according to the magnitude of the residuals, since CalculateQuantile does this
134  for(UInt_t i=0; i<evs.size(); i++){
135  Double_t residual = TMath::Abs(evs[i].trueValue - evs[i].predictedValue);
136  if(residual != 0){
137  fTransitionPoint = residual;
138  break;
139  }
140  }
141  }
142 
143  // Let the user know that the transition point is zero and the loss function won't work properly
144  if(fTransitionPoint == 0){
145  //std::cout << "The residual transition point for the Huber loss function corresponding to quantile, " << fQuantile << ", is zero."
146  //<< " This implies that all of the residuals are zero and the events have been predicted perfectly. Perhaps the regression is too complex"
147  //<< " for the amount of data." << std::endl;
148  }
149 }
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 /// huber, set the sum of weights given a collection of events
153 
154 void TMVA::HuberLossFunction::SetSumOfWeights(std::vector<LossFunctionEventInfo>& evs){
156 }
157 
158 ////////////////////////////////////////////////////////////////////////////////
159 /// huber, determine the loss for a single event
160 
162  // If the huber loss function is uninitialized then assume a group of one
163  // and initialize the transition point and weights for this single event
164  if(fSumOfWeights == -9999){
165  std::vector<LossFunctionEventInfo> evs;
166  evs.push_back(e);
167 
168  SetSumOfWeights(evs);
169  SetTransitionPoint(evs);
170  }
171 
172  Double_t residual = TMath::Abs(e.trueValue - e.predictedValue);
173  Double_t loss = 0;
174  // Quadratic loss in terms of the residual for small residuals
175  if(residual <= fTransitionPoint) loss = 0.5*residual*residual;
176  // Linear loss for large residuals, so that the tails don't dominate the net loss calculation
177  else loss = fQuantile*residual - 0.5*fQuantile*fQuantile;
178  return e.weight*loss;
179 }
180 
181 ////////////////////////////////////////////////////////////////////////////////
182 /// huber, determine the net loss for a collection of events
183 
184 Double_t TMVA::HuberLossFunction::CalculateNetLoss(std::vector<LossFunctionEventInfo>& evs){
185  // Initialize the Huber Loss Function so that we can calculate the loss.
186  // The loss for each event depends on the other events in the group
187  // that define the cutoff quantile (fTransitionPoint).
188  SetSumOfWeights(evs);
189  SetTransitionPoint(evs);
190 
191  Double_t netloss = 0;
192  for(UInt_t i=0; i<evs.size(); i++)
193  netloss+=CalculateLoss(evs[i]);
194  return netloss;
195  // should get a function to return the average loss as well
196  // return netloss/fSumOfWeights
197 }
198 
199 ////////////////////////////////////////////////////////////////////////////////
200 /// huber, determine the mean loss for a collection of events
201 
202 Double_t TMVA::HuberLossFunction::CalculateMeanLoss(std::vector<LossFunctionEventInfo>& evs){
203  // Initialize the Huber Loss Function so that we can calculate the loss.
204  // The loss for each event depends on the other events in the group
205  // that define the cutoff quantile (fTransitionPoint).
206  SetSumOfWeights(evs);
207  SetTransitionPoint(evs);
208 
209  Double_t netloss = 0;
210  for(UInt_t i=0; i<evs.size(); i++)
211  netloss+=CalculateLoss(evs[i]);
212  return netloss/fSumOfWeights;
213 }
214 
215 /*! \class TMVA::HuberLossFunctionBDT
216 \ingroup TMVA
217 
218 Huber BDT Loss Function.
219 
220 */
221 
223 }
224 
225 ////////////////////////////////////////////////////////////////////////////////
226 /// huber BDT, initialize the targets and prepare for the regression
227 
228 void TMVA::HuberLossFunctionBDT::Init(std::map<const TMVA::Event*, LossFunctionEventInfo>& evinfomap, std::vector<double>& boostWeights){
229 // Run this once before building the forest. Set initial prediction to weightedMedian.
230 
231  std::vector<LossFunctionEventInfo> evinfovec;
232  for (auto &e: evinfomap){
233  evinfovec.push_back(LossFunctionEventInfo(e.second.trueValue, e.second.predictedValue, e.first->GetWeight()));
234  }
235 
236  // Calculates fSumOfWeights and fTransitionPoint with the current residuals
237  SetSumOfWeights(evinfovec);
238  Double_t weightedMedian = CalculateQuantile(evinfovec, 0.5, fSumOfWeights, false);
239 
240  //Store the weighted median as a first boosweight for later use
241  boostWeights.push_back(weightedMedian);
242  for (auto &e: evinfomap ) {
243  // set the initial prediction for all events to the median
244  e.second.predictedValue += weightedMedian;
245  }
246 }
247 
248 ////////////////////////////////////////////////////////////////////////////////
249 /// huber BDT, set the targets for a collection of events
250 
251 void TMVA::HuberLossFunctionBDT::SetTargets(std::vector<const TMVA::Event*>& evs, std::map< const TMVA::Event*, LossFunctionEventInfo >& evinfomap){
252 
253  std::vector<LossFunctionEventInfo> eventvec;
254  for (std::vector<const TMVA::Event*>::const_iterator e=evs.begin(); e!=evs.end();e++){
255  eventvec.push_back(LossFunctionEventInfo(evinfomap[*e].trueValue, evinfomap[*e].predictedValue, (*e)->GetWeight()));
256  }
257 
258  // Recalculate the residual that separates the "core" of the data and the "tails"
259  // This residual is the quantile given by fQuantile, defaulted to 0.7
260  // the quantile corresponding to 0.5 would be the usual median
261  SetSumOfWeights(eventvec); // This was already set in init, but may change if there is subsampling for each tree
262  SetTransitionPoint(eventvec);
263 
264  for (std::vector<const TMVA::Event*>::const_iterator e=evs.begin(); e!=evs.end();e++) {
265  const_cast<TMVA::Event*>(*e)->SetTarget(0,Target(evinfomap[*e]));
266  }
267 }
268 
269 ////////////////////////////////////////////////////////////////////////////////
270 /// huber BDT, set the target for a single event
271 
273  Double_t residual = e.trueValue - e.predictedValue;
274  // The weight/target relationships are taken care of in the tmva decision tree operations so we don't need to worry about that here
275  if(TMath::Abs(residual) <= fTransitionPoint) return residual;
276  else return fTransitionPoint*(residual<0?-1.0:1.0);
277 }
278 
279 ////////////////////////////////////////////////////////////////////////////////
280 /// huber BDT, determine the fit value for the terminal node based upon the
281 /// events in the terminal node
282 
283 Double_t TMVA::HuberLossFunctionBDT::Fit(std::vector<LossFunctionEventInfo>& evs){
284 // The fit in the terminal node for huber is basically the median of the residuals.
285 // Then you add the average difference from the median to that.
286 // The tails are discounted. If a residual is in the tails then we just use the
287 // cutoff residual that sets the "core" and the "tails" instead of the large residual.
288 // So we get something between least squares (mean as fit) and absolute deviation (median as fit).
289  Double_t sumOfWeights = CalculateSumOfWeights(evs);
290  Double_t shift=0,diff= 0;
291  Double_t residualMedian = CalculateQuantile(evs,0.5,sumOfWeights, false);
292  for(UInt_t j=0;j<evs.size();j++){
293  Double_t residual = evs[j].trueValue - evs[j].predictedValue;
294  diff = residual-residualMedian;
295  // if we are using weights then I'm not sure why this isn't weighted
296  shift+=1.0/evs.size()*((diff<0)?-1.0:1.0)*TMath::Min(fTransitionPoint,fabs(diff));
297  // I think this should be
298  // shift+=evs[j].weight/sumOfWeights*((diff<0)?-1.0:1.0)*TMath::Min(fTransitionPoint,fabs(diff));
299  // not sure why it was originally coded like this
300  }
301  return (residualMedian + shift);
302 
303 }
304 
305 /*! \class TMVA::LeastSquaresLossFunction
306 \ingroup TMVA
307 
308 Least Squares Loss Function.
309 
310 */
311 
312 // Constructor and destructor are in header file. They don't do anything.
313 
314 ////////////////////////////////////////////////////////////////////////////////
315 /// least squares , determine the loss for a single event
316 
318  Double_t residual = (e.trueValue - e.predictedValue);
319  Double_t loss = 0;
320  loss = residual*residual;
321  return e.weight*loss;
322 }
323 
324 ////////////////////////////////////////////////////////////////////////////////
325 /// least squares , determine the net loss for a collection of events
326 
327 Double_t TMVA::LeastSquaresLossFunction::CalculateNetLoss(std::vector<LossFunctionEventInfo>& evs){
328  Double_t netloss = 0;
329  for(UInt_t i=0; i<evs.size(); i++)
330  netloss+=CalculateLoss(evs[i]);
331  return netloss;
332  // should get a function to return the average loss as well
333  // return netloss/fSumOfWeights
334 }
335 
336 ////////////////////////////////////////////////////////////////////////////////
337 /// least squares , determine the mean loss for a collection of events
338 
339 Double_t TMVA::LeastSquaresLossFunction::CalculateMeanLoss(std::vector<LossFunctionEventInfo>& evs){
340  Double_t netloss = 0;
341  Double_t sumOfWeights = 0;
342  for(UInt_t i=0; i<evs.size(); i++){
343  sumOfWeights+=evs[i].weight;
344  netloss+=CalculateLoss(evs[i]);
345  }
346  // return the weighted mean
347  return netloss/sumOfWeights;
348 }
349 
350 /*! \class TMVA::LeastSquaresLossFunctionBDT
351 \ingroup TMVA
352 
353 Least Squares BDT Loss Function.
354 
355 */
356 
357 // Constructor and destructor defined in header. They don't do anything.
358 
359 ////////////////////////////////////////////////////////////////////////////////
360 /// least squares BDT, initialize the targets and prepare for the regression
361 
362 void TMVA::LeastSquaresLossFunctionBDT::Init(std::map<const TMVA::Event*, LossFunctionEventInfo>& evinfomap, std::vector<double>& boostWeights){
363 // Run this once before building the forest. Set initial prediction to the weightedMean
364 
365  std::vector<LossFunctionEventInfo> evinfovec;
366  for (auto &e: evinfomap){
367  evinfovec.push_back(LossFunctionEventInfo(e.second.trueValue, e.second.predictedValue, e.first->GetWeight()));
368  }
369 
370  // Initial prediction for least squares is the weighted mean
371  Double_t weightedMean = Fit(evinfovec);
372 
373  //Store the weighted median as a first boosweight for later use
374  boostWeights.push_back(weightedMean);
375  for (auto &e: evinfomap ) {
376  // set the initial prediction for all events to the median
377  e.second.predictedValue += weightedMean;
378  }
379 }
380 
381 ////////////////////////////////////////////////////////////////////////////////
382 /// least squares BDT, set the targets for a collection of events
383 
384 void TMVA::LeastSquaresLossFunctionBDT::SetTargets(std::vector<const TMVA::Event*>& evs, std::map< const TMVA::Event*, LossFunctionEventInfo >& evinfomap){
385 
386  std::vector<LossFunctionEventInfo> eventvec;
387  for (std::vector<const TMVA::Event*>::const_iterator e=evs.begin(); e!=evs.end();e++){
388  eventvec.push_back(LossFunctionEventInfo(evinfomap[*e].trueValue, evinfomap[*e].predictedValue, (*e)->GetWeight()));
389  }
390 
391  for (std::vector<const TMVA::Event*>::const_iterator e=evs.begin(); e!=evs.end();e++) {
392  const_cast<TMVA::Event*>(*e)->SetTarget(0,Target(evinfomap[*e]));
393  }
394 }
395 
396 ////////////////////////////////////////////////////////////////////////////////
397 /// least squares BDT, set the target for a single event
398 
400  Double_t residual = e.trueValue - e.predictedValue;
401  // The weight/target relationships are taken care of in the tmva decision tree operations. We don't need to worry about that here
402  // and we return the residual instead of the weight*residual.
403  return residual;
404 }
405 
406 ////////////////////////////////////////////////////////////////////////////////
407 /// huber BDT, determine the fit value for the terminal node based upon the
408 /// events in the terminal node
409 
410 Double_t TMVA::LeastSquaresLossFunctionBDT::Fit(std::vector<LossFunctionEventInfo>& evs){
411 // The fit in the terminal node for least squares is the weighted average of the residuals.
412  Double_t sumOfWeights = 0;
413  Double_t weightedResidualSum = 0;
414  for(UInt_t j=0;j<evs.size();j++){
415  sumOfWeights += evs[j].weight;
416  Double_t residual = evs[j].trueValue - evs[j].predictedValue;
417  weightedResidualSum += evs[j].weight*residual;
418  }
419  Double_t weightedMean = weightedResidualSum/sumOfWeights;
420 
421  // return the weighted mean
422  return weightedMean;
423 }
424 
425 /*! \class TMVA::AbsoluteDeviationLossFunction
426 \ingroup TMVA
427 
428 Absolute Deviation Loss Function.
429 
430 */
431 
432 // Constructors in the header. They don't do anything.
433 
434 ////////////////////////////////////////////////////////////////////////////////
435 /// absolute deviation, determine the loss for a single event
436 
438  Double_t residual = e.trueValue - e.predictedValue;
439  return e.weight*TMath::Abs(residual);
440 }
441 
442 ////////////////////////////////////////////////////////////////////////////////
443 /// absolute deviation, determine the net loss for a collection of events
444 
445 Double_t TMVA::AbsoluteDeviationLossFunction::CalculateNetLoss(std::vector<LossFunctionEventInfo>& evs){
446 
447  Double_t netloss = 0;
448  for(UInt_t i=0; i<evs.size(); i++)
449  netloss+=CalculateLoss(evs[i]);
450  return netloss;
451 }
452 
453 ////////////////////////////////////////////////////////////////////////////////
454 /// absolute deviation, determine the mean loss for a collection of events
455 
456 Double_t TMVA::AbsoluteDeviationLossFunction::CalculateMeanLoss(std::vector<LossFunctionEventInfo>& evs){
457  Double_t sumOfWeights = 0;
458  Double_t netloss = 0;
459  for(UInt_t i=0; i<evs.size(); i++){
460  sumOfWeights+=evs[i].weight;
461  netloss+=CalculateLoss(evs[i]);
462  }
463  return netloss/sumOfWeights;
464 }
465 
466 /*! \class TMVA::AbsoluteDeviationLossFunctionBDT
467 \ingroup TMVA
468 
469 Absolute Deviation BDT Loss Function.
470 
471 */
472 
473 ////////////////////////////////////////////////////////////////////////////////
474 /// absolute deviation BDT, initialize the targets and prepare for the regression
475 
476 void TMVA::AbsoluteDeviationLossFunctionBDT::Init(std::map<const TMVA::Event*, LossFunctionEventInfo>& evinfomap, std::vector<double>& boostWeights){
477 // Run this once before building the forest. Set initial prediction to weightedMedian.
478 
479  std::vector<LossFunctionEventInfo> evinfovec;
480  for (auto &e: evinfomap){
481  evinfovec.push_back(LossFunctionEventInfo(e.second.trueValue, e.second.predictedValue, e.first->GetWeight()));
482  }
483 
484  Double_t weightedMedian = Fit(evinfovec);
485 
486  //Store the weighted median as a first boostweight for later use
487  boostWeights.push_back(weightedMedian);
488  for (auto &e: evinfomap ) {
489  // set the initial prediction for all events to the median
490  e.second.predictedValue += weightedMedian;
491  }
492 }
493 
494 ////////////////////////////////////////////////////////////////////////////////
495 /// absolute deviation BDT, set the targets for a collection of events
496 
497 void TMVA::AbsoluteDeviationLossFunctionBDT::SetTargets(std::vector<const TMVA::Event*>& evs, std::map< const TMVA::Event*, LossFunctionEventInfo >& evinfomap){
498 
499  std::vector<LossFunctionEventInfo> eventvec;
500  for (std::vector<const TMVA::Event*>::const_iterator e=evs.begin(); e!=evs.end();e++){
501  eventvec.push_back(LossFunctionEventInfo(evinfomap[*e].trueValue, evinfomap[*e].predictedValue, (*e)->GetWeight()));
502  }
503 
504  for (std::vector<const TMVA::Event*>::const_iterator e=evs.begin(); e!=evs.end();e++) {
505  const_cast<TMVA::Event*>(*e)->SetTarget(0,Target(evinfomap[*e]));
506  }
507 }
508 
509 ////////////////////////////////////////////////////////////////////////////////
510 /// absolute deviation BDT, set the target for a single event
511 
513 // The target is the sign of the residual.
514  Double_t residual = e.trueValue - e.predictedValue;
515  // The weight/target relationships are taken care of in the tmva decision tree operations so we don't need to worry about that here
516  return (residual<0?-1.0:1.0);
517 }
518 
519 ////////////////////////////////////////////////////////////////////////////////
520 /// absolute deviation BDT, determine the fit value for the terminal node based upon the
521 /// events in the terminal node
522 
523 Double_t TMVA::AbsoluteDeviationLossFunctionBDT::Fit(std::vector<LossFunctionEventInfo>& evs){
524 // For Absolute Deviation, the fit in each terminal node is the weighted residual median.
525 
526  // use a lambda function to tell the vector how to sort the LossFunctionEventInfo data structures
527  // sort in ascending order of residual value
528  std::sort(evs.begin(), evs.end(), [](LossFunctionEventInfo a, LossFunctionEventInfo b){
529  return (a.trueValue-a.predictedValue) < (b.trueValue-b.predictedValue); });
530 
531  // calculate the sum of weights, used in the weighted median calculation
532  Double_t sumOfWeights = 0;
533  for(UInt_t j=0; j<evs.size(); j++)
534  sumOfWeights+=evs[j].weight;
535 
536  // get the index of the weighted median
537  UInt_t i = 0;
538  Double_t temp = 0.0;
539  while(i<evs.size() && temp <= sumOfWeights*0.5){
540  temp += evs[i].weight;
541  i++;
542  }
543  if (i >= evs.size()) return 0.; // prevent uncontrolled memory access in return value calculation
544 
545  // return the median residual
546  return evs[i].trueValue-evs[i].predictedValue;
547 }
548 
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
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)
Definition: TMathBase.h:168
TArc * a
Definition: textangle.C:12
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...
Short_t Abs(Short_t d)
Definition: TMathBase.h:108
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 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 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)
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 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
unsigned int UInt_t
Definition: RtypesCore.h:42
void SetTarget(UInt_t itgt, Float_t value)
set the target value (dimension itgt) to value
Definition: Event.cxx:360
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 Double_t
Definition: RtypesCore.h:55
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:134
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
Definition: TRolke.cxx:630
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
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
Definition: TRolke.cxx:630
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