pktools  2.6.7
Processing Kernel for geospatial data
CostFactory.h
1 /**********************************************************************
2 CostFactory.h: select features, typical use: feature selection for classification
3 Copyright (C) 2008-2012 Pieter Kempeneers
4 
5 This file is part of pktools
6 
7 pktools is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 pktools is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with pktools. If not, see <http://www.gnu.org/licenses/>.
19 ***********************************************************************/
20 #ifndef _COSTFACTORY_H_
21 #define _COSTFACTORY_H_
22 
23 #include <math.h>
24 #include <vector>
25 #include <map>
26 #include "ConfusionMatrix.h"
27 #include "base/Vector2d.h"
28 
29 
31 public:
32  CostFactory(void){};
33  CostFactory(unsigned short cv, short verbose) : m_cv(cv), m_verbose(verbose){};
34 
35  virtual ~CostFactory(void){};
36  void setCv(unsigned short cv){m_cv=cv;};
37  void setClassValueMap(const std::string& classname, short classvalue){ m_classValueMap[classname]=classvalue;};
38  std::map<std::string,short> getClassValueMap(){return m_classValueMap;};
39  std::vector<std::string> getNameVector(){return m_nameVector;};
40  void setNameVector(std::vector<std::string>& nameVector){m_nameVector=nameVector;};
41  int getClassIndex(std::string classname) const {return m_cm.getClassIndex(classname);};
42  //pushBackClassName is for confusion matrix
43  void pushBackClassName(std::string classname){m_cm.pushBackClassName(classname,true);};//doSort=true
44  //pushBackName is for nameVector in CostFactory
45  void pushBackName(std::string classname){m_nameVector.push_back(classname);};
46  void setNcTraining(const std::vector<unsigned int> nctraining){m_nctraining=nctraining;};
47  void setNcTest(const std::vector<unsigned int> nctest){m_nctest=nctest;};
48  //getCost needs to be implemented case by case (e.g., SVM, ANN)
49  virtual double getCost(const std::vector<Vector2d<float> > &trainingFeatures)=0;
50 
51 protected:
53  std::map<std::string,short> m_classValueMap;
54  std::vector<std::string> m_nameVector;
55  std::vector<unsigned int> m_nctraining;
56  std::vector<unsigned int> m_nctest;
57  unsigned short m_cv;
58  /* std::string m_classname; */
59  short m_classvalue;
60  short m_verbose;
61 };
62 #endif