-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (46 loc) · 1.69 KB
/
main.cpp
File metadata and controls
56 lines (46 loc) · 1.69 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/****************************************************
*
* Compile with:
* g++ -fopenmp main.cpp -o project_kmean
*
* Run with:
* ./project_kmean <input.csv> <kmean_variant>('kmean', 'kmedoids') <num_threads> <k> <initialization_alg>('random', 'kmeanpp')
*
*****************************************************/
#include "base_kmean.cpp"
#include "kmedoids.cpp"
int main(int argc, const char *argv[]) {
omp_set_dynamic(0);
int epochs = 10;
// parsing arguments
if (argc < 5) {
std::cerr << "usage: project_kmean <input.csv> <kmean_variant> <num_thread> <k> <initialization>" << std::endl;
exit(EXIT_FAILURE);
}
std::string fname = argv[1];
std::string clustering_variant = argv[2];
omp_set_num_threads(atoi(argv[3]));
int k = atoi(argv[4]);
std::vector<Point> (*init_centroids) (const std::vector<Point>&, int&) = (std::string(argv[5]) == "random") ? &initialize_centroids_randomly: &initialize_centroids_kmeanpp;
// load data
std::vector<Point> data = load_csv(fname);
std::vector<Point> centroids;
// start clustering
double tstart, tstop;
tstart = omp_get_wtime();
if (std::string(clustering_variant) == "kmean")
centroids = kMeansClustering(init_centroids, data, k, epochs);
else
centroids = kMedoidsClustering(init_centroids, data, k, epochs);
tstop = omp_get_wtime();
printf("Total execution time: %f\n", tstop - tstart);
double sil = compute_silhouette(data, centroids);
printf("Silhouette score: %f\n", sil);
for (auto& c:centroids) {
std::cout<<std::endl;
for (auto v: c.coordinates)
std::cout << v << " ";
}
std::cout<<std::endl;
return 0;
}