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

Constructor & Destructor Documentation

◆ AbsoluteDeviation()

emtf::AbsoluteDeviation::AbsoluteDeviation ( )
inline

Definition at line 70 of file LossFunctions.h.

70 {}

◆ ~AbsoluteDeviation()

emtf::AbsoluteDeviation::~AbsoluteDeviation ( )
inlineoverride

Definition at line 71 of file LossFunctions.h.

71 {}

Member Function Documentation

◆ fit()

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

Implements emtf::LossFunction.

Definition at line 81 of file LossFunctions.h.

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  }

References MillePedeFileConverter_cfg::e, LaserClient_cfi::high, mps_fire::i, LaserClient_cfi::low, and findQualityFiles::v.

Referenced by trackingPlots.Iteration::modules().

◆ id()

int emtf::AbsoluteDeviation::id ( void  )
inlineoverridevirtual

Implements emtf::LossFunction.

Definition at line 112 of file LossFunctions.h.

112 { return 2; }

◆ name()

std::string emtf::AbsoluteDeviation::name ( void  )
inlineoverridevirtual

Implements emtf::LossFunction.

Definition at line 111 of file LossFunctions.h.

111 { return "Absolute_Deviation"; }

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

◆ target()

double emtf::AbsoluteDeviation::target ( Event e)
inlineoverridevirtual

Implements emtf::LossFunction.

Definition at line 73 of file LossFunctions.h.

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

References MillePedeFileConverter_cfg::e.

mps_fire.i
i
Definition: mps_fire.py:355
findQualityFiles.v
v
Definition: findQualityFiles.py:179
Event
LaserClient_cfi.high
high
Definition: LaserClient_cfi.py:50
LaserClient_cfi.low
low
Definition: LaserClient_cfi.py:52
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37