CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 68 of file LossFunctions.h.

Constructor & Destructor Documentation

emtf::AbsoluteDeviation::AbsoluteDeviation ( )
inline

Definition at line 70 of file LossFunctions.h.

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

Definition at line 71 of file LossFunctions.h.

71 {}

Member Function Documentation

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

Implements emtf::LossFunction.

Definition at line 81 of file LossFunctions.h.

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

Referenced by trackingPlots.Iteration::modules().

81  {
82  // The median of the residuals minimizes absolute deviation.
83  if (v.empty())
84  return 0;
85  std::vector<double> residuals(v.size());
86 
87  // Load the residuals into a vector.
88  for (unsigned int i = 0; i < v.size(); i++) {
89  Event* e = v[i];
90  residuals[i] = (e->trueValue - e->predictedValue);
91  }
92 
93  // Get the median and return it.
94  int median_loc = (residuals.size() - 1) / 2;
95 
96  // Odd.
97  if (residuals.size() % 2 != 0) {
98  std::nth_element(residuals.begin(), residuals.begin() + median_loc, residuals.end());
99  return residuals[median_loc];
100  }
101 
102  // Even.
103  else {
104  std::nth_element(residuals.begin(), residuals.begin() + median_loc, residuals.end());
105  double low = residuals[median_loc];
106  std::nth_element(residuals.begin() + median_loc + 1, residuals.begin() + median_loc + 1, residuals.end());
107  double high = residuals[median_loc + 1];
108  return (high + low) / 2;
109  }
110  }
int emtf::AbsoluteDeviation::id ( void  )
inlineoverridevirtual

Implements emtf::LossFunction.

Definition at line 112 of file LossFunctions.h.

112 { return 2; }
std::string emtf::AbsoluteDeviation::name ( void  )
inlineoverridevirtual
double emtf::AbsoluteDeviation::target ( Event e)
inlineoverridevirtual

Implements emtf::LossFunction.

Definition at line 73 of file LossFunctions.h.

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

73  {
74  // The gradient.
75  if ((e->trueValue - e->predictedValue) >= 0)
76  return 1;
77  else
78  return -1;
79  }