KMeans clustering, partitions the data into k (a-priori specified) clusters.
It minimizes
where are the cluster centers and are the index sets of the clusters.
Beware that this algorithm obtains only a local optimum.
cf. http://en.wikipedia.org/wiki/K-means_algorithm
Definition at line 39 of file KMeans.h.
Public Member Functions | |
CKMeans () | |
CKMeans (int32_t k, CDistance *d) | |
virtual | ~CKMeans () |
virtual EClassifierType | get_classifier_type () |
virtual bool | train (CFeatures *data=NULL) |
virtual bool | load (FILE *srcfile) |
virtual bool | save (FILE *dstfile) |
void | set_k (int32_t p_k) |
int32_t | get_k () |
void | set_max_iter (int32_t iter) |
float64_t | get_max_iter () |
void | get_radi (float64_t *&radi, int32_t &num) |
void | get_centers (float64_t *¢ers, int32_t &dim, int32_t &num) |
void | get_radiuses (float64_t **radii, int32_t *num) |
void | get_cluster_centers (float64_t **centers, int32_t *dim, int32_t *num) |
int32_t | get_dimensions () |
Protected Member Functions | |
void | clustknb (bool use_old_mus, float64_t *mus_start) |
virtual CLabels * | classify () |
virtual CLabels * | classify (CFeatures *data) |
virtual const char * | get_name () const |
Protected Attributes | |
int32_t | max_iter |
maximum number of iterations | |
int32_t | k |
the k parameter in KMeans | |
int32_t | dimensions |
number of dimensions | |
float64_t * | R |
radi of the clusters (size k) | |
float64_t * | mus |
centers of the clusters (size dimensions x k) |
CKMeans | ( | ) |
default constructor
Definition at line 29 of file KMeans.cpp.
~CKMeans | ( | ) | [virtual] |
Definition at line 42 of file KMeans.cpp.
virtual CLabels* classify | ( | ) | [protected, virtual] |
classify objects using the currently set features
Implements CDistanceMachine.
classify objects
data | (test)data to be classified |
Implements CDistanceMachine.
void clustknb | ( | bool | use_old_mus, | |
float64_t * | mus_start | |||
) | [protected] |
clustknb
use_old_mus | if old mus shall be used | |
mus_start | mus start |
replace rhs feature vectors
set rhs to mus_start
update rhs
Definition at line 133 of file KMeans.cpp.
void get_centers | ( | float64_t *& | centers, | |
int32_t & | dim, | |||
int32_t & | num | |||
) |
virtual EClassifierType get_classifier_type | ( | ) | [virtual] |
void get_cluster_centers | ( | float64_t ** | centers, | |
int32_t * | dim, | |||
int32_t * | num | |||
) |
int32_t get_dimensions | ( | ) |
float64_t get_max_iter | ( | ) |
virtual const char* get_name | ( | void | ) | const [protected, virtual] |
void get_radi | ( | float64_t *& | radi, | |
int32_t & | num | |||
) |
void get_radiuses | ( | float64_t ** | radii, | |
int32_t * | num | |||
) |
bool load | ( | FILE * | srcfile | ) | [virtual] |
load distance machine from file
srcfile | file to load from |
Reimplemented from CClassifier.
Definition at line 72 of file KMeans.cpp.
bool save | ( | FILE * | dstfile | ) | [virtual] |
save distance machine to file
dstfile | file to save to |
Reimplemented from CClassifier.
Definition at line 79 of file KMeans.cpp.
void set_max_iter | ( | int32_t | iter | ) |
bool train | ( | CFeatures * | data = NULL |
) | [virtual] |
train k-means
data | training data (parameter can be avoided if distance or kernel-based classifiers are used and distance/kernels are initialized with train data) |
Reimplemented from CClassifier.
Definition at line 48 of file KMeans.cpp.
int32_t dimensions [protected] |