IMP logo
IMP Reference Guide  2.9.0
The Integrative Modeling Platform
IMP::kmeans::KMeans Class Reference

#include <IMP/kmeans/KMeans.h>

+ Inheritance diagram for IMP::kmeans::KMeans:

Detailed Description

Class that wraps and provides an interface to the K-means library by David Mount (GPL license), downloaded and adapted to IMP from http://www.cs.umd.edu/~mount/Projects/KMeans/

For a simple usage example, see modules/kmeans/examples/kmeans_example.py

Warning: KMeans has not been well tested yet
Use with caution and please report any bugs found.
Warning: KMeans has not been stabilized and is likely to change without notice.

Definition at line 72 of file kmeans/KMeans.h.

Public Member Functions

 KMeans (const std::string &fname_data, int dim, unsigned int max_nPts)
 
 KMeans ()
 
void add_data_pt (const IMP::Floats &p)
 
void clear_data ()
 Clears all data in object. More...
 
void execute (unsigned int k, KM_ALG_TYPE alg_type=KM_LLOYDS, int stages=100)
 
IMP::Ints get_assignments () const
 Returns the cluster assignment of each data point. More...
 
IMP::Floats get_center (unsigned int i) const
 Returns the i'th center. More...
 
const IMP::Floatsget_data_point (unsigned int i) const
 Returns the i'th point in the dataset. More...
 
unsigned int get_number_of_centers () const
 
unsigned int get_number_of_data_points () const
 
IMP::Floats get_squared_distance_to_centers () const
 
virtual std::string get_type_name () const
 
virtual ::IMP::VersionInfo get_version_info () const
 Get information about the module and version of the object. More...
 
void print_centers (LogLevel ll=PROGRESS) const
 Print the centers (assuming execute() was applied) to log. More...
 
- Public Member Functions inherited from IMP::Object
virtual void clear_caches ()
 
CheckLevel get_check_level () const
 
LogLevel get_log_level () const
 
void set_check_level (CheckLevel l)
 
void set_log_level (LogLevel l)
 Set the logging level used in this object. More...
 
void set_was_used (bool tf) const
 
void show (std::ostream &out=std::cout) const
 
const std::string & get_name () const
 
void set_name (std::string name)
 

Additional Inherited Members

- Protected Member Functions inherited from IMP::Object
 Object (std::string name)
 Construct an object with the given name. More...
 
virtual void do_destroy ()
 

Constructor & Destructor Documentation

IMP::kmeans::KMeans::KMeans ( const std::string &  fname_data,
int  dim,
unsigned int  max_nPts 
)

Initialize the KMeans object with data from fname_data, assuming input data of dimension dim

Parameters
[in]fname_dataInput filename. Input is assumed to be in textual (ascii) whitespace separated format, with a fixed number of columns dim. Each row represents a single data point of fixed dimension dim. For example, a file with three examples of dimension 4 would look as follows:
10.3 0.7 1.3 11.1
2.1 1.5 20.1 0.2
10.1 0.9 2.1 10.9
[in]dimDimension of each data point
[in]max_nPtsMaximal number of points to be read from file
IMP::kmeans::KMeans::KMeans ( )

Empty constructor for default initialization - object data is not considered initialized after this call

Member Function Documentation

void IMP::kmeans::KMeans::add_data_pt ( const IMP::Floats p)

Add a data point for clustering.

Parameters
[in]ppoint to be added
void IMP::kmeans::KMeans::clear_data ( )

Clears all data in object.

void IMP::kmeans::KMeans::execute ( unsigned int  k,
KM_ALG_TYPE  alg_type = KM_LLOYDS,
int  stages = 100 
)

Execute a kmeans algorithm variant on the data points stored.

Parameters
[in]knumber of clusters
[in]alg_typeThe k-means algorithm variant to use
See Also
KM_ALG_TYPE
Parameters
[in]stagesNumber of k-means iterations
IMP::Ints IMP::kmeans::KMeans::get_assignments ( ) const

Returns the cluster assignment of each data point.

Definition at line 149 of file kmeans/KMeans.h.

IMP::Floats IMP::kmeans::KMeans::get_center ( unsigned int  i) const

Returns the i'th center.

Must be called only following a successful execute() invocation

Parameters
[in]iCenter number in range (0,...,k-1)
const IMP::Floats& IMP::kmeans::KMeans::get_data_point ( unsigned int  i) const

Returns the i'th point in the dataset.

Parameters
[in]iCenter number in range (0,...,nPts-1)
unsigned int IMP::kmeans::KMeans::get_number_of_centers ( ) const
Returns
The number of centers after a successful execution

Definition at line 164 of file kmeans/KMeans.h.

unsigned int IMP::kmeans::KMeans::get_number_of_data_points ( ) const
Returns
The number of data points

Definition at line 133 of file kmeans/KMeans.h.

IMP::Floats IMP::kmeans::KMeans::get_squared_distance_to_centers ( ) const

Returns the squared distance of each data point to its respective cluster center

Definition at line 157 of file kmeans/KMeans.h.

virtual ::IMP::VersionInfo IMP::kmeans::KMeans::get_version_info ( ) const
virtual

Get information about the module and version of the object.

Reimplemented from IMP::Object.

Definition at line 101 of file kmeans/KMeans.h.

void IMP::kmeans::KMeans::print_centers ( LogLevel  ll = PROGRESS) const

Print the centers (assuming execute() was applied) to log.

Parameters
llthe log level for printout

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