Dataset::Dataset(std::string dataset_file) : ratings(read_mtx(std::ifstream(dataset_file), 1).csr()), n_users(ratings.dim1()), n_items(ratings.dim2()), ica(generateICA(n_items)), // n_items * M blooms(mult(ratings, ica, 1)), // n_users * M sim(compute_sim()), sim_dense(to_dense(sim)), max_profile_size(0), uniform_priors(n_items, 1), empirical_priors(compute_item_priors()), bloom_bits_priors(compute_bits_priors()), ratings_dense(to_dense(ratings)), rank(std::min(n_users, n_items)), // full rank colMajorU(ratings.dim1() , rank), diagS(rank), colMajorV(ratings.dim2() , rank) { std::cerr << dataset_file << std::endl; std::cerr << n_users << " users, and " << n_items << " items" << std::endl; // if(graphs[dataset_no] != "null")//(2 == dataset || 5 == dataset || 7 == dataset) // { // std::cerr << graphs[dataset_no] << std::endl; // CompressedFormat graph = read_mtx(std::ifstream(base + graphs[dataset_no])).csr(); // } stack_assert(n_items == ica.dim1()); this->max_profile_size = 0; for(index_t user = 0; user < n_users; user++) this->max_profile_size = std::max(this->max_profile_size, nnz_row(user , ratings.starts())); // SVD smat mat = {this->ratings.dim2()/*!!*/, this->ratings.dim1()/*!!*/, this->ratings.nnz(), const_cast<index_t*>(this->ratings.starts()), const_cast<index_t*>(this->ratings.index()), const_cast<double*>(this->ratings.values())}; SVDVerbosity = 0; SVDRec svd = svdLAS2A(&mat, this->rank); std::cerr << "SVD computed!" << std::endl; // i would take the pointer from SVDRec, but i'd have to remember calling free instead of delete[]. std::copy(svd->S, svd->S + this->rank, this->diagS.get_data()); // svd->Ut is row-major, so it is U col-major, save for V std::copy(svd->Vt/*!!*/->value[0], svd->Vt/*!!*/->value[0] + this->ratings.dim1() * this->rank, this->colMajorU.get_data()); std::copy(svd->Ut/*!!*/->value[0], svd->Ut/*!!*/->value[0] + this->ratings.dim2() * this->rank, this->colMajorV.get_data()); svdFreeSVDRec(svd); }
void read_matrix(idx *nv, idx *ne,idx **xadj, idx **adj, wt **ew, const char *filename){ std::string strfilename(filename); if (endswith(strfilename, ".mtx")){ read_mtx ( filename, nv, ne, xadj, adj, ew,false,false,false); } else if (endswith(strfilename, ".bin")){ read_graph_bin(nv, ne,xadj, adj, ew, filename); } else { throw std::runtime_error ("Reader is not available\n"); } }