Loading...
Searching...
No Matches
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
44namespace 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
70
72
73 //overload
74 const Parameters& operator=(const Parameters& params);
75
76 //overload
77 void reset() ;
78
79 //overload
80 AbstractParameters* clone() const;
81 };
82
83 /*!
84 \class Trained model parameters
85 \brief Trained model parameters
86 */
88 {
89 public:
90
91 std::vector<unsigned int> m_classLabels; //!< class labels
92 std::vector< std::vector< double > > m_classesMeans; //!< Classes means;
93 std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceMatrixes; //!< Classes covariance matrixes.
94
96
98
99 //overload
101
102 //overload
103 void reset() ;
104
105 //overload
106 AbstractParameters* clone() const;
107 };
108
109 public:
110
112
114
115 /*!
116 \brief Initialize this classifier instance with new parameters (further training is required).
117 \param params New initialization parameters.
118 */
119 bool initialize(const Parameters& params) ;
120
121 /*!
122 \brief Initialize this classifier instance with new model parameters (further training not required).
123 \param params New initialization parameters.
124 \param modelParams New model parameters.
125 */
126 bool initialize(const Parameters& params, const ModelParameters& modelParams) ;
127
128 /*!
129 \brief Train this classifier instance using the initialization parameters and the suppied train data.
130 \param samples Train data samples.
131 \param attributesIndices The attributes indexes to processe from the iterated train data.
132 \param sampleLabels The sample lables for each iterated train data element.
133 \param enableProgressInterface Enable/disable the use of a proress interfece.
134 */
135 bool train( const InputAdaptor< double >& samples,
136 const std::vector<unsigned int>& attributesIndices,
137 const std::vector<unsigned int>& sampleLabels,
138 const bool enableProgressInterface) ;
139
140 /*!
141 \brief Classify an input iterated data and save the result on the output iterated data.
142 \param input Input data to be classified.
143 \param attributesIndices The attributes indexes to processe from the iterated train data.
144 \param inputNoDataValues A vector of no-data values for each attribute dimension or an empty vector if no-data values are not used.
145 \param output Output classified data.
146 \param outputIndex The output attribute index.
147 \param outputNoDataValue A output label value to use when dealing with input no-data.
148 \param enableProgressInterface Enable/disable the use of a proress interfece.
149 */
151 const std::vector<unsigned int>& attributesIndices,
152 const std::vector< double >& inputNoDataValues,
154 const unsigned int outputIndex,
155 const double outputNoDataValue,
156 const bool enableProgressInterface) ;
157
158 /*!
159 \brief Returns the current model parameters.
160 \return Returns the current model parameters.
161 */
163
164 protected:
165
166 bool m_isInitialized; //!< True if this instance is initialized.
167 Parameters m_parameters; //!< Internal execution parameters.
168 ModelParameters m_modelParameters; //!< Trained model parameters
169 std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceInvMatrixes; //!< Classes covariance inverse matrixes.
170 std::vector< double > m_classesOptizedMAPDiscriminantTerm; //!< An optimized portion of the MAP discriminant function.
171
172 /*! \brief Reset this instance to its initial state */
173 void reset();
174
175 /*!
176 \brief Calculate priori probabilities by pre-classifying the input data.
177 \param input Input data to be classified.
178 \param attributesIndices The attributes indexes to processe from the iterated train data.
179 \param prioriProbs Calculated priori-probabilities.
180 */
182 const std::vector<unsigned int>& attributesIndices,
183 std::vector< double >& prioriProbs ) const;
184 };
185 } // end namespace cl
186} // end namespace te
187
188#endif // __TERRALIB_CLASSIFICATION_INTERNAL_MAP_H
Classifiers adaptors.
Classifiers input data adaptor.
Definition: Adaptors.h:46
AbstractParameters * clone() const
Create a clone copy of this instance.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
std::vector< std::vector< double > > m_classesMeans
Classes means;.
Definition: MAP.h:92
const ModelParameters & operator=(const ModelParameters &params)
std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceMatrixes
Classes covariance matrixes.
Definition: MAP.h:93
std::vector< unsigned int > m_classLabels
class labels
Definition: MAP.h:91
Classifier Parameters.
Definition: MAP.h:63
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
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
const Parameters & operator=(const Parameters &params)
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
AbstractParameters * clone() const
Create a clone copy of this instance.
MAP strategy for classification.
Definition: MAP.h:55
bool initialize(const Parameters &params)
Initialize this classifier instance with new parameters (further training is required).
bool classify(const InputAdaptor< double > &input, const std::vector< unsigned int > &attributesIndices, const std::vector< double > &inputNoDataValues, OutputAdaptor< unsigned int > &output, const unsigned int outputIndex, const double outputNoDataValue, const bool enableProgressInterface)
Classify an input iterated data and save the result on the output iterated data.
std::vector< boost::numeric::ublas::matrix< double > > m_classesCovarianceInvMatrixes
Classes covariance inverse matrixes.
Definition: MAP.h:169
bool getPrioriProbabilities(const InputAdaptor< double > &input, const std::vector< unsigned int > &attributesIndices, std::vector< double > &prioriProbs) const
Calculate priori probabilities by pre-classifying the input data.
bool m_isInitialized
True if this instance is initialized.
Definition: MAP.h:166
bool initialize(const Parameters &params, const ModelParameters &modelParams)
Initialize this classifier instance with new model parameters (further training not required).
std::vector< double > m_classesOptizedMAPDiscriminantTerm
An optimized portion of the MAP discriminant function.
Definition: MAP.h:170
ModelParameters m_modelParameters
Trained model parameters.
Definition: MAP.h:168
Parameters m_parameters
Internal execution parameters.
Definition: MAP.h:167
const ModelParameters & getModelParams()
Returns the current model parameters.
void reset()
Reset this instance to its initial state.
bool train(const InputAdaptor< double > &samples, const std::vector< unsigned int > &attributesIndices, const std::vector< unsigned int > &sampleLabels, const bool enableProgressInterface)
Train this classifier instance using the initialization parameters and the suppied train data.
Classifiers output data adaptor.
Definition: Adaptors.h:80
Abstract parameters base interface.
TerraLib.
#define TECLEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:102
Proxy configuration file for TerraView (see terraview_config.h).
An exception class for the XML module.