90 auto redfunc = [](std::vector<Double_t>
a) ->
Double_t {
return std::accumulate(
a.begin(),
a.end(), 0); };
96 Int_t start = 1.0*partition/nPartitions*evs.size();
97 Int_t end = (partition+1.0)/nPartitions*evs.size();
99 for(
Int_t i=start; i<end; i++)
101 sumOfWeightsN+=evs[i].weight;
104 return sumOfWeightsN;
108 return sumOfWeightsN;
116 for(
UInt_t i = 0; i<evs.size(); i++)
117 sumOfWeights+=evs[i].weight;
139 while(i<evs.size()-1 && temp <= sumOfWeights*whichQuantile){
140 temp += evs[i].weight;
145 if(whichQuantile == 0) i=0;
148 if(abs)
return TMath::Abs(evs[i].trueValue-evs[i].predictedValue);
149 else return evs[i].trueValue-evs[i].predictedValue;
163 for(
UInt_t i=0; i<evs.size(); i++){
194 std::vector<LossFunctionEventInfo> evs;
221 for(
UInt_t i=0; i<evs.size(); i++)
239 for(
UInt_t i=0; i<evs.size(); i++)
260 std::vector<LossFunctionEventInfo> evinfovec;
261 for (
auto &
e: evinfomap){
270 boostWeights.push_back(weightedMedian);
271 for (
auto &
e: evinfomap ) {
273 e.second.predictedValue += weightedMedian;
285 std::vector<LossFunctionEventInfo> eventvec(evs.size());
292 auto fcopy = [&eventvec, &evs, &evinfomap, &nPartitions](
UInt_t partition = 0) ->
Int_t{
294 Int_t start = 1.0*partition/nPartitions*evs.size();
295 Int_t end = (partition+1.0)/nPartitions*evs.size();
297 for(
Int_t i=start; i<end; ++i)
298 eventvec[i] =
LossFunctionEventInfo(evinfomap[evs[i]].trueValue, evinfomap[evs[i]].predictedValue, evs[i]->GetWeight());
315 auto f = [
this, &evs, &evinfomap, &nPartitions](
UInt_t partition = 0) ->
Int_t{
317 Int_t start = 1.0*partition/nPartitions*evs.size();
318 Int_t end = (partition+1.0)/nPartitions*evs.size();
320 for(
Int_t i=start; i<end; ++i)
321 const_cast<TMVA::Event*>(evs[i])->SetTarget(0,Target(evinfomap[evs[i]]));
333 std::vector<LossFunctionEventInfo> eventvec;
334 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++){
335 eventvec.push_back(
LossFunctionEventInfo(evinfomap[*
e].trueValue, evinfomap[*
e].predictedValue, (*e)->GetWeight()));
344 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++) {
373 for(
UInt_t j=0;j<evs.size();j++){
374 Double_t residual = evs[j].trueValue - evs[j].predictedValue;
375 diff = residual-residualMedian;
382 return (residualMedian + shift);
401 loss = residual*residual;
410 for(
UInt_t i=0; i<evs.size(); i++)
423 for(
UInt_t i=0; i<evs.size(); i++){
424 sumOfWeights+=evs[i].weight;
428 return netloss/sumOfWeights;
446 std::vector<LossFunctionEventInfo> evinfovec;
447 for (
auto &
e: evinfomap){
455 boostWeights.push_back(weightedMean);
456 for (
auto &
e: evinfomap ) {
458 e.second.predictedValue += weightedMean;
473 auto f = [
this, &evs, &evinfomap, &nPartitions](
UInt_t partition = 0) ->
Int_t{
475 Int_t start = 1.0*partition/nPartitions*evs.size();
476 Int_t end = (partition+1.0)/nPartitions*evs.size();
478 for(
Int_t i=start; i<end; ++i)
479 const_cast<TMVA::Event*>(evs[i])->SetTarget(0,Target(evinfomap[evs[i]]));
490 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++) {
514 for(
UInt_t j=0;j<evs.size();j++){
515 sumOfWeights += evs[j].weight;
516 Double_t residual = evs[j].trueValue - evs[j].predictedValue;
517 weightedResidualSum += evs[j].weight*residual;
519 Double_t weightedMean = weightedResidualSum/sumOfWeights;
548 for(
UInt_t i=0; i<evs.size(); i++)
559 for(
UInt_t i=0; i<evs.size(); i++){
560 sumOfWeights+=evs[i].weight;
563 return netloss/sumOfWeights;
579 std::vector<LossFunctionEventInfo> evinfovec;
580 for (
auto &
e: evinfomap){
587 boostWeights.push_back(weightedMedian);
588 for (
auto &
e: evinfomap ) {
590 e.second.predictedValue += weightedMedian;
605 auto f = [
this, &evs, &evinfomap, &nPartitions](
UInt_t partition = 0) ->
Int_t{
607 Int_t start = 1.0*partition/nPartitions*evs.size();
608 Int_t end = (partition+1.0)/nPartitions*evs.size();
610 for(
Int_t i=start; i<end; ++i)
611 const_cast<TMVA::Event*>(evs[i])->SetTarget(0,Target(evinfomap[evs[i]]));
622 for (std::vector<const TMVA::Event*>::const_iterator
e=evs.begin();
e!=evs.end();
e++) {
635 return (residual<0?-1.0:1.0);
652 for(
UInt_t j=0; j<evs.size(); j++)
653 sumOfWeights+=evs[j].weight;
658 while(i<evs.size() && temp <= sumOfWeights*0.5){
659 temp += evs[i].weight;
662 if (i >= evs.size())
return 0.;
665 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
static Config & Instance()
static function: returns TMVA instance
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)
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 SetTargets(std::vector< const TMVA::Event *> &evs, std::map< const TMVA::Event *, LossFunctionEventInfo > &evinfomap)
huber BDT, set the targets for a collection of events
TSeq< unsigned int > TSeqU
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
ROOT::TThreadExecutor & GetThreadExecutor()
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, calculate the sum of weights for the events in the vector
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
auto MapReduce(F func, unsigned nTimes, R redfunc) -> typename std::result_of< F()>::type
This method behaves just like Map, but an additional redfunc function must be provided.
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
auto Map(F func, unsigned nTimes) -> std::vector< typename std::result_of< F()>::type >
Execute func (with no arguments) nTimes in parallel.
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