ANIMA  4.0
animaFuzzyCMeansFilter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 
5 namespace anima
6 {
7 
14 template <class ScalarType>
16 {
17 public:
18  typedef std::vector <ScalarType> VectorType;
19  typedef std::vector <VectorType> DataHolderType;
20 
22  {
23  Euclidean = 0,
26  };
27 
29  virtual ~FuzzyCMeansFilter() {}
30 
31  void SetInputData(DataHolderType &data);
32  void SetDataWeights(VectorType &val) {m_DataWeights = val;}
33  void SetNbClass(unsigned int nbC) {m_NbClass = nbC;}
34  void SetFlagSpectralClustering(bool flag) {m_SpectralClusterInit = flag;}
35  void SetMaxIterations(unsigned int mIt) {m_MaxIterations = mIt;}
36  void SetRelStopCriterion(double rC) {m_RelStopCriterion = rC;}
37  void SetMValue(double mV) {m_MValue = mV;}
38  void SetSphericalAverageType(CentroidAverageType spher) {m_SphericalAverageType = spher;}
39 
40  void ComputeCentroids();
41  void UpdateMemberships();
42 
44  void InitializeClassesMemberships(DataHolderType &classM);
45  void ResetClassesMemberships() {m_ClassesMembership.clear();}
46 
47  bool endConditionReached(DataHolderType &oldMemberships);
48  void SetVerbose(bool verb) {m_Verbose = verb;}
49 
50  void Update();
51 
52  VectorType &GetCentroid(unsigned int i) {return m_Centroids[i];}
53  VectorType &GetClassesMembership(unsigned int i) {return m_ClassesMembership[i];}
54 
55 private:
56  long double computeDistance(VectorType &vec1, VectorType &vec2);
57 
58  DataHolderType m_ClassesMembership;
59  DataHolderType m_Centroids;
60  DataHolderType m_InputData;
61  VectorType m_DataWeights;
62 
63  unsigned int m_NbClass, m_NbInputs;
64  unsigned int m_NDim;
65  unsigned int m_MaxIterations;
66 
67  bool m_Verbose;
68  bool m_SpectralClusterInit;
69 
70  CentroidAverageType m_SphericalAverageType;
71 
72  double m_RelStopCriterion;
73  double m_MValue;
74 
75  // Internal work values
76  std::vector <long double> m_DistancesPointsCentroids;
77  DataHolderType m_PowMemberships;
78  VectorType m_TmpVector;
79  VectorType m_TmpWeights;
80 
81  // Internal variable for faster pseudo-spherical average computation
82  VectorType m_WorkVector, m_WorkLogVector;
83 };
84 
85 } // end namespace anima
86 
std::vector< VectorType > DataHolderType
void InitializeClassesMemberships(DataHolderType &classM)
void SetFlagSpectralClustering(bool flag)
VectorType & GetClassesMembership(unsigned int i)
void SetInputData(DataHolderType &data)
std::vector< ScalarType > VectorType
bool endConditionReached(DataHolderType &oldMemberships)
void SetSphericalAverageType(CentroidAverageType spher)
void SetNbClass(unsigned int nbC)
void SetMaxIterations(unsigned int mIt)
VectorType & GetCentroid(unsigned int i)
void SetDataWeights(VectorType &val)