ClassifierMAPStrategy.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/rp/ClassifierMAPStrategy.h
22  \brief Maximum a posteriori probability strategy.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_CLASSIFIERMAPSTRATEGY_H
26 #define __TERRALIB_RP_INTERNAL_CLASSIFIERMAPSTRATEGY_H
27 
28 #include "ClassifierStrategy.h"
30 #include "../common/progress/TaskProgress.h"
31 #include "Config.h"
32 
33 #include <boost/numeric/ublas/matrix.hpp>
34 #include <boost/shared_ptr.hpp>
35 
36 #include <map>
37 #include <vector>
38 
39 namespace te
40 {
41  namespace rp
42  {
43  /*!
44  \class ClassifierMAPStrategy
45 
46  \brief Maximum a posteriori probability strategy.
47 
48  \ingroup rp_class
49  */
51  {
52  public:
53 
54  /*!
55  \class Parameters
56 
57  \brief Classifier Parameters
58  */
60  {
61  public:
62 
63  typedef unsigned int ClassIDT; //!< Class ID type definition (zero means invalid ID).
64 
65  typedef std::vector< double > ClassSampleT; //!< Class sample type definition.
66 
67  typedef std::vector< ClassSampleT > ClassSamplesContainerT; //!< Class samples container type definition.
68 
69  typedef std::map< ClassIDT, ClassSamplesContainerT > MClassesSamplesCT; //!< Multi-classes samples container type definition.
70 
71  typedef boost::shared_ptr<MClassesSamplesCT> MClassesSamplesCTPtr; //!< A shared pointer to a multi classes samples container type definition.
72 
73  MClassesSamplesCTPtr m_trainSamplesPtr; //!< A shared pointer to a always-valid structure where trainning samples are stored.
74 
75  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).
76 
77  unsigned int m_prioriCalcSampleStep; //!< A positive non-zero sample step used when calculating piori probabilities (default:2 - half of samples will be used);
78 
79  Parameters();
80 
81  ~Parameters();
82 
83  //overload
84  const Parameters& operator=(const Parameters& params);
85 
86  //overload
87  void reset() throw( te::rp::Exception );
88 
89  //overload
90  AbstractParameters* clone() const;
91  };
92 
94 
96 
97  //overload
98  bool initialize(ClassifierStrategyParameters const* const strategyParams) throw(te::rp::Exception);
99 
100  //overload
101  bool execute(const te::rst::Raster& inputRaster, const std::vector<unsigned int>& inputRasterBands,
102  const std::vector<te::gm::Polygon*>& inputPolygons, te::rst::Raster& outputRaster,
103  const unsigned int outputRasterBand, const bool enableProgressInterface) throw(te::rp::Exception);
104 
105  // overload
106  std::vector< int > getOutputDataTypes() const;
107 
108  unsigned int getOutputNumberBands(void);
109 
110  protected :
111 
112  bool m_isInitialized; //!< Is this instance initialized?
113 
114  ClassifierMAPStrategy::Parameters m_initParams; //!< Initialization parameters.
115 
116  std::vector< Parameters::ClassIDT > m_classesIndex2ID; //!< An class index ordered vector of classes IDs;
117 
118  std::vector< std::vector< double > > m_classesMeans; //!< Classes means;
119 
120  std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceMatrixes; //!< Classes covariance matrixes.
121 
122  std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceInvMatrixes; //!< Classes covariance inverse matrixes.
123 
124  std::vector< double > m_classesOptizedMAPDiscriminantTerm; //!< An optimized portion of the MAP discriminant function.
125 
126  /*!
127  \brief Calcule of priori probabilities following the current internal state.
128  \param inputRaster Input raster.
129  \param inputRasterBands Input raster bands.
130  \param progressPtr A pointer to a progress interface, or a null pointer if no progress must be updated.
131  \param prioriProbabilities The calculated probabilities.
132  \return true if ok, false on errors.
133  */
134  bool getPrioriProbabilities(
135  const te::rst::Raster& inputRaster,
136  const std::vector<unsigned int>& inputRasterBands,
137  te::common::TaskProgress * const progressPtr,
138  std::vector< double >& prioriProbabilities ) const;
139  };
140 
141  /*!
142  \class ClassifierMAPStrategyFactory
143 
144  \brief Maximum a posteriori probability strategy factory.
145 
146  \note Factory key: RegionGrowing
147  */
149  {
150  public:
151 
153 
155 
156  //overload
158  };
159 
160  } // end namespace rp
161 } // end namespace te
162 
163 #endif // __TERRALIB_RP_INTERNAL_CLASSIFIERMAPSTRATEGY_H
164 
MClassesSamplesCTPtr m_trainSamplesPtr
A shared pointer to a always-valid structure where trainning samples are stored.
Maximum a posteriori probability strategy factory.
boost::shared_ptr< MClassesSamplesCT > MClassesSamplesCTPtr
A shared pointer to a multi classes samples container type definition.
unsigned int m_prioriCalcSampleStep
A positive non-zero sample step used when calculating piori probabilities (default:2 - half of sample...
Base exception class for plugin module.
Definition: Exception.h:42
unsigned int ClassIDT
Class ID type definition (zero means invalid ID).
std::vector< double > m_prioriProbs
Priori probabilities, one for each class. Values from 0 to 1 (use an empty vector to allow internal c...
Raster classifier strategy factory base class.
std::map< ClassIDT, ClassSamplesContainerT > MClassesSamplesCT
Multi-classes samples container type definition.
std::vector< double > ClassSampleT
Class sample type definition.
URI C++ Library.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Maximum a posteriori probability strategy.
Raster classifier strategy factory base class.
Configuration flags for the Raster Processing module of TerraLib.
Raster classifier strategy base class.
Raster classifier strategy base class.
std::vector< ClassSampleT > ClassSamplesContainerT
Class samples container type definition.