CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
emtf::Huber Class Reference

#include <LossFunctions.h>

Inheritance diagram for emtf::Huber:
emtf::LossFunction

Public Member Functions

double calculateQuantile (std::vector< Event * > &v, double whichQuantile)
 
double fit (std::vector< Event * > &v) override
 
 Huber ()
 
int id () override
 
std::string name () override
 
double target (Event *e) override
 
 ~Huber () override
 
- Public Member Functions inherited from emtf::LossFunction
virtual ~LossFunction ()=default
 

Public Attributes

double quantile
 
double residual_median
 

Detailed Description

Definition at line 131 of file LossFunctions.h.

Constructor & Destructor Documentation

emtf::Huber::Huber ( )
inline

Definition at line 134 of file LossFunctions.h.

134 {}
emtf::Huber::~Huber ( )
inlineoverride

Definition at line 135 of file LossFunctions.h.

135 {}

Member Function Documentation

double emtf::Huber::calculateQuantile ( std::vector< Event * > &  v,
double  whichQuantile 
)
inline

Definition at line 173 of file LossFunctions.h.

References funct::abs(), MillePedeFileConverter_cfg::e, mps_fire::i, emtf::Event::predictedValue, jetUpdater_cfi::sort, and emtf::Event::trueValue.

174  {
175  // Container for the residuals.
176  std::vector<double> residuals(v.size());
177 
178  // Load the residuals into a vector.
179  for(unsigned int i=0; i<v.size(); i++)
180  {
181  Event* e = v[i];
182  residuals[i] = std::abs(e->trueValue - e->predictedValue);
183  }
184 
185  std::sort(residuals.begin(), residuals.end());
186  unsigned int quantile_location = whichQuantile*(residuals.size()-1);
187  return residuals[quantile_location];
188  }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double emtf::Huber::fit ( std::vector< Event * > &  v)
inlineoverridevirtual

Implements emtf::LossFunction.

Definition at line 150 of file LossFunctions.h.

References funct::abs(), diffTreeTool::diff, MillePedeFileConverter_cfg::e, mps_fire::i, min(), emtf::Event::predictedValue, and emtf::Event::trueValue.

Referenced by trackingPlots.Iteration::modules().

151  {
152  // The constant fit that minimizes Huber in a region.
153 
154  quantile = calculateQuantile(v, 0.7);
156 
157  double x = 0;
158  for(unsigned int i=0; i<v.size(); i++)
159  {
160  Event* e = v[i];
161  double residual = e->trueValue - e->predictedValue;
162  double diff = residual - residual_median;
163  x += ((diff > 0)?1.0:-1.0)*std::min(quantile, std::abs(diff));
164  }
165 
166  return (residual_median + x/v.size());
167 
168  }
double quantile
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T min(T a, T b)
Definition: MathUtil.h:58
double calculateQuantile(std::vector< Event * > &v, double whichQuantile)
double residual_median
int emtf::Huber::id ( void  )
inlineoverridevirtual

Implements emtf::LossFunction.

Definition at line 171 of file LossFunctions.h.

171 { return 3; }
std::string emtf::Huber::name ( void  )
inlineoverridevirtual

Implements emtf::LossFunction.

Definition at line 170 of file LossFunctions.h.

Referenced by config.CFG::__str__(), validation.Sample::digest(), and VIDSelectorBase.VIDSelectorBase::initialize().

170 { return "Huber"; }
double emtf::Huber::target ( Event e)
inlineoverridevirtual

Implements emtf::LossFunction.

Definition at line 140 of file LossFunctions.h.

References funct::abs(), emtf::Event::predictedValue, and emtf::Event::trueValue.

141  {
142  // The gradient of the loss function.
143 
144  if (std::abs(e->trueValue - e->predictedValue) <= quantile)
145  return (e->trueValue - e->predictedValue);
146  else
147  return quantile*(((e->trueValue - e->predictedValue) > 0)?1.0:-1.0);
148  }
double quantile
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

Member Data Documentation

double emtf::Huber::quantile

Definition at line 137 of file LossFunctions.h.

double emtf::Huber::residual_median

Definition at line 138 of file LossFunctions.h.