-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.cpp
38 lines (32 loc) · 848 Bytes
/
main.cpp
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
#include <iostream>
#include "k-means.h"
using namespace std;
int main()
{
double data[] = {
0.0, 0.2, 0.4,
0.3, 0.2, 0.4,
0.4, 0.2, 0.4,
0.5, 0.2, 0.4,
5.0, 5.2, 8.4,
6.0, 5.2, 7.4,
4.0, 5.2, 4.4,
10.3, 10.4, 10.5,
10.1, 10.6, 10.7,
11.3, 10.2, 10.9
};
const int size = 10; //Number of samples
const int dim = 3; //Dimension of feature
const int cluster_num = 4; //Cluster number
KMeans* kmeans = new KMeans(dim,cluster_num);
int* labels = new int[size];
kmeans->SetInitMode(KMeans::InitUniform);
kmeans->Cluster(data,size,labels);
for(int i = 0; i < size; ++i)
{
printf("%f, %f, %f belongs to %d cluster\n", data[i*dim+0], data[i*dim+1], data[i*dim+2], labels[i]);
}
delete []labels;
delete kmeans;
return 0;
}