GClasses
|
An implementation of the K-means clustering algorithm. More...
#include <GCluster.h>
Public Member Functions | |
GKMeans (size_t nClusters, GRand *pRand) | |
~GKMeans () | |
virtual void | cluster (GMatrix *pData) |
Performs clustering. | |
virtual size_t | whichCluster (size_t nVector) |
Identifies the cluster of the specified row. | |
void | init (GMatrix *pData) |
Selects random centroids and initializes internal data structures. | |
double | assignClusters () |
Assigns each row to the cluster of the nearest centroid as measured with the dissimilarity metric. Returns the sum-squared-distance of each row with its centroid. | |
void | recomputeCentroids () |
Computes new centroids for each cluster. | |
GMatrix * | centroids () |
Returns a k x d matrix, where each row is one of the k centroids. | |
void | setReps (size_t r) |
Specify the number of times to cluster the data. The best clustering (as measured by the sum-squared-difference between each point and its cluster-centroid) will be kept. | |
Protected Member Functions | |
bool | clusterAttempt (size_t nMaxIterations) |
bool | selectSeeds (GMatrix *pSeeds) |
Protected Attributes | |
GMatrix * | m_pCentroids |
GMatrix * | m_pData |
size_t * | m_pClusters |
size_t | m_reps |
GRand * | m_pRand |
An implementation of the K-means clustering algorithm.
GClasses::GKMeans::GKMeans | ( | size_t | nClusters, |
GRand * | pRand | ||
) |
GClasses::GKMeans::~GKMeans | ( | ) |
double GClasses::GKMeans::assignClusters | ( | ) |
Assigns each row to the cluster of the nearest centroid as measured with the dissimilarity metric. Returns the sum-squared-distance of each row with its centroid.
GMatrix* GClasses::GKMeans::centroids | ( | ) | [inline] |
Returns a k x d matrix, where each row is one of the k centroids.
virtual void GClasses::GKMeans::cluster | ( | GMatrix * | pData | ) | [virtual] |
Performs clustering.
Implements GClasses::GClusterer.
bool GClasses::GKMeans::clusterAttempt | ( | size_t | nMaxIterations | ) | [protected] |
void GClasses::GKMeans::init | ( | GMatrix * | pData | ) |
Selects random centroids and initializes internal data structures.
void GClasses::GKMeans::recomputeCentroids | ( | ) |
Computes new centroids for each cluster.
bool GClasses::GKMeans::selectSeeds | ( | GMatrix * | pSeeds | ) | [protected] |
void GClasses::GKMeans::setReps | ( | size_t | r | ) | [inline] |
Specify the number of times to cluster the data. The best clustering (as measured by the sum-squared-difference between each point and its cluster-centroid) will be kept.
virtual size_t GClasses::GKMeans::whichCluster | ( | size_t | nVector | ) | [virtual] |
Identifies the cluster of the specified row.
Implements GClasses::GClusterer.
GMatrix* GClasses::GKMeans::m_pCentroids [protected] |
size_t* GClasses::GKMeans::m_pClusters [protected] |
GMatrix* GClasses::GKMeans::m_pData [protected] |
GRand* GClasses::GKMeans::m_pRand [protected] |
size_t GClasses::GKMeans::m_reps [protected] |