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

📄 densematrix.cc

📁 一种聚类算法,名字是cocluster
💻 CC
📖 第 1 页 / 共 3 页
字号:
  nrm = sqrt(dvec_l2normsq(dim, v));  //if(nrm != 0)   //  dvec_scale(1.0 / nrm, dim, v);}*/double DenseMatrix::squaredFNorm()  /* compute the squared Frobenius norm of the dense matrix.   */{  double temp = 0;  for (int r = 0; r < numRow; r++)    for (int c = 0; c < numCol; c++){      double tempValue = value[r][c];      temp += tempValue * tempValue;    }  return temp;}double DenseMatrix::squaredL2Norm4Row(int r)  /* compute the squared L2 norm of row i in a matrix   */{  double temp = 0;  for (int c = 0; c < numCol; c++){    double tempValue = value[r][c];    temp += tempValue * tempValue;  }  return temp;}double DenseMatrix::squaredL2Norm4Col(int c)  /* compute the squared L2 norm of column j in a matrix   */{  double temp = 0;  for (int r = 0; r < numRow; r++){    double tempValue = value[r][c];    temp += tempValue * tempValue;  }  return temp;}double DenseMatrix::computeRowDistance(int rowId, int rowCluster, int *colCL, double **cM, double rowQuality4Compressed){  double temp = 0;  for (int c = 0; c < numCol; c++)    temp += value[rowId][c] * cM[rowCluster][colCL[c]];  return (-2 * temp + rowQuality4Compressed);  }double DenseMatrix::computeColDistance(int colId, int colCluster, int *rowCL, double **cM, double colQuality4Compressed){  double temp = 0;  for (int r = 0; r < numRow; r++)    temp += value[r][colId] * cM[rowCL[r]][colCluster];  return (-2 * temp + colQuality4Compressed);  }double DenseMatrix::computeRowDistance(int rowId, int rowCluster, int *colCL, double **cM, double rowQuality4Compressed, bool *isReversed){  double temp = 0;  if (isReversed[rowId])    for (int c = 0; c < numCol; c++)      temp += (0 - value[rowId][c]) * cM[rowCluster][colCL[c]];  else    for (int c = 0; c < numCol; c++)      temp += value[rowId][c] * cM[rowCluster][colCL[c]];  return (-2 * temp + rowQuality4Compressed);  }double DenseMatrix::computeColDistance(int colId, int colCluster, int *rowCL, double **cM, double colQuality4Compressed, bool *isReversed){  double temp = 0;  for (int r = 0; r < numRow; r++){    if (isReversed[r])      temp += (0 - value[r][colId]) * cM[rowCL[r]][colCluster];    else      temp += value[r][colId] * cM[rowCL[r]][colCluster];  }  return (-2 * temp + colQuality4Compressed);  }//MSSRIICCvoid DenseMatrix::computeRowCentroid(int numRowCluster, int *rowCL, double **rowCentroid){  for (int rc = 0; rc < numRowCluster; rc++)    for (int c = 0; c < numCol; c++)      rowCentroid[rc][c] = 0;  for (int r = 0; r < numRow; r++)    for (int c = 0; c < numCol; c++)      rowCentroid[rowCL[r]][c] += value[r][c];}void DenseMatrix::computeRowCentroid(int numRowCluster, int *rowCL, double **rowCentroid, bool *isReversed){  for (int rc = 0; rc < numRowCluster; rc++)    for (int c = 0; c < numCol; c++)      rowCentroid[rc][c] = 0;  for (int r = 0; r < numRow; r++)    if (isReversed[r])      for (int c = 0; c < numCol; c++)        rowCentroid[rowCL[r]][c] -= value[r][c];    else      for (int c = 0; c < numCol; c++)        rowCentroid[rowCL[r]][c] += value[r][c];}void DenseMatrix::computeColCentroid(int numColCluster, int *colCL, double **colCentroid){  for (int cc = 0; cc < numColCluster; cc++)    for (int r = 0; r < numRow; r++)      colCentroid[cc][r] = 0;  for (int r = 0; r < numRow; r++)    for (int c = 0; c < numCol; c++)      colCentroid[colCL[c]][r] += value[r][c];}void DenseMatrix::computeColCentroid(int numColCluster, int *colCL, double **colCentroid, bool *isReversed){  for (int cc = 0; cc < numColCluster; cc++)    for (int r = 0; r < numRow; r++)      colCentroid[cc][r] = 0;  for (int r = 0; r < numRow; r++)    if (isReversed[r])      for (int c = 0; c < numCol; c++)        colCentroid[colCL[c]][r] -= value[r][c];    else      for (int c = 0; c < numCol; c++)        colCentroid[colCL[c]][r] += value[r][c];}/*double DenseMatrix::computeRowDistance(int rowId, int *colCL, double *colCentroid, double *mAR, double rowQuality4Compressed) {  double temp = 0;  for (int j = 0; j < numCol; j++)    temp += (value[rowId][j] - colCentroid[colCL[j]]) * mAR[j];  return (-2 * temp + rowQuality4Compressed);  }double DenseMatrix::computeColDistance(int colId, int *rowCL, double *rowCentroid, double *nAC, double colQuality4Compressed){  double temp = 0;  for (int i = 0; i < numRow; i++)    temp += (value[i][colId] - rowCentroid[rowCL[i]]) * nAC[i];  return (-2 * temp + colQuality4Compressed);  }*/double DenseMatrix::computeRowDistance(int rowId, int rowCluster, int *rowCL, int *colCL, double **cM){  double temp = 0;  for (int c = 0; c < numCol; c++){    double tempValue = value[rowId][c] - cM[rowCluster][colCL[c]];    temp += tempValue * tempValue;  }  return temp;}double DenseMatrix::computeColDistance(int colId, int colCluster, int *rowCL, int *colCL, double **cM){  double temp = 0;  for (int r = 0; r < numRow; r++){    double tempValue = value[r][colId] - cM[colCluster][rowCL[r]];    temp += tempValue * tempValue;  }  return temp;}void DenseMatrix::computeRowAP(int rowId, double **colCentroid, int *colCL, double *rowAP){  for (int c = 0; c < numCol; c++)    rowAP[c] = value[rowId][c];  for (int c = 0; c < numCol; c++)    rowAP[c] -= colCentroid[colCL[c]][rowId];}void DenseMatrix::computeRowAP(int rowId, double **colCentroid, int *colCL, double *rowAP, bool *isReversed){  if (isReversed[rowId]){    for (int c = 0; c < numCol; c++)      rowAP[c] = 0;    for (int c = 0; c < numCol; c++)      rowAP[c] -= value[rowId][c];  } else     for (int c = 0; c < numCol; c++)      rowAP[c] = value[rowId][c];  for (int c = 0; c < numCol; c++)    rowAP[c] -= colCentroid[colCL[c]][rowId];}void DenseMatrix::computeColAP(int colId, double **rowCentroid, int *rowCL, double *colAP){  for (int r = 0; r < numRow; r++)    colAP[r] = value[r][colId];  for (int r = 0; r < numRow; r++)    colAP[r] -= rowCentroid[rowCL[r]][colId];}void DenseMatrix::computeColAP(int colId, double **rowCentroid, int *rowCL, double *colAP, bool *isReversed){  for (int r = 0; r < numRow; r++)    colAP[r] = 0;  for (int r = 0; r < numRow; r++)    if (isReversed[r])      colAP[r] -= value[r][colId];      else      colAP[r] = value[r][colId];  for (int r = 0; r < numRow; r++)    colAP[r] -= rowCentroid[rowCL[r]][colId];}void DenseMatrix::subtractRow(double *x, int r){  for (int c = 0; c < numCol; c++)    x[c] -= value[r][c];}void DenseMatrix::subtractCol(double *x, int c){  for (int r = 0; r < numRow; r++)    x[r] -= value[r][c];}void DenseMatrix::addRow(double *x, int r){  for (int c = 0; c < numCol; c++)    x[c] += value[r][c];}void DenseMatrix::addCol(double *x, int c){  for (int r = 0; r < numRow; r++)    x[r] += value[r][c];}// for reversed rowsvoid DenseMatrix::subtractRow(double *x, int r, bool *isReversed){  if (isReversed[r])    for (int c = 0; c < numCol; c++)      x[c] += value[r][c];  else    for (int c = 0; c < numCol; c++)      x[c] -= value[r][c];}void DenseMatrix::subtractCol(double *x, int c, bool *isReversed){  for (int r = 0; r < numRow; r++)    if (isReversed[r])      x[r] += value[r][c];    else      x[r] -= value[r][c];}void DenseMatrix::addRow(double *x, int r, bool *isReversed){  if (isReversed[r])    for (int c = 0; c < numCol; c++)      x[c] -= value[r][c];  else    for (int c = 0; c < numCol; c++)      x[c] += value[r][c];}void DenseMatrix::addCol(double *x, int c, bool *isReversed){  for (int r = 0; r < numRow; r++)    if (isReversed[r])      x[r] -= value[r][c];    else      x[r] += value[r][c];}void DenseMatrix::subtractCol(double **x, int col, int j, int *rowCL, bool *isReversed){  for (int i = 0; i < numRow; i++)    if (isReversed[i])      x[rowCL[i]][col] += value[i][j];    else      x[rowCL[i]][col] -= value[i][j];}void DenseMatrix::subtractCol(double *x, int j, int *rowCL, bool *isReversed){  for (int i = 0; i < numRow; i++)    if (isReversed[i])      x[rowCL[i]] += value[i][j];    else      x[rowCL[i]] -= value[i][j];}void DenseMatrix::addCol(double **x, int col, int j, int *rowCL, bool *isReversed){  for (int i = 0; i < numRow; i++)    if (isReversed[i])      x[rowCL[i]][col] -= value[i][j];    else      x[rowCL[i]][col] += value[i][j];}void DenseMatrix::addCol(double *x, int j, int *rowCL, bool *isReversed){  for (int i = 0; i < numRow; i++)    if (isReversed[i])      x[rowCL[i]] -= value[i][j];    else      x[rowCL[i]] += value[i][j];}double DenseMatrix::computeObjectiveFunctionValue(int *rowCL, int *colCL, double **cM){  double temp = 0;  for (int r = 0; r < numRow; r++)    for (int c = 0; c < numCol; c++){      double tempValue = value[r][c] - cM[rowCL[r]][colCL[c]];      temp += tempValue * tempValue;    }  return temp;}  double DenseMatrix::computeObjectiveFunctionValue(int *rowCL, int *colCL, double **cM, bool *isReversed){  double temp = 0;  for (int r = 0; r < numRow; r++){    if (isReversed[r])      for (int c = 0; c < numCol; c++){        double tempValue = (0 - value[r][c]) - cM[rowCL[r]][colCL[c]];        temp += tempValue * tempValue;      }    else      for (int c = 0; c < numCol; c++){        double tempValue = value[r][c] - cM[rowCL[r]][colCL[c]];        temp += tempValue * tempValue;      }  }  return temp;}  double DenseMatrix::computeObjectiveFunctionValue(int *rowCL, int *colCL, double **cM, double **rowCentroid, double **colCentroid){  double temp = 0;  for (int r = 0; r < numRow; r++)    for (int c = 0; c < numCol; c++){      double tempValue = value[r][c] - rowCentroid[rowCL[r]][c] - colCentroid[colCL[c]][r] + cM[rowCL[r]][colCL[c]];      temp += tempValue * tempValue;    }  return temp;}  double DenseMatrix::computeObjectiveFunctionValue(int *rowCL, int *colCL, double **cM, double **rowCentroid, double **colCentroid, bool *isReversed){  double temp = 0;  for (int r = 0; r < numRow; r++){    if (isReversed[r])      for (int c = 0; c < numCol; c++){        double tempValue = (0 - value[r][c]) - rowCentroid[rowCL[r]][c] - colCentroid[colCL[c]][r] + cM[rowCL[r]][colCL[c]];        temp += tempValue * tempValue;      }    else      for (int c = 0; c < numCol; c++){        double tempValue = value[r][c] - rowCentroid[rowCL[r]][c] - colCentroid[colCL[c]][r] + cM[rowCL[r]][colCL[c]];        temp += tempValue * tempValue;      }  }  return temp;}  double DenseMatrix::computeObjectiveFunctionValue4RowCluster(int *rowCL, double **rowCentroid){  double temp = 0, tempValue = 0;  for (int r = 0; r < numRow; r++)    for (int c = 0; c < numCol; c++){      tempValue = value[r][c] - rowCentroid[rowCL[r]][c];      temp += tempValue * tempValue;    }  return temp;}double DenseMatrix::computeObjectiveFunctionValue4ColCluster(int *colCL, double **colCentroid){  double temp = 0, tempValue = 0;  for (int r = 0; r < numRow; r++)    for (int c = 0; c < numCol; c++){      tempValue = value[r][c] - colCentroid[colCL[c]][r];      temp += tempValue * tempValue;    }  return temp;}

⌨️ 快捷键说明

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