CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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

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, and findQualityFiles::size.

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 }
long double T
tuple size
Write out results.