示例#1
0
  MMOutputter_mat(std::string fname, uint start, uint end, std::string comment, std::vector<vertex_data> & latent_factors_inmem, int size = 0)  {
    assert(start < end);
    MM_typecode matcode;
    set_matcode(matcode, R_output_format);
    FILE * outf = open_file(fname.c_str(), "w");
    mm_write_banner(outf, matcode);
    if (comment != "")
      fprintf(outf, "%%%s\n", comment.c_str());
    int actual_Size = size > 0 ? size : latent_factors_inmem[start].pvec.size();

    if (R_output_format)
      mm_write_mtx_crd_size(outf, end-start, actual_Size, (end-start)*actual_Size);
    else
      mm_write_mtx_array_size(outf, end-start, actual_Size);

    for (uint i=start; i < end; i++){
      for(int j=0; j < actual_Size; j++) {
        if (R_output_format)
          fprintf(outf, "%d %d %12.8g\n", i-start+input_file_offset, j+input_file_offset, latent_factors_inmem[i].get_val(j));
        else {
          fprintf(outf, "%1.12e ", latent_factors_inmem[i].get_val(j));
          if (j == actual_Size -1)
	    fprintf(outf, "\n");
        }
      }
      }
    fclose(outf);
  }
示例#2
0
 MMOutputter2(std::string fname, uint start, uint end, std::string comment)  {
   MM_typecode matcode;
   set_matcode(matcode);     
   outf = fopen(fname.c_str(), "w");
   assert(outf != NULL);
   mm_write_banner(outf, matcode);
   if (comment != "")
     fprintf(outf, "%%%s\n", comment.c_str());
   mm_write_mtx_array_size(outf, end-start, D); 
   for (uint i=start; i < end; i++)
     fprintf(outf, "%1.12e\n", latent_factors_inmem[i].mean_rating);
 }
示例#3
0
 MMOutputter_vec(std::string fname, uint start, uint end, int index, std::string comment, std::vector<vertex_data> & latent_factors_inmem)  {
   MM_typecode matcode;
   set_matcode(matcode, R_output_format);
   FILE * outf = open_file(fname.c_str(), "w");
   mm_write_banner(outf, matcode);
   if (comment != "")
     fprintf(outf, "%%%s\n", comment.c_str());
   if (R_output_format)
     mm_write_mtx_crd_size(outf, end-start, 1, end-start);
   else
     mm_write_mtx_array_size(outf, end-start, 1);
   for (uint i=start; i< end; i++)
     if (R_output_format)
        fprintf(outf, "%d %d %12.8g\n", i-start+input_file_offset, 1, latent_factors_inmem[i].get_val(index));
     else
        fprintf(outf, "%1.12e\n", latent_factors_inmem[i].get_val(index));
   fclose(outf);
 }
示例#4
0
  MMOutputter_scalar(std::string fname, std::string comment, double val)  {
    MM_typecode matcode;
    set_matcode(matcode, R_output_format);
    FILE * outf = open_file(fname.c_str(), "w");
    mm_write_banner(outf, matcode);
    if (comment != "")
      fprintf(outf, "%%%s\n", comment.c_str());

    if (R_output_format)
      mm_write_mtx_crd_size(outf, 1, 1, 1);
    else 
      mm_write_mtx_array_size(outf, 1, 1);

    if (R_output_format)
      fprintf(outf, "%d %d %12.8g\n", 1, 1, val);
    else
      fprintf(outf, "%1.12e\n", val);
    fclose(outf);
  }
示例#5
0
 MMOutputter_ids(std::string fname, uint start, uint end, std::string comment)  {
   assert(start < end);
   MM_typecode matcode;
   set_matcode(matcode);     
   FILE * outf = fopen(fname.c_str(), "w");
   assert(outf != NULL);
   mm_write_banner(outf, matcode);
   if (comment != "")
     fprintf(outf, "%%%s\n", comment.c_str());
   mm_write_mtx_array_size(outf, end-start, num_ratings+1); 
   for (uint i=start; i < end; i++){
     fprintf(outf, "%u ", i+1);
     for(int j=0; j < latent_factors_inmem[i].ids.size(); j++) {
       fprintf(outf, "%u ", (int)latent_factors_inmem[i].ids[j]+1);//go back to item ids starting from 1,2,3, (and not from zero as in c)
     }
     fprintf(outf, "\n");
   }
   fclose(outf);
 }
示例#6
0
 MMOutputter_ratings(std::string fname, uint start, uint end, std::string comment)  {
   assert(start < end);
   MM_typecode matcode;
   set_matcode(matcode);     
   FILE * outf = fopen(fname.c_str(), "w");
   assert(outf != NULL);
   mm_write_banner(outf, matcode);
   if (comment != "")
     fprintf(outf, "%%%s\n", comment.c_str());
   mm_write_mtx_array_size(outf, end-start, num_ratings+1); 
   for (uint i=start; i < end; i++){
     fprintf(outf, "%u ", i+1);
     for(int j=0; j < latent_factors_inmem[i].ratings.size(); j++) {
       fprintf(outf, "%1.12e ", latent_factors_inmem[i].ratings[j]);
     }
     fprintf(outf, "\n");
   }
   fclose(outf);
 }