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 130 of file LossFunctions.h.

Constructor & Destructor Documentation

emtf::Huber::Huber ( )
inline

Definition at line 133 of file LossFunctions.h.

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

Definition at line 134 of file LossFunctions.h.

134 {}

Member Function Documentation

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

Definition at line 172 of file LossFunctions.h.

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

173  {
174  // Container for the residuals.
175  std::vector<double> residuals(v.size());
176 
177  // Load the residuals into a vector.
178  for(unsigned int i=0; i<v.size(); i++)
179  {
180  Event* e = v[i];
181  residuals[i] = std::abs(e->trueValue - e->predictedValue);
182  }
183 
184  std::sort(residuals.begin(), residuals.end());
185  unsigned int quantile_location = whichQuantile*(residuals.size()-1);
186  return residuals[quantile_location];
187  }
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 149 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().

150  {
151  // The constant fit that minimizes Huber in a region.
152 
153  quantile = calculateQuantile(v, 0.7);
155 
156  double x = 0;
157  for(unsigned int i=0; i<v.size(); i++)
158  {
159  Event* e = v[i];
160  double residual = e->trueValue - e->predictedValue;
161  double diff = residual - residual_median;
162  x += ((diff > 0)?1.0:-1.0)*std::min(quantile, std::abs(diff));
163  }
164 
165  return (residual_median + x/v.size());
166 
167  }
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 170 of file LossFunctions.h.

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

Implements emtf::LossFunction.

Definition at line 169 of file LossFunctions.h.

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

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

Implements emtf::LossFunction.

Definition at line 139 of file LossFunctions.h.

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

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

Member Data Documentation

double emtf::Huber::quantile

Definition at line 136 of file LossFunctions.h.

double emtf::Huber::residual_median

Definition at line 137 of file LossFunctions.h.