Skip to content

Commit

Permalink
real fix #228
Browse files Browse the repository at this point in the history
  • Loading branch information
Adarsh321123 committed Jun 4, 2023
1 parent 6e1c15e commit a2eb16f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/algorithms/fastpam1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ void FastPAM1::swapFastPAM1(
float dij = 0;

while (swapPerformed && iter < maxIter) {
bestChange = 0;
deltaTD.zeros();
iter++;
// TODO(@motiwari): pragma omp parallel for?
for (size_t i = 0; i < data.n_cols; i++) {
Expand Down Expand Up @@ -164,15 +166,16 @@ void FastPAM1::swapFastPAM1(
arma::uword swapOut = deltaTD.index_min();
// If the loss change is better than the best loss change so far,
// Update our running best statistics
if (deltaTD.min() < bestChange) {
if (deltaTD.min() < prevBestChange) {
bestChange = deltaTD.min();
prevBestChange = bestChange;
swapIn = i;
medoidToSwap = swapOut;
}
}

// Update the loss and perform the swap if the loss would be improved
if (bestChange < prevBestChange) {
if (bestChange < 0) {
(*medoidIndices)(medoidToSwap) = swapIn;
calcBestDistancesSwap(
data,
Expand All @@ -182,7 +185,6 @@ void FastPAM1::swapFastPAM1(
&secondBestDistances,
assignments,
swapPerformed);
prevBestChange = bestChange;
} else {
swapPerformed = false;
}
Expand Down

0 comments on commit a2eb16f

Please sign in to comment.