CMS 3D CMS Logo

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

#include <LossFunctions.h>

Inheritance diagram for emtf::AbsoluteDeviation:
emtf::LossFunction

Public Member Functions

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

Detailed Description

Definition at line 75 of file LossFunctions.h.

Constructor & Destructor Documentation

emtf::AbsoluteDeviation::AbsoluteDeviation ( )
inline

Definition at line 78 of file LossFunctions.h.

78 {}
emtf::AbsoluteDeviation::~AbsoluteDeviation ( )
inlineoverride

Definition at line 79 of file LossFunctions.h.

79 {}

Member Function Documentation

double emtf::AbsoluteDeviation::fit ( std::vector< Event * > &  v)
inlineoverridevirtual

Implements emtf::LossFunction.

Definition at line 90 of file LossFunctions.h.

References MillePedeFileConverter_cfg::e, mps_fire::i, emtf::Event::predictedValue, and emtf::Event::trueValue.

Referenced by trackingPlots.Iteration::modules().

91  {
92  // The median of the residuals minimizes absolute deviation.
93  if(v.empty()) return 0;
94  std::vector<double> residuals(v.size());
95 
96  // Load the residuals into a vector.
97  for(unsigned int i=0; i<v.size(); i++)
98  {
99  Event* e = v[i];
100  residuals[i] = (e->trueValue - e->predictedValue);
101  }
102 
103  // Get the median and return it.
104  int median_loc = (residuals.size()-1)/2;
105 
106  // Odd.
107  if(residuals.size()%2 != 0)
108  {
109  std::nth_element(residuals.begin(), residuals.begin()+median_loc, residuals.end());
110  return residuals[median_loc];
111  }
112 
113  // Even.
114  else
115  {
116  std::nth_element(residuals.begin(), residuals.begin()+median_loc, residuals.end());
117  double low = residuals[median_loc];
118  std::nth_element(residuals.begin()+median_loc+1, residuals.begin()+median_loc+1, residuals.end());
119  double high = residuals[median_loc+1];
120  return (high + low)/2;
121  }
122  }
int emtf::AbsoluteDeviation::id ( void  )
inlineoverridevirtual

Implements emtf::LossFunction.

Definition at line 124 of file LossFunctions.h.

124 { return 2; }
std::string emtf::AbsoluteDeviation::name ( void  )
inlineoverridevirtual

Implements emtf::LossFunction.

Definition at line 123 of file LossFunctions.h.

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

123 { return "Absolute_Deviation"; }
double emtf::AbsoluteDeviation::target ( Event e)
inlineoverridevirtual

Implements emtf::LossFunction.

Definition at line 81 of file LossFunctions.h.

References emtf::Event::predictedValue, and emtf::Event::trueValue.

82  {
83  // The gradient.
84  if ((e->trueValue - e->predictedValue) >= 0)
85  return 1;
86  else
87  return -1;
88  }