CMS 3D CMS Logo

List of all members | Public Member Functions
AbsoluteDeviation Class Reference

#include <LossFunctions.h>

Inheritance diagram for AbsoluteDeviation:
L1TLossFunction

Public Member Functions

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

Detailed Description

Definition at line 71 of file LossFunctions.h.

Constructor & Destructor Documentation

AbsoluteDeviation::AbsoluteDeviation ( )
inline

Definition at line 74 of file LossFunctions.h.

74 {}
AbsoluteDeviation::~AbsoluteDeviation ( )
inline

Definition at line 75 of file LossFunctions.h.

75 {}

Member Function Documentation

Double_t AbsoluteDeviation::fit ( std::vector< emtf::Event * > &  v)
inlinevirtual

Implements L1TLossFunction.

Definition at line 86 of file LossFunctions.h.

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

Referenced by trackingPlots.Iteration::modules().

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

Implements L1TLossFunction.

Definition at line 120 of file LossFunctions.h.

120 { return 2; }
std::string AbsoluteDeviation::name ( void  )
inlinevirtual

Implements L1TLossFunction.

Definition at line 119 of file LossFunctions.h.

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

119 { return "Absolute_Deviation"; }
Double_t AbsoluteDeviation::target ( emtf::Event e)
inlinevirtual

Implements L1TLossFunction.

Definition at line 77 of file LossFunctions.h.

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

78  {
79  // The gradient.
80  if ((e->trueValue - e->predictedValue) >= 0)
81  return 1;
82  else
83  return -1;
84  }
Double_t trueValue
Definition: Event.h:19
Double_t predictedValue
Definition: Event.h:20