Exemplo n.º 1
0
void recommender_base::complete_row(const std::string& id,
                                    common::sfv_t& ret) const {
  ret.clear();
  common::sfv_t sfv;
  orig_.get_row(id, sfv);
  complete_row(sfv, ret);
}
Exemplo n.º 2
0
void recommender_base::complete_row(const common::sfv_t& query,
                                    common::sfv_t& ret) const {
  ret.clear();
  vector<pair<string, float> > ids;
  similar_row(query, ids, complete_row_similar_num_);
  if (ids.size() == 0) {
    return;
  }

  size_t exist_row_num = 0;
  for (size_t i = 0; i < ids.size(); ++i) {
    common::sfv_t row;
    orig_.get_row(ids[i].first, row);
    if (row.size() == 0) {
      continue;
    } else {
      ++exist_row_num;
    }
    float ratio = ids[i].second;
    for (size_t j = 0; j < row.size(); ++j) {
      ret.push_back(make_pair(row[j].first, row[j].second * ratio));
    }
  }

  if (exist_row_num == 0) {
    return;
  }
  common::sort_and_merge(ret);
  for (size_t i = 0; i < ret.size(); ++i) {
    ret[i].second /= exist_row_num;
  }
}
Exemplo n.º 3
0
void recommender_base::decode_row(const std::string& id,
                                  common::sfv_t& ret) const {
  ret.clear();
  orig_->get_model()->get_row(id, ret);
}