-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkmeans.h
68 lines (62 loc) · 1.3 KB
/
kmeans.h
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
58
59
60
61
62
63
64
65
66
67
68
#pragma once
#include <iostream>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
/**
Created:2018-11-17, Updated:2018-11-17
Author: Siqing Ma
Version: V0.1T
**/
class Point
{
private:
int id_point, id_cluster;
vector<double> values;
int nd;
public:
Point(int id_point, vector<double>& values);
int getID();
void setID(int id);
void setCluster(int id_cluster);
int getCluster();
double getValue(int index);
int getDimension();
void setValue(int index, double value);
};
class Cluster
{
private:
int id_cluster;
vector<double> central_values;
map<int, Point> points;
public:
Cluster(int id_cluster, Point point);
void addPoint(Point point);
void removePoint(int id_point);
double getCentralValue(int index);
void setCentralValue(int index, double value);
map<int, Point> getPoints();
int getID();
int getSize();
};
class KMeans
{
private:
int nc, nd, np, max_iterations;
vector<Point> init_centres;
vector<Cluster> clusters;
vector<int> dependency;
// return ID of nearest center
int getNearestCentreId(Point point);
public:
KMeans(int nc, int np, int nd, int max_iterations, vector<Point> centers);
Cluster getCluster(int index);
vector<int> getDependency();
void run(vector<Point> & points);
};