Image Component Library (ICL)
|
Generic Implementation of the K-Means algorithm. More...
#include <KMeans.h>
Classes | |
struct | Result |
restult type More... | |
Public Member Functions | |
KMeans (int numCenters=0) | |
constructor with optionally given number of centers | |
void | init (int numCenters) |
deferred intitialization with number of centers | |
int | findNN (const Vector &v, Scalar &minDist) |
finds the nearest centroid for a given data pointer | |
template<class RandomAcessIterator > | |
Result | apply (RandomAcessIterator begin, RandomAcessIterator end, int numSteps=1000, bool reinitCenters=true) |
runs the KMeans algorithms on the given data | |
Static Private Member Functions | |
static Scalar | diff_power_two (const Scalar &a, const Scalar &b) |
internal utility function | |
static Scalar | dist (const Vector &a, const Vector &b) |
utility function computing the vector distance | |
static void | setVectorNull (Vector &v) |
sets a vector to null | |
Private Attributes | |
std::vector< Vector > | m_centers |
internal list of centroids | |
std::vector< Vector > | m_means |
internal buffer | |
std::vector< int > | m_nums |
numbers of points associated to each centroid | |
std::vector< Scalar > | m_errors |
averate quantisation error for each centroid |
Generic Implementation of the K-Means algorithm.
The K-Means algorithms performs vector quantisation in a very simple way. Given a set of data pointers xi, and starting with a fixed given number of initial centroids, randomly drawn from the given data points, it iterates two steps:
Supported Vector Types are FixedColVector, FixedRowVector, DynColVector, DynRowVector and Point32f
icl::math::KMeans< Vector, Scalar >::KMeans | ( | int | numCenters = 0 | ) | [inline] |
constructor with optionally given number of centers
Result icl::math::KMeans< Vector, Scalar >::apply | ( | RandomAcessIterator | begin, |
RandomAcessIterator | end, | ||
int | numSteps = 1000 , |
||
bool | reinitCenters = true |
||
) | [inline] |
runs the KMeans algorithms on the given data
if reinitCenters is set to false, the centers of the last call to this method are reused
static Scalar icl::math::KMeans< Vector, Scalar >::diff_power_two | ( | const Scalar & | a, |
const Scalar & | b | ||
) | [inline, static, private] |
internal utility function
static Scalar icl::math::KMeans< Vector, Scalar >::dist | ( | const Vector & | a, |
const Vector & | b | ||
) | [inline, static, private] |
utility function computing the vector distance
int icl::math::KMeans< Vector, Scalar >::findNN | ( | const Vector & | v, |
Scalar & | minDist | ||
) | [inline] |
finds the nearest centroid for a given data pointer
void icl::math::KMeans< Vector, Scalar >::init | ( | int | numCenters | ) | [inline] |
deferred intitialization with number of centers
static void icl::math::KMeans< Vector, Scalar >::setVectorNull | ( | Vector & | v | ) | [inline, static, private] |
sets a vector to null
std::vector<Vector> icl::math::KMeans< Vector, Scalar >::m_centers [private] |
internal list of centroids
std::vector<Scalar> icl::math::KMeans< Vector, Scalar >::m_errors [private] |
averate quantisation error for each centroid
std::vector<Vector> icl::math::KMeans< Vector, Scalar >::m_means [private] |
internal buffer
std::vector<int> icl::math::KMeans< Vector, Scalar >::m_nums [private] |
numbers of points associated to each centroid