📄 cocluster.cc
字号:
/* Cocluster.cc the main file for co-clustering programs Copyright (c) 2005, 2006 by Hyuk Cho Copyright (c) 2003, 2004 by Hyuk Cho, Yuqiang Guan, and Suvrit Sra {hyukcho, yguan, suvrit}@cs.utexas.edu*/#include <fstream>#include <cmath>#include <iomanip>#include <time.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h>#include "MatrixVector.h"#include "TimerUtility.h"#include "Tools.h"#include "Itcc.h"#include "MssrIcc.h"#include "MssrIIcc.h"using namespace std;long memoryUsed = 0l;int main(int argc, char **argv){ commandLineArgument myCLA; //------------------------------------------------------------------------------ setCommandLine(myCLA); // set default command line arguments getCommandLine(argc, argv, myCLA); // get command line arguments//------------------------------------------------------------------------------ if (!myCLA.havingArgument) printHelp(); if (myCLA.numInvalidCLA != 0) exit(EXIT_FAILURE); if (myCLA.algorithmType == INFORMATION_THEORETIC_CC && myCLA.takingReverse){ cout << " Taking reverse is invalid for ITCC..." << endl << endl; exit(EXIT_FAILURE); } if (myCLA.takingReverse && myCLA.coclusterOffsetType == START_FROM_0){ cout << " Taking reverse and output labels starting from 0 are not valid..." << endl << endl; exit(EXIT_FAILURE); }// strcat(myCLA.dumpFilename, DUMP_FILENAME_SUFFIX);// strcat(myCLA.objectiveFilename, OBJECTIVE_FILENAME_SUFFIX);// strcat(myCLA.coclusterFilename, COCLUSTER_FILENAME_SUFFIX);// makeFilename(myCLA.objectiveFilename, OBJECTIVE_FILENAME_SUFFIX, myCLA);// makeFilename(myCLA.coclusterFilename, COCLUSTER_FILENAME_SUFFIX, myCLA);//------------------------------------------------------------------------------ sparseStruct sparseCCS; sparseStruct sparseCRS; denseStruct denseMat; TimerUtil runTime; switch (myCLA.inputMatrixType){ case DENSE_MATRIX: case DENSE_MATRIX_TRANS: // not used... myCLA.emptyColId = readMatrix(myCLA.inputFilename, &denseMat, myCLA.numEmptyCol, myCLA.inputFormatType, myCLA.inputMatrixType); assert(((myCLA.numRowCluster <= denseMat.numRow) && (myCLA.numColCluster <= denseMat.numCol)) && (myCLA.numRowCluster != denseMat.numRow || myCLA.numColCluster != denseMat.numCol)); assert((myCLA.rowLocalSearchLength < denseMat.numRow) && (myCLA.colLocalSearchLength < denseMat.numCol)); memoryUsed += denseMat.numRow * denseMat.numCol * sizeof(double); break; case SPARSE_MATRIX: myCLA.emptyColId = readMatrix(myCLA.inputFilename, &sparseCCS, myCLA.numEmptyCol, myCLA.inputFormatType, myCLA.scalingType); assert(((myCLA.numRowCluster <= sparseCCS.numRow) && (myCLA.numColCluster <= sparseCCS.numCol)) && (myCLA.numRowCluster != sparseCCS.numRow || myCLA.numColCluster != sparseCCS.numCol)); assert((myCLA.rowLocalSearchLength < sparseCCS.numRow) && (myCLA.colLocalSearchLength < sparseCCS.numCol)); sparseCRS.colPtr = new int[sparseCCS.numRow+1]; sparseCRS.rowIdx = new int[sparseCCS.numVal]; sparseCRS.value = new double[sparseCCS.numVal]; sparseCRS.numCol = sparseCCS.numRow; sparseCRS.numRow = sparseCCS.numCol; sparseCRS.numVal = sparseCCS.numVal; convertSparse2Sparse(sparseCCS.numCol, sparseCCS.numRow, sparseCCS.numVal, sparseCCS.colPtr, sparseCCS.rowIdx, sparseCCS.value, sparseCRS.colPtr, sparseCRS.rowIdx, sparseCRS.value); // checkConvertSparse2Sparse(sparseCCS.numCol, sparseCCS.numRow, sparseCCS.numVal, sparseCCS.colPtr, sparseCCS.rowIdx, sparseCCS.value, sparseCRS.colPtr, sparseCRS.rowIdx, sparseCRS.value); memoryUsed += (sparseCCS.numCol + sparseCCS.numRow + 2 * sparseCCS.numVal) * sizeof(int) + 2 * sparseCCS.numVal * sizeof(double); break; default: break; }//------------------------------------------------------------------------------//------------------------------------------------------------------------------ Matrix *myCCS = NULL; Matrix *myCRS = NULL; Coclustering *myCC = NULL; switch (myCLA.inputMatrixType){ case DENSE_MATRIX: myCCS = new DenseMatrix(denseMat.numRow, denseMat.numCol, denseMat.value); myCRS = myCCS; if (myCLA.algorithmType == INFORMATION_THEORETIC_CC) myCCS->preprocess(); break; case SPARSE_MATRIX: myCCS = new SparseMatrix(sparseCCS.numRow, sparseCCS.numCol, sparseCCS.numVal, sparseCCS.value, sparseCCS.rowIdx, sparseCCS.colPtr); if (myCLA.algorithmType == INFORMATION_THEORETIC_CC) myCCS->preprocess(); myCRS = new SparseMatrix(sparseCRS.numRow, sparseCRS.numCol, sparseCRS.numVal, sparseCRS.value, sparseCRS.rowIdx, sparseCRS.colPtr); if (myCLA.algorithmType == INFORMATION_THEORETIC_CC) myCRS->preprocess(); break; default: break; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ switch (myCLA.algorithmType){ case INFORMATION_THEORETIC_CC: myCC = new Itcc(myCCS, myCRS, myCLA); myCC->classPrefix = ITCC_CLASS; break; case MINIMUM_SUM_SQUARE_RESIDUE_I_CC: myCC = new MssrIcc(myCCS, myCRS, myCLA); myCC->classPrefix = MSSRICC_CLASS; break; case MINIMUM_SUM_SQUARE_RESIDUE_II_CC: myCC = new MssrIIcc(myCCS, myCRS, myCLA); myCC->classPrefix = MSSRIICC_CLASS; break; default: myCC = new Itcc(myCCS, myCRS, myCLA); myCC->classPrefix = ITCC_CLASS; break; }//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ if (myCLA.externalValidityType == ROW_EXTERNAL_VALIDITY){ myCLA.rowClassLabel = new int[myCCS->getNumRow()]; myCLA.numRowClass = readLabel(myCLA.rowClassFilename, myCCS->getNumRow(), myCLA.rowClassLabel, myCLA.classOffsetType); } if (myCLA.externalValidityType == COL_EXTERNAL_VALIDITY){ myCLA.colClassLabel = new int[myCCS->getNumCol()]; myCLA.numColClass = readLabel(myCLA.colClassFilename, myCCS->getNumCol(), myCLA.colClassLabel, myCLA.classOffsetType); } if (myCLA.externalValidityType == BOTH_EXTERNAL_VALIDITY){ myCLA.rowClassLabel = new int[myCCS->getNumRow()]; myCLA.colClassLabel = new int[myCCS->getNumRow()]; readLabel(myCLA.bothClassFilename, myCCS->getNumRow(), myCCS->getNumCol(), myCLA.rowClassLabel, myCLA.colClassLabel, myCLA.numRowClass, myCLA.numColClass, myCLA.classOffsetType); }//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ outputConstructor(myCLA, myCC->classPrefix, myCC->dumpFile, myCC->statisticsFile); if (myCLA.numRun >= 1){ int *numPingPong = new int[myCLA.numRun]; int *numReversedRow = NULL; double *initialObjectVal4RC = NULL, *initialObjectVal4CC = NULL; double *finalObjectVal4RC = NULL, *finalObjectVal4CC = NULL; double *numEmptyRC = new double[myCLA.numRun];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -