⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tools.cc

📁 一种聚类算法,名字是cocluster
💻 CC
📖 第 1 页 / 共 5 页
字号:
    case DIM_MATRIX_SEPARATE_FORMAT:      sprintf(tempFilename, "%s%s", filename, "_dim");      dimFile.open(tempFilename, ios::in);      if (!dimFile.is_open()){        cout << "  !!! Dimension file open error: " << tempFilename << " !!!" << endl;        exit(EXIT_FAILURE);      }      dimFile >> mat->numRow >> mat->numCol;      dimFile.getline(whole_line, DEFAULT_STRING_LENGTH, '\n');      inputFile.open(filename, ios::in);      if (!inputFile.is_open()){        cout << "  !!! Input file open error: " << filename << " !!!" << endl;        exit(EXIT_FAILURE);      }      break;    case DIM_MATRIX_TOGETHER_FORMAT:      inputFile.open(filename, ios::in);      if (!inputFile.is_open()){        cout << "  !!! Input file open error: " << filename << " !!!" << endl;        exit(EXIT_FAILURE);      }      inputFile >> mat->numRow >> mat->numCol;      inputFile.getline(whole_line, DEFAULT_STRING_LENGTH, '\n');      break;    default:      cout << "  !!! Incorrect input format type: " << formatType << " !!!" << endl;      exit(EXIT_FAILURE);      break;  }                  //cout<<mat->numRow<<" "<< mat->numCol<<endl;  mat->numVal = mat->numRow * mat->numCol;  mat->value = new double *[mat->numRow];  for (int i = 0; i < mat->numRow; i++)    mat->value[i]= new double[mat->numCol];  memoryUsed += (mat->numRow * mat->numCol) * sizeof(double);    cout << "  Reading matrix file ... " << filename << endl;  switch (matrixType){    case DENSE_MATRIX:      numEmptyCol = 0;      for (int i = 0; i < mat->numRow; i++)        for (int j = 0; j < mat->numCol; j++)          inputFile >> mat->value[i][j];      break;    case DENSE_MATRIX_TRANS:				// not used...      numEmptyCol = 0;      for (int i = 0; i < mat->numCol; i++)        for (int j=0; j < mat->numRow; j++)          inputFile >> mat->value[j][i];      break;    default:      break;  }  dimFile.close();  inputFile.close();  emptyColId = new int[numEmptyCol+1];  emptyColId[0] = mat->numCol;  return  emptyColId;}int *readMatrix(char *fname, sparseStruct *mat, int &numEmptyCol, int formatType, char *scalingType)// read in a sparse matrix from files into 'mat' and return #empty vectors and an array of empty vector IDs{  char filename[FILENAME_LENGTH];  //clock_t start_clock, finish_clock;  sprintf(filename, "%s%s", fname, "_dim");  std::ifstream dimFile(filename);  if (dimFile == 0)    cout << "  !!! File open error: " << filename << " !!!" << endl << endl;  sprintf(filename, "%s%s", fname, "_row_ccs");  std::ifstream rowPtrFile(filename);  if (rowPtrFile == 0)    cout << "  !!! File open error: " << filename << " !!!" << endl << endl;  sprintf(filename, "%s%s", fname, "_col_ccs");  std::ifstream colIdxFile(filename);  if (colIdxFile == 0)    cout << "  !!! File open error: " << filename << " !!!" << endl << endl;  sprintf(filename, "%s%s", fname, "_");  if (formatType == 0)    sprintf(filename, "%s%s", filename, TXX_SCALING);  else    sprintf(filename, "%s%s", filename, TFN_SCALING);    sprintf(filename, "%s%s", filename, "_nz");  std::ifstream valFile(filename);  if (valFile == 0)      cout << "  !!! File open error: " << filename << " !!!" << endl;  if (dimFile == 0 || rowPtrFile == 0 || colIdxFile == 0 || valFile == 0){    cout << "  !!! Matrix file " << fname << "_* has missing file(s) !!!" << endl;    exit(EXIT_FAILURE);  }  //data.width(MAX_DESC_STR_LENGTH);  //data >> mat->descString;  //data >> mat->numCol >> mat->numRow >> mat->numVal;  //start_clock = clock();  cout << "  Reading dimension file ... " << endl;  dimFile >> mat->numRow >> mat->numCol >> mat->numVal;  dimFile.close();  mat->colPtr = new int[mat->numCol+1];  mat->rowIdx = new int[mat->numVal];  mat->value = new double[mat->numVal];  //space used for storing the sparse matrix is as follows  memoryUsed += (mat->numCol + 1 + mat->numVal) * sizeof(int) + mat->numVal * sizeof(double);  //it is necessary to handle empty vectors separately  int pre = -1;  int *tempEmptyColId = new int[mat->numCol], *emptyColId;  numEmptyCol = 0;  cout << "  Reading column pointer file ... " << endl;  for (int i = 0; i < mat->numCol+1; i++){    colIdxFile >> (mat->colPtr)[i];    if ((mat->colPtr)[i] == pre){      tempEmptyColId[numEmptyCol] = i - 1;      numEmptyCol++;    }    pre = (mat->colPtr)[i];  }  colIdxFile.close();  emptyColId = new int[numEmptyCol+1];  for(int i = 0; i < numEmptyCol; i++)    emptyColId[i] = tempEmptyColId[i];  emptyColId[numEmptyCol] = mat->numCol;  delete [] tempEmptyColId;  cout << "  Reading row index file ... " << endl;  for (int i = 0; i < mat->numVal; i++)    rowPtrFile >> (mat->rowIdx)[i];  rowPtrFile.close();  cout << "  Reading non-zero value file ... " << endl;  for (int i = 0; i < mat->numVal; i++)    valFile >> (mat->value)[i];  valFile.close();  cout << endl;  //finish_clock = clock();  //cout << "Reading file time: " << (finish_clock - start_clock) / 1e6 << " seconds." << endl;  if (numEmptyCol == 0)    cout << "  !!! No empty col found !!!" << endl;  else {    cout << "  !!! " << numEmptyCol << " empty col(s) found !!!" << endl;    for(int i = 0; i < numEmptyCol; i++)      cout << emptyColId[i] << " ";    cout << endl;  }  return  emptyColId;}/*void myReadMatrix(commandLineArgument myCLA, sparseStruct &sparseCCS, sparseStruct &sparseCRS, denseStruct &denseMat){  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:    default:      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;  }}*//*void myPreprocessMatrix(commandLineArgument myCLA, sparseStruct &sparseCCS, sparseStruct &sparseCRS, denseStruct &denseMat, Matrix *myCCS, Matrix *myCRS){  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;  }  }*//*void myConstructCoclustering(commandLineArgument myCLA, Matrix *myCCS, Matrix *myCRS, Coclustering *myCC){  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;  }}*/// Read column class/cluster labels from the file whose first row contains num, // and each of the other line contains a label (i.e., one label in a row).int readLabel(char *filename, int numData, int *label, int classOffsetType){  char whole_line[DEFAULT_STRING_LENGTH];  int maxLabel = 0, num, numClass = 0;//  cout << "  Reading class label file ... " << filename << endl;  std::ifstream labelFile(filename);  if (!labelFile.is_open()){    if (strcmp(filename, "") != 0){      cout << "  !!! File open error: " << filename << " !!!" << endl;      exit(EXIT_FAILURE);    }  }  labelFile >> num;  labelFile.getline(whole_line, DEFAULT_STRING_LENGTH, '\n');	// skip all the other columns in the first line  if (num != numData){    cout << "  !!! Incorrect number of class labels in: " << filename << " !!!" << endl;    exit(EXIT_FAILURE);  }//  if (!isSilent)	// not used...    cout << "  Reading class label file ... " << filename << endl;  for (int i = 0; i < num; i++){    labelFile >> label[i];    labelFile.getline(whole_line, DEFAULT_STRING_LENGTH, '\n');    if (label[i] > maxLabel)      maxLabel = label[i];  }  labelFile.close();  if (classOffsetType == START_FROM_0)     numClass = maxLabel + 1;  else {    numClass = maxLabel;    for (int i = 0; i < num; i++)      label[i]--;  }  return numClass;}// Read row or column class/cluster labels from the file, // where each line contains either row or column labels.// So, if the file consists of many lines, # of lines == # of label sets.void readLabel(char *filename, int numLabel, int *label, int &numClass, int classOffsetType){//  cout << "  Reading class label file ... " << filename << endl;  std::ifstream labelFile(filename);  if (!labelFile.is_open()){    if (strcmp(filename, "") != 0)      cout << "  File open error: " << filename << endl;    exit(EXIT_FAILURE);  }  readLabel(labelFile, numLabel, label, numClass, classOffsetType);  labelFile.close();}// Read row or column class/cluster labels from the file stream, // where each line contains either row or column labels, // So, it the file consists of many lines, # of lines == # of label sets.//(i.e., it may contains several sets of labels.)void readLabel(istream &labelFile, int numLabel, int *label, int &numClass, int classOffsetType){//  cout << "  Reading class label file ... " << filename << endl;//  if (!isSilent)		// not used...    cout << "  Reading class label file ... " << endl;    int maxLabel = 0;  for (int i = 0; i < numLabel; i++){    labelFile >> label[i];    if (label[i] > maxLabel)      maxLabel = label[i];  }  if (classOffsetType == START_FROM_0)     numClass = maxLabel + 1;  else {    numClass = maxLabel;    for (int i = 0; i < numLabel; i++)      label[i]--;  }}// Read row and column class/cluster labels from the file consisting of two lines, // first line for row labels and second line for col labels.void readLabel(char *filename, int numRow, int numCol, int *rowLabel, int *colLabel, int &numRowClass, int &numColClass, int classOffsetType){//  cout << "  Reading class label file ... " << filename << endl;  std::ifstream labelFile(filename);  if (!labelFile.is_open()){    if (strcmp(filename, "") != 0)      cout << "  File open error: " << filename << endl;    exit(EXIT_FAILURE);  }  readLabel(labelFile, numRow, numCol, rowLabel, colLabel, numRowClass, numColClass, classOffsetType);// Otherwise, the following two lines are equivalent to the line above.//  readLabel(labelFile, numRow, rowLabel, numRowClass, classOffsetType);//  readLabel(labelFile, numCol, colLabel, numColClass, classOffsetType);  labelFile.close();}// Read row and column class/cluster labels from the file stream, // where the first line for row labels and second line for col labels, // and so on. (i.e., it may contains several sets of labels.)void readLabel(istream &labelFile, int numRow, int numCol, int *rowLabel, int *colLabel, int &numRowClass, int &numColClass, int classOffsetType){//  cout << "  Reading class label file ... " << filename << endl;//  if (!isSilent)		// not used...    cout << "  Reading class label file ... " << endl;    int maxLabel = 0;  for (int i = 0; i < numRow; i++){    labelFile >> rowLabel[i];    if (rowLabel[i] > maxLabel)      maxLabel = rowLabel[i];  }  if (classOffsetType == START_FROM_0)     numRowClass = maxLabel + 1;  else {    numRowClass = maxLabel;    for (int i = 0; i < numRow; i++)      rowLabel[i]--;  }  maxLabel = 0;  for (int i = 0; i < numCol; i++){    labelFile >> colLabel[i];    if (colLabel[i] > maxLabel)      maxLabel = colLabel[i];  }  if (classOffsetType == START_FROM_0)     numColClass = maxLabel + 1;    else {    numColClass = maxLabel;    for (int i = 0; i < numCol; i++)      colLabel[i]--;  }}/* * Description:   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -