Skip to content

Commit

Permalink
Distributed K-Means: fix for step #2 (#2016)
Browse files Browse the repository at this point in the history
  • Loading branch information
amgrigoriev authored Dec 15, 2021
1 parent 4ca95fc commit 62934ec
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ DECLARE_SOURCE(
const int local_id = get_local_id(1);
const int oldN = partialCentroidsCounters[global_id];
const int newN = cCounters[global_id];
const algorithmFPType oldContrib = oldN * partialCentroids[global_id * P + local_id];
const algorithmFPType newContrib = newN * centroids[global_id * P + local_id];
centroids[global_id * P + local_id] = (oldContrib + newContrib) / (oldN + newN);
const algorithmFPType oldContrib = oldN > 0 ? oldN * partialCentroids[global_id * P + local_id] : 0.0;
const algorithmFPType newContrib = newN > 0 ? newN * centroids[global_id * P + local_id] : 0.0;
centroids[global_id * P + local_id] = (oldN + newN > 0) ? (oldContrib + newContrib) / (oldN + newN) : 0.0;
if (local_id == 0) cCounters[global_id] = oldN + newN;
}

Expand Down

0 comments on commit 62934ec

Please sign in to comment.