当前位置: 首页>>代码示例>>C++>>正文


C++ Topic::TopicInit方法代码示例

本文整理汇总了C++中Topic::TopicInit方法的典型用法代码示例。如果您正苦于以下问题:C++ Topic::TopicInit方法的具体用法?C++ Topic::TopicInit怎么用?C++ Topic::TopicInit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Topic的用法示例。


在下文中一共展示了Topic::TopicInit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Singlepass

/*
 * @description:
 *  一趟聚类的思想
 */
void Cluster::Singlepass() {
#ifdef TIME
    time_t start3;
    start3 = time(NULL);
#endif


    this->SetClusterThrod(this->GenClusterThrod() + THROD_ADD);
    std::cout << "CLUSTER_THROD: " << this->CLSTER_THROD << std::endl;

#ifdef DEBUG_CLUSTER1
    printMatrix(this->co_ccur_matrix);
#endif

    MAP::iterator topic_w_it = this->topicword->begin();
    TopicWord firstword = topic_w_it->second;
    //这里初始化一个词作为一个簇(topic)
    Topic topic;
    topic.TopicInit(firstword);
    this->clusterList.push_back(topic);

    //对于每一个词,计算词在话题列表Topic的距离
    topic_w_it++;
    std::cout<<"聚类前特征词的个数"<<this->topicword->size()<<std::endl;
    for (; topic_w_it != this->topicword->end(); ++topic_w_it) {

        vector<Topic>::iterator vec_clu_it = this->clusterList.begin();
        double maxDistance = MINVALUE;
        vector<Topic>::iterator belong_clus_it = vec_clu_it;//这里应该是赋值还是指针????
        for (; vec_clu_it != this->clusterList.end(); ++vec_clu_it) {
            double words_distance = Cal_Words_Topic_Distance(*vec_clu_it,topic_w_it->second);
            //查看是否有比之前保留的最近的簇更近的簇
            if (maxDistance < words_distance) {
                maxDistance = words_distance;
                belong_clus_it = vec_clu_it;
            }
        }
        //如果该词与该簇距离最近,那么将该词加入该簇
        if (maxDistance < this->CLSTER_THROD) {
            Topic newTopic;
            newTopic.TopicInit(topic_w_it->second);
            this->clusterList.push_back(newTopic);
        } else {
            belong_clus_it->addTopicWord(topic_w_it->second);
        }
    }


#ifdef TIME
    time_t ends4;
    ends4 = time(NULL);
    std::cout << "一趟聚类用时:" << difftime(ends4, start3) << std::endl;
#endif

#ifdef TIME
    time_t start5;
    start5 = time(NULL);
#endif
    //及时将共现矩阵清空
//	this->co_ccur_matrix.clear();
    //match weibo id to topic
    this->MatchWeiboIDToTopic();
    //select the weibo which have more than two words in topic
    this->ListAllTopicWeiboId();

#ifdef TIME
    time_t ends5;
    ends5 = time(NULL);
    std::cout << "微博对应话题用时:" << difftime(ends5, start5) << std::endl;
#endif


    this->SortTopic();
//	this->InsterAllTopicToDatabase();


#ifdef PRINTTOPICA
    printTopic(&this->clusterList);
#endif
}
开发者ID:huntzhan,项目名称:WeiboTopic,代码行数:84,代码来源:Cluster.cpp


注:本文中的Topic::TopicInit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。