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:
parent
26f5d2d639
commit
d3ac1bc314
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user