TEST(Util, RandomOrderTest) {
    VInt tmp;
    RandomOrder(100, 1000, &tmp);
    SInt dic;
    ToSet(tmp, &dic);
    EXPECT_EQ(100, dic.size());
    int c = 0;
    for (size_t i = 0; i < tmp.size(); i++) {
        if (tmp[i] == i) {
            c++;
        }
    }
    EXPECT_LT(c, 3);
}
Пример #2
0
void VarRTM::Load(StrC &net_path, StrC &cor_path, int times) {
  ReadData(net_path, &net, &held_out_net_);
  cor.LoadData(cor_path);

  SpMat all_network;
  ReadData(net_path, &all_network);
  TripleVec vec;
  for (int d = 0;d < all_network.cols(); d++) { 
    SInt observed;
    for (SpMatInIt it(all_network, d); it; ++it) {
      int row = it.row();
      observed.insert(row);
    }
    int observed_size = observed.size();
    for (int i = 0;i < observed_size * times; ++i) {
      int k = Random(all_network.rows());
      if(observed.find(k) == observed.end()) {
        vec.push_back(Triple(k, d, -1));
        observed.insert(k);
      }
    }
  }
  for (int d = 0;d < held_out_net_.cols(); d++) {
    for (SpMatInIt it(held_out_net_, d); it; ++it) {
      vec.push_back(Triple(it.row(), d, 1));
    }
  }
  held_out_net_.setFromTriplets(vec.begin(), vec.end());

  LOG(INFO) << cor_path;
  LOG(INFO) << cor.Len();
  LOG(INFO) << net.size();
  LOG(INFO) << held_out_net_.size(); 
}
Пример #3
0
Str Join(const SInt &data, StrC &del) {
  return Join(data.begin(), data.end(), del);
}