From 6ce64c0c32f0aa22eaf70953bd8264130e20e18f Mon Sep 17 00:00:00 2001 From: Sarah Westcott Date: Fri, 31 Jan 2014 11:22:42 -0500 Subject: [PATCH] fixed bug in pam --- pam.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pam.cpp b/pam.cpp index b09c2a0..d33bab8 100644 --- a/pam.cpp +++ b/pam.cpp @@ -25,7 +25,7 @@ Pam::Pam(vector > c, vector > d, int p) : CommunityTy if (dists[i][j] > largestDist) { largestDist = dists[i][j]; } } } - + buildPhase(); //choosing the medoids swapPhase(); //optimize clusters } @@ -65,12 +65,11 @@ int Pam::buildPhase() { gains[i] = 0.0; for (int j = 0; j < numSamples; j++) { - //cout << i << '\t' << j << '\t' << Dp[i][0] << '\t' << dists[i][j] << '\t' << totalGain << endl; - totalGain = Dp[i][0] - dists[i][j]; + totalGain = Dp[j][0] - dists[i][j]; if (totalGain > 0.0) { gains[i] += totalGain; } } if (m->debug) { m->mothurOut("[DEBUG]: " + toString(i) + " totalGain = " + toString(totalGain) + "\n"); } - + if (clusterGain <= gains[i]) { clusterGain = gains[i]; medoid = i; @@ -104,7 +103,7 @@ int Pam::swapPhase() { //calculate cost of initial choice - average distance of samples to their closest medoid double sky = 0.0; double dzsky = 1.0; - for (int i = 0; i < numSamples; i++) { sky += Dp[i][0]; } sky /= (double) numSamples; + for (int i = 0; i < numSamples; i++) { sky += Dp[i][0]; } //sky /= (double) numSamples; bool done = false; int hbest, nbest; hbest = -1; nbest = -1; @@ -128,9 +127,9 @@ int Pam::swapPhase() { double small = 0.0; if (Dp[j][1] > dists[h][j]) { small = dists[h][j]; } else { small = Dp[j][1]; } - dz += (small - Dp[j][0]); + dz += (- Dp[j][0]+ small); }else if (dists[h][j] < Dp[j][0]) { - dz += (dists[h][j] - Dp[j][0]); + dz += (- Dp[j][0] + dists[h][j]); } } if (dzsky > dz) { @@ -222,6 +221,7 @@ int Pam::updateDp() { } } } + return 0; } catch(exception& e) { -- 2.39.2