MAP.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/classification/MAP.h
22 
23  \brief MAP (Maximum a Posteriori) strategy for classification.
24 */
25 
26 #ifndef __TERRALIB_CLASSIFICATION_INTERNAL_MAP_H
27 #define __TERRALIB_CLASSIFICATION_INTERNAL_MAP_H
28 
29 // TerraLib
30 #include "../common/AbstractParameters.h"
31 #include "../common/MatrixUtils.h"
32 #include "../common/progress/TaskProgress.h"
33 #include "Adaptors.h"
34 #include "Config.h"
35 #include "Exception.h"
36 
37 // STL
38 #include <vector>
39 #include <memory>
40 
41 // boost
42 #include <boost/numeric/ublas/matrix.hpp>
43 
44 namespace te
45 {
46  namespace cl
47  {
48  /*!
49  \class MAP
50  \brief MAP strategy for classification.
51 
52  */
53 
55  {
56  public:
57 
58  /*!
59  \class Parameters
60  \brief Classifier Parameters
61  */
63  {
64  public:
65 
66  std::vector< double > m_prioriProbs; //!< Priori probabilities, one for each class. Values from 0 to 1 (use an empty vector to allow internal calcule of priori probabilities).
67  unsigned int m_prioriCalcSampleStep; //!< A positive non-zero sample step used when calculating piori probabilities (default:5 - 1/5 of samples will be used);
68 
69  Parameters();
70 
71  ~Parameters();
72 
73  //overload
74  const Parameters& operator=(const Parameters& params);
75 
76  //overload
77  void reset() throw(te::cl::Exception);
78 
79  //overload
80  AbstractParameters* clone() const;
81  };
82 
83  public:
84 
85  MAP();
86 
87  ~MAP();
88 
89  /*!
90  \brief Initialize this classifier instance with new parameters.
91  \param params New initialization parameters.
92  */
93  bool initialize(const Parameters& params) throw(te::cl::Exception);
94 
95  /*!
96  \brief Train this classifier instance using the initialization parameters and the suppied train data.
97  \param samples Train data samples.
98  \param attributesIndices The attributes indexes to processe from the iterated train data.
99  \param sampleLabels The sample lables for each iterated train data element.
100  \param enableProgressInterface Enable/disable the use of a proress interfece.
101  */
102  bool train( const InputAdaptor< double >& samples,
103  const std::vector<unsigned int>& attributesIndices,
104  const std::vector<unsigned int>& sampleLabels,
105  const bool enableProgressInterface) throw(te::cl::Exception);
106 
107  /*!
108  \brief Classify an input iterated data and save the result on the output iterated data.
109  \param input Input data to be classified.
110  \param attributesIndices The attributes indexes to processe from the iterated train data.
111  \param inputNoDataValues A vector of no-data values for each attribute dimension or an empty vector if no-data values are not used.
112  \param output Output classified data.
113  \param outputIndex The output attribute index.
114  \param outputNoDataValue A output label value to use when dealing with input no-data.
115  \param enableProgressInterface Enable/disable the use of a proress interfece.
116  */
117  bool classify( const InputAdaptor< double >& input,
118  const std::vector<unsigned int>& attributesIndices,
119  const std::vector< double >& inputNoDataValues,
120  OutputAdaptor< unsigned int >& output,
121  const unsigned int outputIndex,
122  const double outputNoDataValue,
123  const bool enableProgressInterface) throw(te::cl::Exception);
124 
125  protected:
126 
127  bool m_isInitialized; //!< True if this instance is initialized.
128  Parameters m_parameters; //!< Internal execution parameters.
129  std::vector< std::vector< double > > m_classesMeans; //!< Classes means;
130  std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceMatrixes; //!< Classes covariance matrixes.
131  std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceInvMatrixes; //!< Classes covariance inverse matrixes.
132  std::vector<unsigned int> m_classLabels; //!< class labels
133  std::vector< double > m_classesOptizedMAPDiscriminantTerm; //!< An optimized portion of the MAP discriminant function.
134 
135  /*! \brief Reset this instance to its initial state */
136  void reset();
137 
138  /*!
139  \brief Calculate priori probabilities by pre-classifying the input data.
140  \param input Input data to be classified.
141  \param attributesIndices The attributes indexes to processe from the iterated train data.
142  \param prioriProbs Calculated priori-probabilities.
143  */
144  bool getPrioriProbabilities( const InputAdaptor< double >& input,
145  const std::vector<unsigned int>& attributesIndices,
146  std::vector< double >& prioriProbs ) const;
147  };
148  } // end namespace cl
149 } // end namespace te
150 
151 #endif // __TERRALIB_CLASSIFICATION_INTERNAL_MAP_H
unsigned int m_prioriCalcSampleStep
A positive non-zero sample step used when calculating piori probabilities (default:5 - 1/5 of samples...
Definition: MAP.h:67
Classifier Parameters.
Definition: MAP.h:62
Base exception class for plugin module.
Definition: Exception.h:42
std::vector< double > m_prioriProbs
Priori probabilities, one for each class. Values from 0 to 1 (use an empty vector to allow internal c...
Definition: MAP.h:66
Configuration flags for the Terrralib Classification module.
Classifiers input data adaptor.
Definition: Adaptors.h:45
Classifiers output data adaptor.
Definition: Adaptors.h:79
MAP strategy for classification.
Definition: MAP.h:54
URI C++ Library.
Abstract parameters base interface.
#define TECLEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:102
An exception class for the Classification module.
Classifiers adaptors.