码迷,mamicode.com
首页 > 其他好文 > 详细

相似度计算

时间:2014-08-25 16:59:24      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   for   2014   div   log   amp   

bubuko.com,布布扣

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;
}

相似度计算

标签:style   blog   http   color   for   2014   div   log   amp   

原文地址:http://www.cnblogs.com/scofield0li/p/3935208.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!