forked from mattnedrich/MeanShift_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp_test.cpp
More file actions
57 lines (51 loc) · 1.46 KB
/
cpp_test.cpp
File metadata and controls
57 lines (51 loc) · 1.46 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
57
#include <stdio.h>
#include <stdlib.h>
#include "MeanShift.h"
using namespace std;
vector<vector<double> > load_points(const char *filename) {
vector<vector<double> > points;
FILE *fp = fopen(filename, "r");
char line[50];
while (fgets(line, sizeof(line), fp) != NULL) {
double x, y;
char *x_str = line;
char *y_str = line;
while (*y_str != '\0') {
if (*y_str == ',') {
*y_str++ = 0;
x = atof(x_str);
y = atof(y_str);
vector<double> point;
point.push_back(x);
point.push_back(y);
points.push_back(point);
break;
}
++y_str;
}
}
fclose(fp);
return points;
}
void print_points(vector<vector<double> > points){
for(int i=0; i<points.size(); i++){
for(int dim = 0; dim<points[i].size(); dim++) {
printf("%f ", points[i][dim]);
}
printf("\n");
}
}
int main(int argc, char **argv)
{
MeanShift *msp = new MeanShift();
double kernel_bandwidth = 3;
vector<vector<double> > points = load_points("test.csv");
vector<vector<double> > shifted_points = msp->cluster(points, kernel_bandwidth);
for(int i=0; i<shifted_points.size(); i++){
for(int dim = 0; dim<shifted_points[i].size(); dim++) {
printf("%f ", shifted_points[i][dim]);
}
printf("\n");
}
return 0;
}