k-Means Algorithm.
More...
#include <rgroupingkmeans.h>
|
class | Centroid |
| Centroid of a group.
|
|
class | Group |
| Prototype Group.
|
|
template<class cGroup, class cObj, class cGroups>
class R::RGroupingKMeans< cGroup, cObj, cGroups >
k-Means Algorithm.
The RGroupingKMeans class provides the implementation of a basic k-Means grouping algorithm.
How to start the kMeans.
Enumerator |
---|
Incremental |
Start from the existing clustering.
|
Refine |
Use several sub-samples to initialize.
|
kMeansPlusPlus |
Use the kMeans++ method.
|
Random |
Initialize randomly.
|
Construct the k-Means.
- Parameters
-
n | Name of the k-Means. |
r | Random number generator to use. |
objs | Cursor over the objects to group. |
convergence | Convergence. |
debug | Debugger. |
Get the name of the heuristic.
size_t GetNbIterations |
( |
void |
| ) |
const |
Get the number of iterations run.
void ComputePrototype |
( |
cGroup * |
group | ) |
|
|
protected |
Compute the prototype of a given group.
- Parameters
-
double ComputeSumSim |
( |
cGroup * |
group, |
|
|
const cObj * |
obj |
|
) |
| |
|
protected |
Compute the sum of similarities between a given object and the other objects of its group.
- Parameters
-
void InitRandom |
( |
size_t |
nb | ) |
|
|
protected |
Creates the initial prototypes by randomly choosing them.
- Parameters
-
nb | Number of groups to create. |
void InitRefine |
( |
size_t |
nb, |
|
|
size_t |
max, |
|
|
size_t |
nbsub = 5 , |
|
|
int |
level = 5 |
|
) |
| |
|
protected |
Creates the initial prototypes by using a given number of samples containing a given percentage of the objects to group and running the kMeans. The best centroids of the sample are used.
- Parameters
-
nb | Number of groups to create. |
max | Maximal number of iterations. |
nbsub | Number of samples to use. |
level | Percentage of objects to group for each sample. |
void InitkMeansPlusPlus |
( |
size_t |
nb | ) |
|
|
protected |
Creates the initial prototypes by using the kMeans++ method.
- Parameters
-
nb | Number of groups to create. |
Re-Allocation step where the objects are put in the group of the most similar prototype.
size_t CalcNewProtosNb |
( |
void |
| ) |
|
|
protected |
Computing the new prototypes.
- Returns
- Number of different prototypes.
virtual double Similarity |
( |
const cObj * |
obj1, |
|
|
const cObj * |
obj2 |
|
) |
| |
|
pure virtual |
Compute the similarity between two objects. It is suppose that if the similarity is between 0 and 1 (same objects).
- Parameters
-
obj1 | First object. |
obj2 | Second object. |
virtual double Fitness |
( |
void |
| ) |
|
|
virtual |
Compute the fitness of the given clustering (the higher is the fitness, the best is the clustering.
By default, it computes the ratio between the average intra-similarity and the similarity between the centroids and the meta-centroid.
void DokMeans |
( |
size_t |
max | ) |
|
Perform a kMeans.
- Parameters
-
max | Maximal number of iterations. |
void Run |
( |
cGroups * |
groups, |
|
|
size_t |
max, |
|
|
size_t |
nb, |
|
|
tInitial |
start = Random |
|
) |
| |
Run the heuristic.
- Parameters
-
groups | Group to initialize. |
max | Maximal number of iterations. |
nb | Number of groups to create. |
start | How to the start the clustering. |
Random number generator to use.
Objects used to build the clusters.
Number of objects used to build the clusters.
Prototypes of the groups. The order of the prototypes is identical as the corresponding group.