CMS 3D CMS Logo

Functions
lms_1d.h File Reference
#include "CommonTools/Statistics/interface/StatisticsException.h"
#include <vector>
#include <algorithm>
#include <cmath>

Go to the source code of this file.

Functions

template<class T >
T lms_1d (std::vector< T > values)
 

Function Documentation

◆ lms_1d()

template<class T >
T lms_1d ( std::vector< T values)

Least Median Sum of Squares in one dimension. T must be sortable, 'addable', and dividable by 2.

Definition at line 15 of file lms_1d.h.

References mps_fire::i, findQualityFiles::size, jetUpdater_cfi::sort, and contentValuesCheck::values.

Referenced by lms_3d().

15  {
16  switch (values.size()) {
17  case 0:
18  throw StatisticsException("Lms of empty vector undefined");
19  case 1:
20  return (T) * (values.begin());
21  case 2:
22  return (T)((*(values.begin()) + *(values.end() - 1)) / 2);
23  };
24  const int size = values.size();
25  const int half = size / 2;
26  const int n_steps = (size + 1) / 2;
27 
28  sort(values.begin(), values.end());
29 
30  T i_begin = *(values.begin());
31  T i_end = *(values.begin() + half);
32  T div = (T)fabs(i_begin - i_end);
33  for (typename std::vector<T>::const_iterator i = values.begin(); i != (values.begin() + n_steps); ++i) {
34  if (fabs((*i) - (*(i + half))) < div) {
35  i_begin = (*i);
36  i_end = *(i + half);
37  div = (T)fabs(i_begin - i_end);
38  }
39  }
40 
41  return (T)((i_begin + i_end) / 2);
42 }
size
Write out results.
long double T