Skip to content

Commit

Permalink
Distributed K-Means: fix for step #2
Browse files Browse the repository at this point in the history
  • Loading branch information
amgrigoriev committed Dec 9, 2021
1 parent c5d36a9 commit ff495f3
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 ff495f3

Please sign in to comment.