ANIMA  4.0
animaSpectralClusteringFilter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 #include <vnl/vnl_matrix.h>
5 #include <vnl/vnl_diag_matrix.h>
6 
7 #include <itkSymmetricEigenAnalysis.h>
8 
10 
11 namespace anima
12 {
13 
19 template <class ScalarType>
21 {
22 public:
23  typedef std::vector <ScalarType> VectorType;
24  typedef vnl_matrix <ScalarType> MatrixType;
25 
28  typedef itk::SymmetricEigenAnalysis <MatrixType, vnl_diag_matrix<ScalarType>, MatrixType> EigenAnalysisType;
29 
32 
34  void SetInputData(MatrixType &data);
35  void SetDataWeights(VectorType &val) {m_DataWeights = val;}
36  void SetNbClass(unsigned int nbC) {m_NbClass = nbC;}
37  void SetSigmaWeighting(double sigma) {m_SigmaWeighting = sigma;}
38 
39  // Parameters for fuzzy c-means
40  void SetMaxIterations(unsigned int mIt) {m_MaxIterations = mIt;}
41  void SetRelStopCriterion(double rC) {m_RelStopCriterion = rC;}
42  void SetMValue(double mV) {m_MValue = mV;}
43 
44  void SetCMeansAverageType(CMeansAverageType val) {m_CMeansAverageType = val;}
45 
47  void Update();
48 
49  double ComputeClustersSpreading();
51 
52  void SetVerbose(bool verb) {m_Verbose = verb;}
53 
54  VectorType &GetSpectralVector(unsigned int i) {return m_SpectralVectors[i];}
55  VectorType &GetClassesMembership(unsigned int i) {return m_ClassesMembership[i];}
56  VectorType &GetCentroid(unsigned int i) {return m_Centroids[i];}
57  std::vector <unsigned int> GetClassMembers(unsigned int i);
58 
59 private:
60  std::vector <VectorType> m_ClassesMembership;
61  std::vector <VectorType> m_Centroids;
62  std::vector <VectorType> m_SpectralVectors;
63  MatrixType m_InputData;
64  VectorType m_DataWeights;
65 
66  unsigned int m_NbClass;
67 
68  CMeansAverageType m_CMeansAverageType;
69  CMeansFilterType m_MainFilter;
70 
71  bool m_Verbose;
72 
73  unsigned int m_MaxIterations;
74  double m_RelStopCriterion;
75  double m_MValue;
76 
77  double m_SigmaWeighting;
78 
79  // Internal data
80  MatrixType m_WMatrix;
81  std::vector <double> m_DValues;
82 
83  EigenAnalysisType m_EigenAnalyzer;
84  vnl_diag_matrix<ScalarType> m_EigVals;
85  MatrixType m_EigVecs;
86  VectorType m_WorkVec;
87 };
88 
89 } // end namespace anima
90 
Provides an implementation of spectral clustering, as proposed in A.Y. Ng, M.I. Jordan and Y...
void SetCMeansAverageType(CMeansAverageType val)
void SetInputData(MatrixType &data)
Input data: matrix of squared distances.
VectorType & GetClassesMembership(unsigned int i)
anima::FuzzyCMeansFilter< ScalarType > CMeansFilterType
itk::SymmetricEigenAnalysis< MatrixType, vnl_diag_matrix< ScalarType >, MatrixType > EigenAnalysisType
VectorType & GetCentroid(unsigned int i)
VectorType & GetSpectralVector(unsigned int i)
CMeansFilterType::CentroidAverageType CMeansAverageType
std::vector< unsigned int > GetClassMembers(unsigned int i)