CKMeans Class Reference


Detailed Description

KMeans clustering, partitions the data into k (a-priori specified) clusters.

It minimizes

\[ \sum_{i=1}^k\sum_{x_j\in S_i} (x_j-\mu_i)^2 \]

where $\mu_i$ are the cluster centers and $S_i,\;i=1,\dots,k$ 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 37 of file KMeans.h.

Inheritance diagram for CKMeans:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CKMeans ()
 CKMeans (int32_t k, CDistance *d)
virtual ~CKMeans ()
virtual EClassifierType get_classifier_type ()
virtual bool train ()
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 *&centers, 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 sqdist (float64_t *x, CSimpleFeatures< float64_t > *y, float64_t *z, int32_t n1, int32_t offs, int32_t n2, int32_t m)
void clustknb (bool use_old_mus, float64_t *mus_start)
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_tR
 radi of the clusters (size k)
float64_tmus
 centers of the clusters (size dimensions x k)

Constructor & Destructor Documentation

CKMeans::CKMeans (  ) 

default constructor

Definition at line 27 of file KMeans.cpp.

CKMeans::CKMeans ( int32_t  k,
CDistance d 
)

constructor

Parameters:
k parameter k
d distance

Definition at line 33 of file KMeans.cpp.

CKMeans::~CKMeans (  )  [virtual]

Definition at line 40 of file KMeans.cpp.


Member Function Documentation

void CKMeans::clustknb ( bool  use_old_mus,
float64_t mus_start 
) [protected]

clustknb

Parameters:
use_old_mus if old mus shall be used
mus_start mus start

Definition at line 168 of file KMeans.cpp.

void CKMeans::get_centers ( float64_t *&  centers,
int32_t &  dim,
int32_t &  num 
)

get centers

Parameters:
centers current centers are stored in here
dim dimensions are stored in here
num number of centers is stored in here

Definition at line 132 of file KMeans.h.

virtual EClassifierType CKMeans::get_classifier_type (  )  [virtual]

get classifier type

Returns:
classifier type KMEANS

Reimplemented from CClassifier.

Definition at line 55 of file KMeans.h.

void CKMeans::get_cluster_centers ( float64_t **  centers,
int32_t *  dim,
int32_t *  num 
)

get cluster centers (swig compatible)

Parameters:
centers current cluster centers are stored in here
dim dimensions are stored in here
num number of centers is stored in here

Definition at line 160 of file KMeans.h.

int32_t CKMeans::get_dimensions (  ) 

get dimensions

Returns:
number of dimensions

Definition at line 176 of file KMeans.h.

int32_t CKMeans::get_k (  ) 

get k

Returns:
the parameter k

Definition at line 91 of file KMeans.h.

float64_t CKMeans::get_max_iter (  ) 

get maximum number of iterations

Returns:
maximum number of iterations

Definition at line 110 of file KMeans.h.

virtual const char* CKMeans::get_name (  )  const [protected, virtual]
Returns:
object name

Implements CSGObject.

Definition at line 205 of file KMeans.h.

void CKMeans::get_radi ( float64_t *&  radi,
int32_t &  num 
)

get radi

Parameters:
radi current radi are stored in here
num number of radi is stored in here

Definition at line 120 of file KMeans.h.

void CKMeans::get_radiuses ( float64_t **  radii,
int32_t *  num 
)

get radiuses (swig compatible)

Parameters:
radii current radiuses are stored in here
num number of radiuses is stored in here

Definition at line 144 of file KMeans.h.

bool CKMeans::load ( FILE *  srcfile  )  [virtual]

load distance machine from file

Parameters:
srcfile file to load from
Returns:
if loading was successful

Reimplemented from CClassifier.

Definition at line 66 of file KMeans.cpp.

bool CKMeans::save ( FILE *  dstfile  )  [virtual]

save distance machine to file

Parameters:
dstfile file to save to
Returns:
if saving was successful

Reimplemented from CClassifier.

Definition at line 71 of file KMeans.cpp.

void CKMeans::set_k ( int32_t  p_k  ) 

set k

Parameters:
p_k new k

Definition at line 81 of file KMeans.h.

void CKMeans::set_max_iter ( int32_t  iter  ) 

set maximum number of iterations

Parameters:
iter the new maximum

Definition at line 100 of file KMeans.h.

void CKMeans::sqdist ( float64_t x,
CSimpleFeatures< float64_t > *  y,
float64_t z,
int32_t  n1,
int32_t  offs,
int32_t  n2,
int32_t  m 
) [protected]

sqdist

Parameters:
x x
y y
z z
n1 n1
offs offset
n2 n2
m m

Definition at line 120 of file KMeans.cpp.

bool CKMeans::train (  )  [virtual]

train distance machine

Returns:
if training was successful

Reimplemented from CClassifier.

Definition at line 46 of file KMeans.cpp.


Member Data Documentation

int32_t CKMeans::dimensions [protected]

number of dimensions

Definition at line 215 of file KMeans.h.

int32_t CKMeans::k [protected]

the k parameter in KMeans

Definition at line 212 of file KMeans.h.

int32_t CKMeans::max_iter [protected]

maximum number of iterations

Definition at line 209 of file KMeans.h.

float64_t* CKMeans::mus [protected]

centers of the clusters (size dimensions x k)

Definition at line 221 of file KMeans.h.

float64_t* CKMeans::R [protected]

radi of the clusters (size k)

Definition at line 218 of file KMeans.h.


The documentation for this class was generated from the following files:

SHOGUN Machine Learning Toolbox - Documentation