6 /***********************************************************************/
8 SingleLinkage::SingleLinkage(RAbundVector* rav, ListVector* lv, SparseDistanceMatrix* dm, float c, string s) :
9 Cluster(rav, lv, dm, c, s)
13 /***********************************************************************/
14 //This function returns the tag of the method.
15 string SingleLinkage::getTag() {
19 /***********************************************************************/
20 //This function clusters based on the single linkage method.
21 void SingleLinkage::update(double& cutOFF){
23 smallCol = dMatrix->getSmallestCell(smallRow);
24 nColCells = dMatrix->seqVec[smallCol].size();
25 nRowCells = dMatrix->seqVec[smallRow].size();
27 vector<bool> deleted(nRowCells, false);
32 // The vector has to be traversed in reverse order to preserve the index
33 // for faster removal in removeCell()
34 for (int i=nRowCells-1;i>=0;i--) {
35 if (dMatrix->seqVec[smallRow][i].index == smallCol) {
36 rowInd = i; // The index of the smallest distance cell in rowCells
38 search = dMatrix->seqVec[smallRow][i].index;
40 for (int j=0;j<nColCells;j++) {
41 if (dMatrix->seqVec[smallCol][j].index != smallRow) { //if you are not the small cell
42 if (dMatrix->seqVec[smallCol][j].index == search) {
43 changed = updateDistance(dMatrix->seqVec[smallCol][j], dMatrix->seqVec[smallRow][i]);
44 dMatrix->updateCellCompliment(smallCol, j);
45 dMatrix->rmCell(smallRow, i);
52 // Assign the cell to the new cluster
53 // remove the old cell from seqVec and add the cell
54 // with the new row and column assignment again
55 float distance = dMatrix->seqVec[smallRow][i].dist;
56 dMatrix->rmCell(smallRow, i);
57 if (search < smallCol){
58 PDistCell value(smallCol, distance);
59 dMatrix->addCell(search, value);
61 PDistCell value(search, distance);
62 dMatrix->addCell(smallCol, value);
64 sort(dMatrix->seqVec[smallCol].begin(), dMatrix->seqVec[smallCol].end(), compareIndexes);
65 sort(dMatrix->seqVec[search].begin(), dMatrix->seqVec[search].end(), compareIndexes);
71 // remove also the cell with the smallest distance
73 dMatrix->rmCell(smallRow, rowInd);
76 m->errorOut(e, "SingleLinkage", "update");
82 /***********************************************************************/
83 //This function updates the distance based on the nearest neighbor method.
84 bool SingleLinkage::updateDistance(PDistCell& colCell, PDistCell& rowCell) {
87 if (colCell.dist > rowCell.dist) {
88 colCell.dist = rowCell.dist;
93 m->errorOut(e, "SingleLinkage", "updateDistance");
97 /***********************************************************************/