📄 itcc.cc
字号:
int tempRowCL = rowCL[r]; int minCL = tempRowCL; double minDistance = MY_DBL_MAX; for (int rc = 0; rc < numRowCluster; rc++){ if (rowCS[rc] > 0){ double tempDistance = rowDistance(r, rc); updateVariable(minDistance, minCL, tempDistance, rc); } } if (minCL != rowCL[r]) rowClusterChange++; rowCL[r] = minCL; } checkDumpLevel4NumOfChange("row(s)", rowClusterChange);} void Itcc::reassignCC(){ int colClusterChange = 0; for (int c = 0; c < numCol; c++){ int tempColCL = colCL[c]; int minCL = tempColCL; double minDistance = MY_DBL_MAX; for (int cc = 0; cc < numColCluster; cc++){ if (colCS[cc] > 0){ double tempDistance = colDistance(c, cc); updateVariable(minDistance, minCL, tempDistance, cc); } } if (minCL != colCL[c]) colClusterChange++; colCL[c] = minCL; } checkDumpLevel4NumOfChange("col(s)", colClusterChange);} void Itcc::doInitialization(){ chooseInitializationMethod(); if (isTakingReverse){ cout << " Row should not be reversed in ITCC." << endl << endl; exit(EXIT_FAILURE); } isEmptyRowClusterReported = isEmptyColClusterReported = false ; computeRowClusterSize(); computeColClusterSize(); if (isComputingOneWayObjective){ computeRowCentroid4RowCluster();// normalizeRowCentroid(); computeObjectiveFunction4RowCluster(); computeColCentroid4ColCluster();// normalizeColCentroid(); computeObjectiveFunction4ColCluster(); } computeAcompressed(); computeMarginal(); computeObjectiveFunction();// cout << "Initialization done..." << endl; checkDumpLevel4InitialObjectValue();}void Itcc::doBatchUpdate(){ checkDumpLevel4BatchUpdate("begin"); int numIteration = 0; double oldObjValue; do { numIteration++; oldObjValue = objValue; myCRS->setSmoothingFactor(smoothingType, rowSmoothingFactor); myCCS->setSmoothingFactor(smoothingType, colSmoothingFactor); if (numRowCluster < numRow){ computeRowCentroid(); reassignRC(); computeAcompressed(); computeMarginal(); computeObjectiveFunction(); checkDumpLevel4BatchUpdate("row", numIteration); } if (numColCluster < numCol){ computeColCentroid(); reassignCC(); computeAcompressed(); computeMarginal(); computeObjectiveFunction(); checkDumpLevel4BatchUpdate("col", numIteration); } rowSmoothingFactor *= myCRS->getAnnealingFactor(); colSmoothingFactor *= myCCS->getAnnealingFactor(); } while ((oldObjValue - objValue) > (rowBatchUpdateThreshold * mutualInfo)); checkDumpLevel4BatchUpdate("end");}void Itcc::doBatchUpdate4VariationI(){ checkDumpLevel4BatchUpdate("begin"); int numIteration = 0; int *beforeRowCL = new int[numRow]; int *afterRowCL = new int[numRow];// int *beforeColCL = new int[numCol]; double oldObjValue; do { numIteration++; oldObjValue = objValue; myCRS->setSmoothingFactor(smoothingType, rowSmoothingFactor); myCCS->setSmoothingFactor(smoothingType, colSmoothingFactor); for (int r = 0; r < numRow; r++) beforeRowCL[r] = rowCL[r]; computeRowCentroid(); reassignRC(); for (int r = 0; r < numRow; r++) afterRowCL[r] = rowCL[r]; computeAcompressed(); computeMarginal(); computeObjectiveFunction(); checkDumpLevel4BatchUpdate("row", numIteration);//------------ for (int r = 0; r < numRow; r++) rowCL[r] = beforeRowCL[r]; computeAcompressed(); computeMarginal(); for (int r = 0; r < numRow; r++) rowCL[r] = afterRowCL[r];//------------// for (int c = 0; c < numCol; c++)// beforeColCL[c] = colCL[c]; computeColCentroid(); reassignCC(); computeAcompressed(); computeMarginal(); computeObjectiveFunction(); checkDumpLevel4BatchUpdate("col", numIteration); rowSmoothingFactor *= myCRS->getAnnealingFactor(); colSmoothingFactor *= myCCS->getAnnealingFactor(); } while ((oldObjValue - objValue) > (rowBatchUpdateThreshold * mutualInfo)); delete [] beforeRowCL; delete [] afterRowCL;// delete [] beforeColCL; checkDumpLevel4BatchUpdate("end");}void Itcc::doBatchUpdate4VariationII(){ checkDumpLevel4BatchUpdate("begin"); int numIteration = 0; double oldObjValue; double tempRowSmoothingFactor = rowSmoothingFactor, tempColSmoothingFactor = colSmoothingFactor; myCRS->setSmoothingFactor(smoothingType, tempRowSmoothingFactor); myCCS->setSmoothingFactor(smoothingType, tempColSmoothingFactor); do { numIteration++; myCRS->setSmoothingFactor(smoothingType, tempRowSmoothingFactor); oldObjValue = objValue; computeRowCentroid(); reassignRC(); computeAcompressed(); computeMarginal(); computeObjectiveFunction(); checkDumpLevel4BatchUpdate("row", numIteration); tempRowSmoothingFactor *= myCRS->getAnnealingFactor(); } while ((oldObjValue - objValue) > (rowBatchUpdateThreshold * mutualInfo)); numIteration = 0; tempRowSmoothingFactor = rowSmoothingFactor; myCRS->setSmoothingFactor(smoothingType, tempRowSmoothingFactor); do { numIteration++; myCCS->setSmoothingFactor(smoothingType, tempColSmoothingFactor); oldObjValue = objValue; computeColCentroid(); reassignCC(); computeAcompressed(); computeMarginal(); computeObjectiveFunction(); checkDumpLevel4BatchUpdate("col", numIteration); tempColSmoothingFactor *= myCCS->getAnnealingFactor(); } while ((oldObjValue - objValue) > (colBatchUpdateThreshold * mutualInfo)); colSmoothingFactor = tempColSmoothingFactor; checkDumpLevel4BatchUpdate("end");}/*// It doesn't guarantee the monotonic decrese of objective function values.void Itcc::doBatchUpdate4VariationIII(){ checkDumpLevel4BatchUpdate("begin"); int numIteration = 0; int *beforeRowCL = new int[numRow]; int *afterRowCL = new int[numRow]; double oldObjValue; double tempRowSmoothingFactor = rowSmoothingFactor, tempColSmoothingFactor = colSmoothingFactor; for (int r = 0; r < numRow; r++) beforeRowCL[r] = rowCL[r]; myCRS->setSmoothingFactor(smoothingType, tempRowSmoothingFactor); myCCS->setSmoothingFactor(smoothingType, tempColSmoothingFactor); do { numIteration++; myCRS->setSmoothingFactor(smoothingType, tempRowSmoothingFactor); oldObjValue = objValue;// for (int r = 0; r < numRow; r++)// beforeRowCL[r] = rowCL[r]; computeRowCentroid(); reassignRC(); for (int r = 0; r < numRow; r++) afterRowCL[r] = rowCL[r]; computeAcompressed(); computeMarginal(); computeObjectiveFunction(); checkDumpLevel4BatchUpdate("row", numIteration); tempRowSmoothingFactor *= myCRS->getAnnealingFactor(); } while ((oldObjValue - objValue) > (rowBatchUpdateThreshold * mutualInfo));//------------ for (int r = 0; r < numRow; r++) rowCL[r] = beforeRowCL[r]; computeAcompressed(); computeMarginal(); for (int r = 0; r < numRow; r++) rowCL[r] = afterRowCL[r];//------------ numIteration = 0; tempRowSmoothingFactor = rowSmoothingFactor; myCRS->setSmoothingFactor(smoothingType, tempRowSmoothingFactor); do { numIteration++; myCCS->setSmoothingFactor(smoothingType, tempColSmoothingFactor); oldObjValue = objValue; computeColCentroid(); reassignCC(); computeAcompressed(); computeMarginal(); computeObjectiveFunction(); checkDumpLevel4BatchUpdate("col", numIteration); tempColSmoothingFactor *= myCCS->getAnnealingFactor(); } while ((oldObjValue - objValue) > (colBatchUpdateThreshold * mutualInfo)); colSmoothingFactor = tempColSmoothingFactor; delete [] beforeRowCL; delete [] afterRowCL; checkDumpLevel4BatchUpdate("end");}*/void Itcc::doBatchUpdate4VariationIII(){ checkDumpLevel4BatchUpdate("begin"); int numIteration = 0; double oldObjValue; do { numIteration++; myCRS->setSmoothingFactor(smoothingType, rowSmoothingFactor); myCCS->setSmoothingFactor(smoothingType, colSmoothingFactor); oldObjValue = objValue; if (randNumGenerator.GetUniform() > SELECTION_PROBABILITY){ computeRowCentroid(); reassignRC(); computeAcompressed(); computeMarginal(); computeObjectiveFunction(); checkDumpLevel4BatchUpdate("row", numIteration); } else { computeColCentroid(); reassignCC(); computeAcompressed(); computeMarginal(); computeObjectiveFunction(); checkDumpLevel4BatchUpdate("col", numIteration); } rowSmoothingFactor *= myCRS->getAnnealingFactor(); colSmoothingFactor *= myCCS->getAnnealingFactor(); } while ((oldObjValue - objValue) > (rowBatchUpdateThreshold * mutualInfo)); checkDumpLevel4BatchUpdate("end");}void Itcc::doBatchUpdate4VariationIV(){ checkDumpLevel4BatchUpdate("begin"); int numIteration = 0; double oldObjValue; do { numIteration++; myCRS->setSmoothingFactor(smoothingType, rowSmoothingFactor); myCCS->setSmoothingFactor(smoothingType, colSmoothingFactor); if (randNumGenerator.GetUniform() > SELECTION_PROBABILITY){ do { oldObjValue = objValue; computeRowCentroid(); reassignRC(); computeAcompressed(); computeMarginal(); computeObjectiveFunction(); checkDumpLevel4BatchUpdate("row", numIteration); } while ((oldObjValue - objValue) > (MULTIPLE_FACTOR * rowBatchUpdateThreshold * mutualInfo)); } else { do { oldObjValue = objValue; computeColCentroid(); reassignCC(); computeAcompressed(); computeMarginal(); computeObjectiveFunction(); checkDumpLevel4BatchUpdate("col", numIteration); } while ((oldObjValue - objValue) > (MULTIPLE_FACTOR * colBatchUpdateThreshold * mutualInfo)); } rowSmoothingFactor *= myCRS->getAnnealingFactor(); colSmoothingFactor *= myCCS->getAnnealingFactor(); } while ((oldObjValue - objValue) > (rowBatchUpdateThreshold * mutualInfo)); checkDumpLevel4BatchUpdate("end");}double Itcc::rowClusterQuality(double *row, double rowP, double *colP){ double rcq = 0; for(int cc = 0; cc < numColCluster; cc++) if (row[cc] > 0) rcq += row[cc] * log(row[cc] / (rowP * colP[cc])); return rcq / log(2.0);}double Itcc::colClusterQuality(double *col, double colP, double *rowP){ double ccq = 0; for(int rc = 0; rc < numRowCluster; rc++) if (col[rc] > 0) ccq += col[rc] * log(col[rc] / (colP * rowP[rc]));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -