MaxLikelihood.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/MaxLikelihood.h
22 
23  \brief A maximum likelihood estimation strategy for classification (a.k.a. MaxVer in portuguese).
24 */
25 
26 #ifndef __TERRALIB_CLASSIFICATION_INTERNAL_MAXLIKELIHOOD_H
27 #define __TERRALIB_CLASSIFICATION_INTERNAL_MAXLIKELIHOOD_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 MaxLikelihood
50  \brief A maximum likelihood estimation strategy for classification (a.k.a. MaxVer in portuguese).
51  \note Reference: Erthal, G.J.; Frery, A.C. Segmentação de imagens multiespectrais pelo algoritmo ICM:integração ao ambiente SPRING. In: Simpósio Brasileiro de Computação Gráfica eProcessamento de Imagens-SIBGRAP, 6., Recife, 1993. Comunicações. Recife:SBC/UFPe, 1993. p. 33-36.
52 
53  */
54 
56  {
57  public:
58 
59  /*!
60  \class Parameters
61  \brief Classifier Parameters
62  */
64  {
65  public:
66 
67  Parameters();
68 
69  ~Parameters();
70 
71  //overload
72  const Parameters& operator=(const Parameters& params);
73 
74  //overload
75  void reset();
76 
77  //overload
78  AbstractParameters* clone() const;
79  };
80 
81  public:
82 
83  MaxLikelihood();
84 
85  ~MaxLikelihood();
86 
87  /*!
88  \brief Initialize this classifier instance with new parameters.
89  \param params New initialization parameters.
90  */
91  bool initialize(const Parameters& params);
92 
93  /*!
94  \brief Train this classifier instance using the initialization parameters and the suppied train data.
95  \param samples Train data samples.
96  \param attributesIndices The attributes indexes to processe from the iterated train data.
97  \param sampleLabels The sample lables for each iterated train data element.
98  \param enableProgressInterface Enable/disable the use of a proress interfece.
99  */
100  bool train( const InputAdaptor< double >& samples,
101  const std::vector<unsigned int>& attributesIndices,
102  const std::vector<unsigned int>& sampleLabels,
103  const bool enableProgressInterface);
104 
105  /*!
106  \brief Classify an input iterated data and save the result on the output iterated data.
107  \param input Input data to be classified.
108  \param attributesIndices The attributes indexes to processe from the iterated train data.
109  \param inputNoDataValues A vector of no-data values for each attribute dimension or an empty vector if no-data values are not used.
110  \param output Output classified data.
111  \param outputIndex The output attribute index.
112  \param outputNoDataValue A output label value to use when dealing with input no-data.
113  \param enableProgressInterface Enable/disable the use of a proress interfece.
114  */
115  bool classify( const InputAdaptor< double >& input,
116  const std::vector<unsigned int>& attributesIndices,
117  const std::vector< double >& inputNoDataValues,
119  const unsigned int outputIndex,
120  const unsigned int outputNoDataValue,
121  const bool enableProgressInterface);
122 
123  /*!
124  \brief Get the current classes covariance matrixes.
125  \param covMatrixes A vector to return the current classes covariance matrixes.
126  \return true if ok, false on errors.
127  */
128  bool getCovMatrixes( std::vector< boost::numeric::ublas::matrix< double > >& covMatrixes ) const;
129 
130  /*!
131  \brief Get the current classes inverse covariance matrixes.
132  \param invCovMatrixes A vector to return the current classes inverse covariance matrixes.
133  \return true if ok, false on errors.
134  */
135  bool getInverseCovMatrixes( std::vector< boost::numeric::ublas::matrix< double > >& invCovMatrixes ) const;
136 
137  /*!
138  \brief Get the current classes means.
139  \param classesMeans A vector to return the current classes means.
140  \return true if ok, false on errors.
141  */
142  bool getMeans( std::vector< std::vector< double > >& classesMeans ) const;
143 
144  /*!
145  \brief Get the current classes labels.
146  \param classesMeans A vector to return the current classes labels.
147  \return true if ok, false on errors.
148  */
149  bool getLables( std::vector<unsigned int>& classLabels ) const;
150 
151  protected:
152 
153  bool m_isInitialized; //!< True if this instance is initialized.
154  Parameters m_parameters; //!< Internal execution parameters.
155  std::vector< std::vector< double > > m_classesMeans; //!< Classes means;
156  std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceMatrixes; //!< Classes covariance matrixes.
157  std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceInvMatrixes; //!< Classes covariance inverse matrixes.
158  std::vector<unsigned int> m_classLabels; //!< class labels
159  std::vector< double > m_classesOptizedMaxLikelihoodDiscriminantTerm; //!< An optimized portion of the MaxLikelihood discriminant function.
160 
161  /*! \brief Reset this instance to its initial state */
162  void reset();
163 
164  };
165  } // end namespace cl
166 } // end namespace te
167 
168 #endif // __TERRALIB_CLASSIFICATION_INTERNAL_MAXLIKELIHOOD_H
std::vector< std::vector< double > > m_classesMeans
Classes means;.
Parameters m_parameters
Internal execution parameters.
Configuration flags for the Terrralib Classification module.
std::vector< double > m_classesOptizedMaxLikelihoodDiscriminantTerm
An optimized portion of the MaxLikelihood discriminant function.
std::vector< unsigned int > m_classLabels
class labels
Classifiers input data adaptor.
Definition: Adaptors.h:45
Classifiers output data adaptor.
Definition: Adaptors.h:79
TerraLib.
Classifier Parameters.
Definition: MaxLikelihood.h:63
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
std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceMatrixes
Classes covariance matrixes.
An exception class for the Classification module.
A maximum likelihood estimation strategy for classification (a.k.a. MaxVer in portuguese).
Definition: MaxLikelihood.h:55
bool m_isInitialized
True if this instance is initialized.
Classifiers adaptors.
std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceInvMatrixes
Classes covariance inverse matrixes.