When a cluster is empty for KMeans, it's better to give it the point from another cluster j that is the furthest one from center j.

This commit is contained in:
Pierre-Emmanuel Viel 2013-12-20 01:00:55 +01:00
parent 26f5d2d639
commit d3ac1bc314

View File

@ -759,12 +759,15 @@ private:
for (int k=0; k<indices_length; ++k) { for (int k=0; k<indices_length; ++k) {
if (belongs_to[k]==j) { if (belongs_to[k]==j) {
// for cluster j, we move the furthest element from the center to the empty cluster i
if ( distance_(dataset_[indices[k]], dcenters[j], veclen_) == radiuses[j] ) {
belongs_to[k] = i; belongs_to[k] = i;
count[j]--; count[j]--;
count[i]++; count[i]++;
break; break;
} }
} }
}
converged = false; converged = false;
} }
} }