-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImplementation.hpp
More file actions
152 lines (126 loc) · 3.83 KB
/
Implementation.hpp
File metadata and controls
152 lines (126 loc) · 3.83 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <functional>
#include <cmath>
#include <memory>
#include <optional>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include <nmmintrin.h>
#include <immintrin.h>
#include <smmintrin.h>
/*------------------------------------------------------------------------------*/
/*
Point class
a simple 2 dimensional point (x,y) with simple functionality to calculate euclidean
distance to another Point
*/
class Point {
private:
public:
/*co-ordinates x & y - public for testing accessibility*/
double x, y;
/* Constructor
initializes x & y
*/
Point(double x, double y): x(x), y(y) {};
/* euclideanDistance(Point other)
calculates euclidean distance to another point
- returns distance
*/
double euclideanDistance(Point other);
/* toString()
string parsing of point visualization
*/
std::string toString() {return std::to_string(x) + " " + std::to_string(y);}
};
/*------------------------------------------------------------------------------*/
/*
Centroid class
a simple 2 dimensional point (x,y) with simple functionality to calculate euclidean
distance to another Point
*/
class Centroid : public Point {
private:
/* id
centroids are identified by id
NB - only relevant for benchmarking in emulating true data stucture of
flink centroid
*/
int id;
public:
/* Constructor
initializes id, x & y
*/
Centroid(int id, double x, double y): Point(x, y), id(id) {};
/* getID()
returns id
*/
int getID() {return id;};
};
/*------------------------------------------------------------------------------*/
/*
KMeansData class
class responsible for initializing and offering (random) data of different forms
*/
class KMeansData {
/* num_data_points
number of data points for a dataset. KMeansData set can store an array and
vector representation
*/
int num_arr_points = 0;
int num_vec_points = 0;
/* centroids
array of centroid pointers
*/
Centroid** centroids;
/* centroids_vec
standard library vector of centroids
*/
std::vector<Centroid> centroids_vec = {};
public:
/* Constructor
set num_data_points attributes (optional)
*/
KMeansData() {};
// KMeansData(int num_data_points): num_data_points(num_data_points) {};
/* setRandomCentroidsArray()
internal function allocates num_centroids amount of Centroid objects on
heap, with random coordinates between min-max. Pointers to Centroids stored
in centroids
*/
void setRandomCentroidsArray(int num_centroids, double min, double max, bool verbose = false);
/* setRandomCentroidsVector()
internal function creates num_centroids amount of Cantroids, with random
coordinates between min-max. Centroids pushed in centroids_vec
*/
void setRandomCentroidsVector(int num_centroids, double min, double max, bool verbose = false);
/* getCentroidsArray()
getter function for centroids. Returns pointer to first Centroid pointer
on heap
*/
Centroid** getCentroidsArray() {return centroids;};
/* getCentroidsVector()
getter function for centroids_vec. Returns Centroid vector
*/
std::vector<Centroid> getCentroidsVector() {return centroids_vec;};
/* getArrayLength()/getVectorLength()
getter function for dataset lengths
*/
int getArrayLength() {return num_arr_points;};
int getVectorLength() {return num_vec_points;};
~KMeansData();
};
/*------------------------------------------------------------------------------*/
/*
Helper Functions for Benchmark.cpp
*/
/* randNum()
returns random double betwee min & max
*/
double randNum(double min, double max);
/* getPoint()
initializes a point with random x/y coordinates between min/max
*/
Point getPoint(double min, double max, bool verbose = false);