PedestrainCounting
ClassifierThreshold.h
1 
9 #ifndef CLASSIFIER_THRESHOLD_HEADER
10 #define CLASSIFIER_THRESHOLD_HEADER
11 
12 #include "EstimatedGaussianDistribution.h"
13 #include "Feature.h"
14 
15 template<int N> class ClassifierThreshold {
16 public:
19 
25  void Update(const Feature &feature, int target);
26 
34  int Classify(const Feature &feature) const;
35 
39  inline void Reset();
40 
41  void *GetDistribution(int target) const;
42 
43 private:
44 
47 
48  inline float SquareDistance(const float *a, const float *b, int N) const {
49  float d = 0.0f;
50  for (int i = 0; i < N; i++) {
51  d += (a[i] - b[i]) * (a[i] - b[i]);
52  }
53  return d;
54  }
55 };
56 
58  posSamples = new EstimatedGaussianDistribution<N>();
59  negSamples = new EstimatedGaussianDistribution<N>();
60 }
61 
63  if (posSamples != NULL)
64  delete posSamples;
65  if (negSamples != NULL)
66  delete negSamples;
67 }
68 
69 template<int N> void ClassifierThreshold<N>::Update(const Feature &feature, int target) {
70  if (target > 0)
71  posSamples->Update(feature.data);
72  else
73  negSamples->Update(feature.data);
74 }
75 
76 template<int N> int ClassifierThreshold<N>::Classify(const Feature &feature) const {
77  float dPos = SquareDistance(feature.data, posSamples->mean, N);
78  float dNeg = SquareDistance(feature.data, negSamples->mean, N);
79  if (dPos == 0.0f && dNeg == 0.0f) {
80  return -1;
81  }
82  return dPos < dNeg ? 1 : -1;
83 }
84 
85 template<int N> void *ClassifierThreshold<N>::GetDistribution(int target) const {
86  if (target > 0)
87  return posSamples;
88  else
89  return negSamples;
90 }
91 
92 template<int N> void ClassifierThreshold<N>::Reset() {
93  posSamples->Reset();
94  negSamples->Reset();
95 }
96 
97 #endif
void Update(const Feature &feature, int target)
Definition: ClassifierThreshold.h:69
void Reset()
Definition: ClassifierThreshold.h:92
Definition: EstimatedGaussianDistribution.h:10
Definition: ClassifierThreshold.h:15
Definition: Feature.h:12
int Classify(const Feature &feature) const
Definition: ClassifierThreshold.h:76