Apply to KMeansIndex KMeanspp the same modification as in HierarchicalClusteringIndex
This commit is contained in:
parent
45e0e5f8e9
commit
5aeeaa6fce
@ -211,6 +211,7 @@ public:
|
|||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
closestDistSq[i] = distance_(dataset_[indices[i]], dataset_[indices[index]], dataset_.cols);
|
closestDistSq[i] = distance_(dataset_[indices[i]], dataset_[indices[index]], dataset_.cols);
|
||||||
|
closestDistSq[i] *= closestDistSq[i];
|
||||||
currentPot += closestDistSq[i];
|
currentPot += closestDistSq[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +237,10 @@ public:
|
|||||||
|
|
||||||
// Compute the new potential
|
// Compute the new potential
|
||||||
double newPot = 0;
|
double newPot = 0;
|
||||||
for (int i = 0; i < n; i++) newPot += std::min( distance_(dataset_[indices[i]], dataset_[indices[index]], dataset_.cols), closestDistSq[i] );
|
for (int i = 0; i < n; i++) {
|
||||||
|
DistanceType dist = distance_(dataset_[indices[i]], dataset_[indices[index]], dataset_.cols);
|
||||||
|
newPot += std::min( dist*dist, closestDistSq[i] );
|
||||||
|
}
|
||||||
|
|
||||||
// Store the best result
|
// Store the best result
|
||||||
if ((bestNewPot < 0)||(newPot < bestNewPot)) {
|
if ((bestNewPot < 0)||(newPot < bestNewPot)) {
|
||||||
@ -248,7 +252,10 @@ public:
|
|||||||
// Add the appropriate center
|
// Add the appropriate center
|
||||||
centers[centerCount] = indices[bestNewIndex];
|
centers[centerCount] = indices[bestNewIndex];
|
||||||
currentPot = bestNewPot;
|
currentPot = bestNewPot;
|
||||||
for (int i = 0; i < n; i++) closestDistSq[i] = std::min( distance_(dataset_[indices[i]], dataset_[indices[bestNewIndex]], dataset_.cols), closestDistSq[i] );
|
for (int i = 0; i < n; i++) {
|
||||||
|
DistanceType dist = distance_(dataset_[indices[i]], dataset_[indices[bestNewIndex]], dataset_.cols);
|
||||||
|
closestDistSq[i] = std::min( dist*dist, closestDistSq[i] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
centers_length = centerCount;
|
centers_length = centerCount;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user