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; sparse_matrix_storage_mixable::model_ptr model = orig_->get_model(); for (size_t i = 0; i < ids.size(); ++i) { common::sfv_t row; model->get_row(ids[i].first, row); if (row.size() == 0) { continue; } else { ++exist_row_num; } for (size_t j = 0; j < row.size(); ++j) { ret.push_back(make_pair(row[j].first, row[j].second)); } } 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; } }
void recommender_base::similar_row( const std::string& id, std::vector<std::pair<std::string, float> >& ids, size_t ret_num) const { ids.clear(); common::sfv_t sfv; orig_->get_model()->get_row(id, sfv); similar_row(sfv, ids, ret_num); }
void lsh::neighbor_row( const common::sfv_t& query, vector<pair<string, float> >& ids, size_t ret_num) const { similar_row(query, ids, ret_num); for (size_t i = 0; i < ids.size(); ++i) { ids[i].second = 1 - ids[i].second; } }
void euclid_lsh::neighbor_row( const string& id, vector<pair<string, float> >& ids, size_t ret_num) const { similar_row(id, ids, ret_num); for (size_t i = 0; i < ids.size(); ++i) { ids[i].second = -ids[i].second; } }
void bit_index_storage::similar_row( const std::string& id, vector<pair<string, float> >& ids, uint64_t ret_num) const { ids.clear(); bit_table_t::const_iterator it = bitvals_diff_.find(id); if (it == bitvals_diff_.end()) { it = bitvals_.find(id); if (it == bitvals_.end()) { return; } } similar_row(it->second, ids, ret_num); }