Ejemplo n.º 1
0
int main(int argc, char *argv[]) {


  // preprocess data
  NodeFiles node_files;
  std::vector<Block> col_blocks;
  // std::vector<string> in_files;
  AssignData(&node_files, &col_blocks);
  // PreprocessData(node_files, col_blocks, &in_files);

  std::vector<string> in_files = node_files[FLAGS_my_row_rank];
  int nf = in_files.size();

  Block col = col_blocks[FLAGS_my_col_rank];

  RSpMat<size_t> tmp;
  RSpMat<uint32_t> *adjs = new RSpMat<uint32_t>[nf];
  for (int i = 0; i < nf; ++i) {
    // load data
    tmp.Load(in_files[i]);
    tmp.VSlice(col, adjs+i);
  }


  // do actual computing
  // w = alpha * X * w + (1-alpha)*1/n
  // TODO
  CHECK_EQ(nf, 1);
  CHECK(adjs[0].square());

    int f = 0;

    uint32_t* index = adjs[f].index();
    size_t* offset = adjs[f].offset();
    double penalty = (1 - FLAGS_alpha) / (double) adjs[f].rows();

    DVec w = DVec::Ones(col.size()) * penalty;
    DVec u(adjs[f].rows());

  for (int it = 0; it < 40; ++it) {
    for (size_t i = 0; i < adjs[f].rows(); ++i) {
      double v = 0;
      double degree = offset[i+1] - offset[i];
      for (uint32_t j = offset[i]; j < offset[i+1]; ++j) {
        v += w[index[j]] / degree;
      }
      u[i] = v*FLAGS_alpha + penalty;
    }
    LL << "iter " << it << " err " << (u-w).norm() / w.norm()
       << " 1-norm " << w.cwiseAbs().sum();
    w = u;
  }

  return 0;
}