/***********************************************************************/
AverageLinkage::AverageLinkage(RAbundVector* rav, ListVector* lv, SparseMatrix* dm) :
-Cluster(rav, lv, dm)
-{}
+ Cluster(rav, lv, dm)
+{
+ saveRow = -1;
+ saveCol = -1;
+}
+
+
+/***********************************************************************/
+//This function returns the tag of the method.
+string AverageLinkage::getTag() {
+ return("an");
+}
+
/***********************************************************************/
-//THis function clusters based on the average method
-void AverageLinkage::update(){
- try{
- getRowColCells();
-
- vector<int> found(nColCells, 0);
-
- int rowBin = rabund->get(smallRow);
- int colBin = rabund->get(smallCol);
- int totalBin = rowBin + colBin;
-
- for(int i=1;i<nRowCells;i++){
-
- int search;
-
- if(rowCells[i]->row == smallRow){
- search = rowCells[i]->column;
- }
- else{
- search = rowCells[i]->row;
- }
-
- for(int j=1;j<nColCells;j++){
-
- if(colCells[j]->row == search || colCells[j]->column == search){
- colCells[j]->dist = (colBin * colCells[j]->dist + rowBin * rowCells[i]->dist) / totalBin;
-
- found[j] = 1;
-
- if(colCells[j]->vectorMap != NULL){
- *(colCells[j]->vectorMap) = NULL;
- colCells[j]->vectorMap = NULL;
- }
-
- break;
- }
-
- }
- dMatrix->rmCell(rowCells[i]);
- }
-
- clusterBins();
- clusterNames();
-
- for(int i=0;i<nColCells;i++){
- if(found[i] == 0){
- dMatrix->rmCell(colCells[i]);
- }
+//This function updates the distance based on the average linkage method.
+bool AverageLinkage::updateDistance(MatData& colCell, MatData& rowCell) {
+ try {
+ if ((saveRow != smallRow) || (saveCol != smallCol)) {
+ rowBin = rabund->get(smallRow);
+ colBin = rabund->get(smallCol);
+ totalBin = rowBin + colBin;
+ saveRow = smallRow;
+ saveCol = smallCol;
}
+
+ colCell->dist = (colBin * colCell->dist + rowBin * rowCell->dist) / totalBin;
+ return(true);
}
catch(exception& e) {
- errorOut(e, "AverageLinkage", "update");
+ errorOut(e, "AverageLinkage", "updateDistance");
exit(1);
}
}
/***********************************************************************/
-#endif
+/***********************************************************************/
+#endif