KMeans.h
1 /*
2  * Developing brain Region Annotation With Expectation-Maximization (Draw-EM)
3  *
4  * Copyright 2013-2016 Imperial College London
5  * Copyright 2013-2016 Antonios Makropoulos
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef _MIRTKKMEANS_H
21 #define _MIRTKKMEANS_H
22 
23 #include <math.h>
24 #include <stdlib.h>
25 #include <float.h>
26 #include <iostream>
27 #include <algorithm>
28 
29 using namespace std;
30 
31 class kmeans
32 {
33 
34 protected:
35  int k,iter;
36  double * centroid;
37  double * point;
38  int * pointcluster, * oldpointcluster;
39  int n;
40  bool converged;
41  double * bestcentroid;
42  int * bestpointcluster;
43  double bestsumdistances;
44  int *nb;
45 
46  void KMeansAssign();
47  void KMeansCluster();
48 
49 public:
50  //method to run
51  kmeans();
52 
53  kmeans(double *thepoints,int numpoints,int numclusters,int numiters=100,int replicates=10);
54  kmeans(double *thepoints,int numpoints,int numclusters,double* centroids_init,int numiters=100,int replicates=10);
55  double *getCentroids();
56  int *getPointClusters();
57 
58 };
59 
60 
61 
62 inline double * kmeans::getCentroids(){return bestcentroid;}
63 inline int * kmeans::getPointClusters(){return bestpointcluster;}
64 
65 
66 
67 
68 #endif
69 
70 
71 
72 
73 
74 
STL namespace.