Kmeans Class Reference

K-Means clustering algorithm. More...

#include <math/gzmath.hh>

Public Member Functions

 Kmeans (const std::vector< Vector3 > &_obs)
 constructor More...
 
virtual ~Kmeans ()
 Destructor. More...
 
bool AppendObservations (const std::vector< Vector3 > &_obs)
 Add observations to the cluster. More...
 
bool Cluster (int _k, std::vector< Vector3 > &_centroids, std::vector< unsigned int > &_labels)
 Executes the k-means algorithm. More...
 
std::vector< Vector3Observations () const
 Get the observations to cluster. More...
 
bool Observations (const std::vector< Vector3 > &_obs)
 Set the observations to cluster. More...
 

Detailed Description

K-Means clustering algorithm.

Given a set of observations, k-means partitions the observations into k sets so as to minimize the within-cluster sum of squares. Description based on http://en.wikipedia.org/wiki/K-means_clustering.

Constructor & Destructor Documentation

§ Kmeans()

Kmeans ( const std::vector< Vector3 > &  _obs)

constructor

Parameters
[in]_obsSet of observations to cluster.

§ ~Kmeans()

virtual ~Kmeans ( )
virtual

Destructor.

Member Function Documentation

§ AppendObservations()

bool AppendObservations ( const std::vector< Vector3 > &  _obs)

Add observations to the cluster.

Parameters
[in]_obsVector of observations.
Returns
True if the _obs vector is not empty or false otherwise.

§ Cluster()

bool Cluster ( int  _k,
std::vector< Vector3 > &  _centroids,
std::vector< unsigned int > &  _labels 
)

Executes the k-means algorithm.

Parameters
[in]_kNumber of partitions to cluster.
[out]_centroidsVector of centroids. Each element contains the centroid of one cluster.
[out]_labelsVector of labels. The size of this vector is equals to the number of observations. Each element represents the cluster to which observation belongs.
Returns
True when the operation succeed or false otherwise. The operation will fail if the number of observations is not positive, if the number of clusters is non positive, or if the number of clusters if greater than the number of observations.

§ Observations() [1/2]

std::vector<Vector3> Observations ( ) const

Get the observations to cluster.

Returns
The vector of observations.

§ Observations() [2/2]

bool Observations ( const std::vector< Vector3 > &  _obs)

Set the observations to cluster.

Parameters
[in]_obsThe new vector of observations.
Returns
True if the vector is not empty or false otherwise.

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