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
 
virtual ~AbsoluteDeviation ()
 
- Public Member Functions inherited from emtf::LossFunction
virtual ~LossFunction ()=default
 

Detailed Description

Definition at line 74 of file LossFunctions.h.

Constructor & Destructor Documentation

emtf::AbsoluteDeviation::AbsoluteDeviation ( )
inline

Definition at line 77 of file LossFunctions.h.

77 {}
virtual emtf::AbsoluteDeviation::~AbsoluteDeviation ( )
inlinevirtual

Definition at line 78 of file LossFunctions.h.

78 {}

Member Function Documentation

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

Implements emtf::LossFunction.

Definition at line 89 of file LossFunctions.h.

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

Referenced by trackingPlots.Iteration::modules().

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

Implements emtf::LossFunction.

Definition at line 123 of file LossFunctions.h.

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

Implements emtf::LossFunction.

Definition at line 122 of file LossFunctions.h.

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

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

Implements emtf::LossFunction.

Definition at line 80 of file LossFunctions.h.

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

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