if (dists[i][j] > largestDist) { largestDist = dists[i][j]; }
}
}
-
+
buildPhase(); //choosing the medoids
swapPhase(); //optimize clusters
}
}
}
/**************************************************************************************************/
+//build and swap functions based on pam.c by maechler from R cluster package
//sets Dp[0] does not set Dp[1]. chooses intial medoids.
int Pam::buildPhase() {
try {
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;
//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;
for (int j = 0; j < numSamples; j++) {
if (m->control_pressed) { break; }
if (dists[i][j] == Dp[j][0]) {
- 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]);
+ double smallValue; smallValue = 0.0;
+ if (Dp[j][1] > dists[h][j]) { smallValue = dists[h][j]; }
+ else { smallValue = Dp[j][1]; }
+ dz += (- Dp[j][0]+ smallValue);
}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) {
}
}
}
+
return 0;
}
catch(exception& e) {