source: foam/trunk/vision/src/LDAClassifier.h @ 85

Revision 85, 2.6 KB checked in by dave, 11 years ago (diff)

started writing the LDA classifier

Line 
1// Copyright (C) 2009 foam
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation; either version 2 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17#include <vector>
18#include <map>
19#include <set>
20#include "Vector.h"
21#include "Matrix.h"
22
23#ifndef FOAM_LDA_CLASSIFIER
24#define FOAM_LDA_CLASSIFIER
25
26// A linear discriminant analysis classifier for arbitrary data sets
27
28template<class T>
29class LDAClassifier
30{
31public:
32        LDAClassifier(unsigned int FeatureSize);
33        ~LDAClassifier();
34
35        class Feature
36        {
37        public:
38                Vector<T> m_Data;
39                int m_Class;
40        };
41
42        void AddFeature(const Feature &f);
43        int Classify(const Feature &f);
44
45private:
46
47        void CalcClasses();
48        void CalcGlobalMean();
49        void CalcClassMeans();
50        void CalcMeanCorrected();
51        void CalcCovariance();
52        void CalcPooledCovariance();
53        void CalcPriorProbablity();
54
55        unsigned int m_FeatureSize;
56        std::vector<Feature > m_Features;
57       
58        std::set<int> m_Classes;
59        Vector<T> m_GlobalMean;
60        std::map<int,Vector<T> > m_ClassMeans;
61        std::map<int,Matrix<T> > m_MeanCorrected;
62        std::map<int,Matrix<T> > m_Covariance;
63        Matrix<T> m_PooledCovariance;
64        Vector<T> m_PriorProbability;
65
66};
67
68template<class T>
69LDAClassifier<T>::LDAClassifier(unsigned int FeatureSize)
70{
71}
72
73template<class T>
74LDAClassifier<T>::~LDAClassifier()
75{
76}
77
78template<class T>
79void LDAClassifier<T>::AddFeature(const Feature &f)
80{
81        m_Features.push_back(f);
82}
83
84template<class T>
85int LDAClassifier<T>::Classify(const Feature &f)
86{
87        return 0;
88}
89
90template<class T>
91void LDAClassifier<T>::CalcClasses()
92{
93        m_Classes.clear();
94        for (typename std::vector<Feature >::iterator i=m_Features.begin();
95                i!=m_Features.end(); ++i)
96        {
97                m_Classes.insert(i->m_Class);
98        }
99}
100
101template<class T>
102void LDAClassifier<T>::CalcGlobalMean()
103{
104
105}
106
107template<class T>
108void LDAClassifier<T>::CalcClassMeans()
109{
110}
111
112template<class T>
113void LDAClassifier<T>::CalcMeanCorrected()
114{
115}
116
117template<class T>
118void LDAClassifier<T>::CalcCovariance()
119{
120}
121
122template<class T>
123void LDAClassifier<T>::CalcPooledCovariance()
124{
125}
126
127template<class T>
128void LDAClassifier<T>::CalcPriorProbablity()
129{
130}
131
132#endif
Note: See TracBrowser for help on using the repository browser.