6 /***********************************************************************/
8 SingleLinkage::SingleLinkage(RAbundVector* rav, ListVector* lv, SparseMatrix* dm) :
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(){
25 vector<bool> deleted(nRowCells, false);
30 // The vector has to be traversed in reverse order to preserve the index
31 // for faster removal in removeCell()
32 for (int i=nRowCells-1;i>=0;i--) {
33 if ((rowCells[i]->row == smallRow) && (rowCells[i]->column == smallCol)) {
34 rowInd = i; // The index of the smallest distance cell in rowCells
36 if (rowCells[i]->row == smallRow) {
37 search = rowCells[i]->column;
39 search = rowCells[i]->row;
42 for (int j=0;j<nColCells;j++) {
43 if (!((colCells[j]->row == smallRow) && (colCells[j]->column == smallCol))) {
44 if (colCells[j]->row == search || colCells[j]->column == search) {
45 changed = updateDistance(colCells[j], rowCells[i]);
46 // If the cell's distance changed and it had the same distance as
47 // the smallest distance, invalidate the mins vector in SparseMatrix
49 if (colCells[j]->vectorMap != NULL) {
50 *(colCells[j]->vectorMap) = NULL;
51 colCells[j]->vectorMap = NULL;
54 removeCell(rowCells[i], i , -1);
61 // Assign the cell to the new cluster
62 // remove the old cell from seqVec and add the cell
63 // with the new row and column assignment again
64 removeCell(rowCells[i], i , -1, false);
65 if (search < smallCol){
66 rowCells[i]->row = smallCol;
67 rowCells[i]->column = search;
69 rowCells[i]->row = search;
70 rowCells[i]->column = smallCol;
72 seqVec[rowCells[i]->row].push_back(rowCells[i]);
73 seqVec[rowCells[i]->column].push_back(rowCells[i]);
79 // remove also the cell with the smallest distance
80 removeCell(rowCells[rowInd], -1 , -1);
83 errorOut(e, "SingleLinkage", "update");
89 /***********************************************************************/
90 //This function updates the distance based on the nearest neighbor method.
91 bool SingleLinkage::updateDistance(MatData& colCell, MatData& rowCell) {
94 if (colCell->dist > rowCell->dist) {
95 colCell->dist = rowCell->dist;
100 errorOut(e, "SingleLinkage", "updateDistance");
104 /***********************************************************************/