# Ignition Math

## API Reference

6.10.0
Kmeans Class Reference

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. More...

#include <math/gzmath.hh>

## Public Member Functions

Kmeans (const std::vector< Vector3d > &_obs)
constructor More...

virtual ~Kmeans ()
Destructor. More...

bool AppendObservations (const std::vector< Vector3d > &_obs)
Add observations to the cluster. More...

bool Cluster (int _k, std::vector< Vector3d > &_centroids, std::vector< unsigned int > &_labels)
Executes the k-means algorithm. More...

std::vector< Vector3dObservations () const
Get the observations to cluster. More...

bool Observations (const std::vector< Vector3d > &_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.

## ◆ Kmeans()

 Kmeans ( const std::vector< Vector3d > & _obs )
explicit

constructor

Parameters
 [in] _obs Set of observations to cluster.

## ◆ ~Kmeans()

 virtual ~Kmeans ( )
virtual

Destructor.

## ◆ AppendObservations()

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

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

## ◆ Cluster()

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

Executes the k-means algorithm.

Parameters
 [in] _k Number of partitions to cluster. [out] _centroids Vector of centroids. Each element contains the centroid of one cluster. [out] _labels Vector 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 Observations ( ) const

Get the observations to cluster.

Returns
The vector of observations.

## ◆ Observations() [2/2]

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

Set the observations to cluster.

Parameters
 [in] _obs The 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: