Skip to content

Commit

Permalink
bug fix in kmeans sparse init
Browse files Browse the repository at this point in the history
  • Loading branch information
md-shafiul-alam committed May 21, 2024
1 parent 908955d commit 2f52a21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cpp/daal/src/algorithms/kmeans/kmeans_plusplus_init_impl.i
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,19 @@ public:
{
algorithmFPType sumOfDist2 = algorithmFPType(0);
size_t csrCursor = 0u;
algorithmFPType pLastAddedCenterSumSq = algorithmFPType(0.);
for (size_t iCol = 0u; iCol < dim; iCol++){
pLastAddedCenterSumSq += pLastAddedCenter[iCol] * pLastAddedCenter[iCol];
}

for (size_t iRow = 0u; iRow < nRowsToProcess; iRow++)
{
algorithmFPType dist2 = algorithmFPType(0);
algorithmFPType dist2 = pLastAddedCenterSumSq;
const size_t nValues = rowIdx[iRow + 1] - rowIdx[iRow];
for (size_t i = 0u; i < nValues; i++, csrCursor++)
{
dist2 += (pData[csrCursor] - pLastAddedCenter[colIdx[csrCursor] - 1]) * (pData[csrCursor] - pLastAddedCenter[colIdx[csrCursor] - 1]);
dist2 += pData[csrCursor] * pData[csrCursor];
dist2 -= 2 * pData[csrCursor] * pLastAddedCenter[colIdx[csrCursor] - 1];
}
if (aWeights)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ static compute_result<Task> call_daal_kernel(const context_cpu& ctx,
const table& data) {
const std::int64_t column_count = data.get_column_count();
const std::int64_t cluster_count = desc.get_cluster_count();
const std::int64_t trial_count = desc.get_local_trials_count();

daal_kmeans_init::Parameter par(dal::detail::integral_cast<std::size_t>(cluster_count),
0,
dal::detail::integral_cast<std::size_t>(desc.get_seed()));
par.nTrials = dal::detail::integral_cast<std::size_t>(trial_count);

const auto daal_data = interop::convert_to_daal_table<Float>(data);
const std::size_t len_input = 1;
Expand Down

0 comments on commit 2f52a21

Please sign in to comment.