All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ClassifierMAPStrategy.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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 
35 #include <map>
36 #include <vector>
37 
38 namespace te
39 {
40  namespace rp
41  {
42  /*!
43  \class ClassifierMAPStrategy
44 
45  \brief Maximum a posteriori probability strategy.
46  */
48  {
49  public:
50 
51  /*!
52  \class Parameters
53 
54  \brief Classifier Parameters
55  */
57  {
58  public:
59 
60  typedef unsigned int ClassIDT; //!< Class ID type definition (zero means invalid ID).
61 
62  typedef std::vector< double > ClassSampleT; //!< Class sample type definition.
63 
64  typedef std::vector< ClassSampleT > ClassSamplesContainerT; //!< Class samples container type definition.
65 
66  typedef std::map< ClassIDT, ClassSamplesContainerT > MClassesSamplesCT; //!< Multi-classes samples container type definition.
67 
68  MClassesSamplesCT const* m_trainSamplesPtr; //!< A pointer to a always-valid structure where trainning samples are stored.
69 
70  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).
71 
72  unsigned int m_prioriCalcSampleStep; //!< A positive non-zero sample step used when calculating piori probabilities (default:2 - half of samples will be used);
73 
74  Parameters();
75 
76  ~Parameters();
77 
78  //overload
79  const Parameters& operator=(const Parameters& params);
80 
81  //overload
82  void reset() throw( te::rp::Exception );
83 
84  //overload
85  AbstractParameters* clone() const;
86  };
87 
89 
91 
92  //overload
93  bool initialize(StrategyParameters const* const strategyParams) throw(te::rp::Exception);
94 
95  //overload
96  bool execute(const te::rst::Raster& inputRaster, const std::vector<unsigned int>& inputRasterBands,
97  const std::vector<te::gm::Polygon*>& inputPolygons, te::rst::Raster& outputRaster,
98  const unsigned int outputRasterBand, const bool enableProgressInterface) throw(te::rp::Exception);
99 
100  protected :
101 
102  bool m_isInitialized; //!< Is this instance initialized?
103 
104  ClassifierMAPStrategy::Parameters m_initParams; //!< Initialization parameters.
105 
106  std::vector< Parameters::ClassIDT > m_classesIndex2ID; //!< An class index ordered vector of classes IDs;
107 
108  std::vector< std::vector< double > > m_classesMeans; //!< Classes means;
109 
110  std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceMatrixes; //!< Classes covariance matrixes.
111 
112  std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceInvMatrixes; //!< Classes covariance inverse matrixes.
113 
114  std::vector< double > m_classesOptizedMAPDiscriminantTerm; //!< An optimized portion of the MAP discriminant function.
115 
116  /*!
117  \brief Calcule of priori probabilities following the current internal state.
118  \param inputRaster Input raster.
119  \param inputRasterBands Input raster bands.
120  \param progressPtr A pointer to a progress interface, or a null pointer if no progress must be updated.
121  \param prioriProbabilities The calculated probabilities.
122  \return true if ok, false on errors.
123  */
124  bool getPrioriProbabilities(
125  const te::rst::Raster& inputRaster,
126  const std::vector<unsigned int>& inputRasterBands,
127  te::common::TaskProgress * const progressPtr,
128  std::vector< double >& prioriProbabilities ) const;
129  };
130 
131  /*!
132  \class ClassifierMAPStrategyFactory
133 
134  \brief Maximum a posteriori probability strategy factory.
135 
136  \note Factory key: RegionGrowing
137  */
139  {
140  public:
141 
143 
145 
146  //overload
148  };
149 
150  } // end namespace rp
151 } // end namespace te
152 
153 #endif // __TERRALIB_RP_INTERNAL_CLASSIFIERMAPSTRATEGY_H
154 
unsigned int m_prioriCalcSampleStep
A positive non-zero sample step used when calculating piori probabilities (default:2 - half of sample...
Raster strategy parameters base class.
std::vector< double > ClassSampleT
Class sample type definition.
std::map< ClassIDT, ClassSamplesContainerT > MClassesSamplesCT
Multi-classes samples container type definition.
Maximum a posteriori probability strategy factory.
Raster classifier strategy base class.
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.
Configuration flags for the Raster Processing module of TerraLib.
Maximum a posteriori probability strategy.
std::vector< ClassSampleT > ClassSamplesContainerT
Class samples container type definition.
MClassesSamplesCT const * m_trainSamplesPtr
A pointer to a always-valid structure where trainning samples are stored.
Raster classifier strategy base class.
Raster classifier strategy factory base class.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:91