void recommender_base::complete_row(const sfv_t& query, 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) { 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; } sort_and_merge(ret); for (size_t i = 0; i < ret.size(); ++i) { ret[i].second /= exist_row_num; } }
void add_feature(const std::string& key, double value, sfv_t& ret_fv) const { ret_fv.push_back(make_pair(key, std::log(std::max(1.0, value)))); }
void add_feature(const std::string& key, double value, sfv_t& ret_fv) const { std::stringstream ss; ss << key << "$" << value; ret_fv.push_back(make_pair(ss.str(), 1.0)); }