File: ClusteringOutputEvaluator.cxx

package info (click to toggle)
insighttoolkit 3.20.1%2Bgit20120521-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 80,652 kB
  • sloc: cpp: 458,133; ansic: 196,223; fortran: 28,000; python: 3,839; tcl: 1,811; sh: 1,184; java: 583; makefile: 430; csh: 220; perl: 193; xml: 20
file content (110 lines) | stat: -rw-r--r-- 2,994 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    ClusteringOutputEvaluator.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "ClusteringOutputEvaluator.h"

ClusteringOutputEvaluator
::ClusteringOutputEvaluator()
{
  m_Truth = 0 ;
  m_NumberOfClasses = 0 ;
}

ClusteringOutputEvaluator 
::~ClusteringOutputEvaluator()
{
}

void
ClusteringOutputEvaluator 
::SetTruth(EstimatedClassLabelsType* classLabels)
{
  m_Truth = classLabels ;
}

void
ClusteringOutputEvaluator 
::SetClusteringResult(EstimatedClassLabelsType* classLabels)
{
  m_Estimates = classLabels ;
}

void
ClusteringOutputEvaluator 
::SetUniqueClassLabels(const std::vector< unsigned int >& classLabels)
{
  m_ClassLabels = classLabels ;
  m_NumberOfClasses = m_ClassLabels.size() ;
//   m_Sizes.resize(m_NumberOfClasses) ;
//   m_NumberOfMatches.resize(m_NumberOfClasses) ;
//   m_InclusionErrors.resize(m_NumberOfClasses) ;
//   m_ExclusionErrors.resize(m_NumberOfClasses) ;
  m_ClassificationMatrix.resize(m_NumberOfClasses) ;
  for ( int i = 0 ; i < m_NumberOfClasses ; i++ )
    {
      m_ClassificationMatrix[i].resize(m_NumberOfClasses) ;
    }
}

unsigned int
ClusteringOutputEvaluator 
::GetClassIndex(const unsigned int classLabel) const
{
  for ( unsigned int i = 0 ; i < m_NumberOfClasses ; i++ )
    {
      if ( classLabel == m_ClassLabels[i])
        {
          return i ;
        }
    }
 
 return 0 ;
}

unsigned int
ClusteringOutputEvaluator
::GetMappedClassIndex(const unsigned int clusterLabel) const
{
  return this->GetClassIndex(m_ClusterMap[clusterLabel]) ;
}

void
ClusteringOutputEvaluator 
::GenerateData()
{
  for ( int i = 0 ; i < m_NumberOfClasses ; i++ )
    {
      std::fill(m_ClassificationMatrix[i].begin(), 
                m_ClassificationMatrix[i].end(), 0) ;
    }

  EstimatedClassLabelsType::iterator t_iter = m_Truth->begin() ;
  unsigned int trueLabel ;
  unsigned int estimatedLabel ;
  while ( t_iter != m_Truth->end() )
    {
//       std::cout << "DEBUG: id = " << (*t_iter).first 
//                 << " true label = " << (*t_iter).second
//                 << " estimated cluster = " << (*(m_Estimates->find((*t_iter).first))).second 
//                 << std::endl ;
      trueLabel = this->GetClassIndex((*t_iter).second) ;
      estimatedLabel = 
        this->GetMappedClassIndex((*(m_Estimates->find((*t_iter).first))).second) ;
      m_ClassificationMatrix[estimatedLabel][trueLabel] += 1 ;
      ++t_iter ;
    }
}