forked from linupa/GMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KMeans.h
54 lines (44 loc) · 901 Bytes
/
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
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <Eigen/Dense>
#include <Eigen/Eigenvalues>
using namespace std;
using Eigen::MatrixXd;
using Eigen::VectorXd;
using Eigen::VectorXcd;
using Eigen::MatrixXcd;
class Cluster_KMeans
{
public:
Cluster_KMeans(int dimension);
void update(void);
int dimension;
VectorXd mean;
VectorXd getMean();
MatrixXd getCov();
private:
MatrixXd cov_inv;
double sqrt_cov_det;
};
class KMeans
{
public:
KMeans(int n_clust, int dim);
~KMeans(void);
void reset(void);
void iterate(void);
void iterate(int times);
void converge(double threshold);
void setSamples(vector<VectorXd> *samples);
void setDefaultClusters();
void update(void);
vector<Cluster_KMeans> clusters;
vector<VectorXd> *points;
vector<int> classify;
private:
int n_cluster;
int dimension;
vector<Cluster_KMeans> default_clusters;
};