-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathelkan_kmeans.h
39 lines (29 loc) · 1.18 KB
/
elkan_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
#ifndef ELKAN_KMEANS_H
#define ELKAN_KMEANS_H
/* Authors: Greg Hamerly and Jonathan Drake
* Feedback: hamerly@cs.baylor.edu
* See: http://cs.baylor.edu/~hamerly/software/kmeans.php
* Copyright 2014
*
* Elkan's k-means algorithm that uses k lower bounds per point to prune
* distance calculations.
*/
#include "triangle_inequality_base_kmeans.h"
class ElkanKmeans : public TriangleInequalityBaseKmeans {
public:
ElkanKmeans() : centerCenterDistDiv2(NULL) {}
virtual ~ElkanKmeans() { free(); }
virtual void free();
virtual void initialize(Dataset const *aX, unsigned short aK, unsigned short *initialAssignment, int aNumThreads);
virtual std::string getName() const { return "elkan"; }
protected:
virtual int runThread(int threadId, int maxIterations);
// Update the distances between each pair of centers.
void update_center_dists(int threadId);
// Update the upper and lower bounds for the range of points given.
void update_bounds(int startNdx, int endNdx);
// Keep track of the distance (divided by 2) between each pair of
// points.
double *centerCenterDistDiv2;
};
#endif