OTB  9.0.0
Orfeo Toolbox
otbConfusionMatrixToMassOfBelief.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbConfusionMatrixToMassOfBelief_hxx
22 #define otbConfusionMatrixToMassOfBelief_hxx
23 
25 
26 namespace otb
27 {
28 
29 template <class TConfusionMatrix, class TLabel>
31 {
32  this->SetNumberOfRequiredInputs(2);
33  this->SetNumberOfRequiredOutputs(1);
34  this->m_ConfMatMeasurements = ConfusionMatrixMeasurementsType::New();
35  this->m_DefinitionMethod = this->PRECISION;
36 }
37 
38 template <class TConfusionMatrix, class TLabel>
40 {
41  this->GenerateData();
42 }
43 
44 template <class TConfusionMatrix, class TLabel>
46 {
47  this->m_ConfMatMeasurements->SetConfusionMatrix(m_ConfusionMatrix);
48  this->m_ConfMatMeasurements->Compute();
49 
50  typename MapOfIndicesType::iterator itMapOfIndices;
51 
52  MassType currentMass = 0.;
53  this->m_MapMassOfBelief.clear();
54  for (itMapOfIndices = m_MapOfIndices.begin(); itMapOfIndices != m_MapOfIndices.end(); ++itMapOfIndices)
55  {
56  switch (m_DefinitionMethod)
57  {
58  case PRECISION:
59  // Masses of Belief = Precision Rate of each label (TP / [TP + FP])
60  currentMass = m_ConfMatMeasurements->GetPrecisions()[itMapOfIndices->first];
61  break;
62  case RECALL:
63  // Masses of Belief = Recall Rate of each label (TP / [TP + FN])
64  currentMass = m_ConfMatMeasurements->GetRecalls()[itMapOfIndices->first];
65  break;
66  case ACCURACY:
67  // Masses of Belief = Overall Accuracy of the confusion matrix (SUM[TP] / nbSamples)
68  currentMass = m_ConfMatMeasurements->GetOverallAccuracy();
69  break;
70  case KAPPA:
71  // Masses of Belief = Kappa Index of the confusion matrix
72  currentMass = m_ConfMatMeasurements->GetKappaIndex();
73  break;
74 
75  default:
76  // Masses of Belief = Precision Rate of each label (TP / [TP + FP]
77  currentMass = m_ConfMatMeasurements->GetPrecisions()[itMapOfIndices->first];
78  break;
79  } // END switch (m_DefinitionMethod)
80 
81  this->m_MapMassOfBelief[itMapOfIndices->second] = currentMass;
82  }
83 }
84 } // end namespace otb
85 
86 #endif
otb::ConfusionMatrixToMassOfBelief::MassType
double MassType
Definition: otbConfusionMatrixToMassOfBelief.h:82
otbConfusionMatrixToMassOfBelief.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ConfusionMatrixToMassOfBelief::Update
void Update() override
Definition: otbConfusionMatrixToMassOfBelief.hxx:39
otb::ConfusionMatrixToMassOfBelief::ConfusionMatrixToMassOfBelief
ConfusionMatrixToMassOfBelief()
Definition: otbConfusionMatrixToMassOfBelief.hxx:30
otb::ConfusionMatrixToMassOfBelief::GenerateData
void GenerateData(void) override
Definition: otbConfusionMatrixToMassOfBelief.hxx:45