MNE-CPP  beta 1.0
kmeans.h
Go to the documentation of this file.
1 //=============================================================================================================
36 #ifndef KMEANS_H
37 #define KMEANS_H
38 
39 //*************************************************************************************************************
40 //=============================================================================================================
41 // INCLUDES
42 //=============================================================================================================
43 
44 #include "utils_global.h"
45 
46 
47 //*************************************************************************************************************
48 //=============================================================================================================
49 // Qt INCLUDES
50 //=============================================================================================================
51 
52 #include <QString>
53 #include <QSharedPointer>
54 
55 
56 //*************************************************************************************************************
57 //=============================================================================================================
58 // Eigen INCLUDES
59 //=============================================================================================================
60 
61 #include <Eigen/Core>
62 
63 
64 //*************************************************************************************************************
65 //=============================================================================================================
66 // DEFINE NAMESPACE MNELIB
67 //=============================================================================================================
68 
69 namespace UTILSLIB
70 {
71 
72 
73 //*************************************************************************************************************
74 //=============================================================================================================
75 // USED NAMESPACES
76 //=============================================================================================================
77 
78 using namespace Eigen;
79 
80 //=============================================================================================================
87 {
88 public:
89  typedef QSharedPointer<KMeans> SPtr;
90  typedef QSharedPointer<const KMeans> ConstSPtr;
92  //distance {'sqeuclidean','cityblock','cosine','correlation','hamming'};
93  //startNames = {'uniform','sample','cluster'};
94  //emptyactNames = {'error','drop','singleton'};
95 
96  //=========================================================================================================
107  explicit KMeans(QString distance = QString("sqeuclidean") , QString start = QString("sample"), qint32 replicates = 1, QString emptyact = QString("error"), bool online = true, qint32 maxit = 100);
108 
109  //=========================================================================================================
120  bool calculate( MatrixXd X, qint32 kClusters, VectorXi& idx, MatrixXd& C, VectorXd& sumD, MatrixXd& D);
121 
122 
123 private:
124  //=========================================================================================================
133  MatrixXd distfun(const MatrixXd& X, MatrixXd& C);//, qint32 iter);
134 
135  //=========================================================================================================
145  bool batchUpdate(const MatrixXd& X, MatrixXd& C, VectorXi& idx);
146 
147  //=========================================================================================================
157  void gcentroids(const MatrixXd& X, const VectorXi& index, const VectorXi& clusts,
158  MatrixXd& centroids, VectorXi& counts);
159 
160  //=========================================================================================================
170  bool onlineUpdate(const MatrixXd& X, MatrixXd& C, VectorXi& idx);
171 
172 
173  //=========================================================================================================
182  double unifrnd(double a, double b);
183 
184 
185  QString m_sDistance;
186  QString m_sStart;
187  qint32 m_iReps;
188  QString m_sEmptyact;
189  qint32 m_iMaxit;
190  bool m_bOnline;
192  qint32 emptyErrCnt;
194  qint32 iter;
195  qint32 k;
196  qint32 n;
197  qint32 p;
199  MatrixXd Del;
200  VectorXd d;
201  VectorXi m;
203  double totsumD;
205  double prevtotsumD;
207  VectorXi previdx;
209 };
210 
211 } // NAMESPACE
212 
213 #endif // KMEANS_H
#define UTILSSHARED_EXPORT
Definition: utils_global.h:57
utils library export/import macros.
QSharedPointer< const KMeans > ConstSPtr
Definition: kmeans.h:90
K-Means Clustering.
Definition: kmeans.h:86
QSharedPointer< KMeans > SPtr
Definition: kmeans.h:89