首页 > 代码库 > 相似度计算
相似度计算
struct topic_info_t { int topic_id; float topic_pr;};float sim(const vector<topic_info_t>& query_info,const vector<topic_info_t>& adwords){ vector<topic_info_t>::iterator it1 = query_info.begin(); vector<topic_info_t>::iterator it2 = adwords.begin(); float sim = 0.0; for (; it1 != query_info.end() && it2 != adwords.end() ;){ if(it1->topic_id == it2->topic_id){ sim += it1->topic_pr*it2->topic_pr; it1++; it2++; } else if(it1->topic_id < it2->topic_id) it1++; else it2++; } return sim;}float max_sim(const vector<topic_info_t>& query_info, const vector<topic_info_t> adwords_topic_info[],int adwords_number){ if (NULL == adwords_topic_info || adwords_number <= 0) return 0.0; float maxSim = sim(query_info,adwords_topic_info[0]); int i = 1; while(i<adwords_number){ simI = sim(query_info,adwords_topic_info[i]); if(simI > maxSim) maxSim = simI; } return maxSim;}
相似度计算
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。