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


Python Model.max_likelihood_estimate方法代码示例

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


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

示例1: train

# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import max_likelihood_estimate [as 别名]
def train(docs_filename,numOfDoc,vocab_filename,dfEps,topicNum=50,epsilon=1e-5,maxIter=1e6):
    #globalVocab=Vocab();
    #globalVocab.load(vocab_filename,0);
    print "globalVocab memoery useage:",resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1000,"time:",datetime.now();
    vocab=load_local_vocab(docs_filename,numOfDoc,dfEps);
    print "local vocab memoery useage:",resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1000,"time:",datetime.now();
    print "vocab loaded, size=",len(vocab.get_term_id_list());
    model=Model(topicNum,vocab);
    model.init_parameters();
    print "model memoery useage:",resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1000,"time:",datetime.now();
    print "start load docs,time:",datetime.now();
    docs=load_docs(docs_filename,numOfDoc,vocab,model);
    print "end of load docs",datetime.now();
    avg_likelihood=1e10; ##model.lowerbound_likelihood(docs);
    iteration=0;
    while iteration<maxIter:
        print "iteration#",iteration,"ave_likelihood#",avg_likelihood,"time:",datetime.now();
        doc_cnt=0;
        for doc in docs:
            if doc_cnt%40==0:
                print "doc varational inference progress:",doc_cnt,"time:",datetime.now();
            doc_cnt+=1;
            doc.varational_inference(model,vocab);
        print "end of docs varataional inference,time:",datetime.now();
        model.max_likelihood_estimate(docs);
        print "end of MLE,time:",datetime.now();
        new_likelihood=model.lowerbound_likelihood(docs);
        if abs(avg_likelihood-new_likelihood)<epsilon:
            break;
        avg_likelihood=new_likelihood;
        iteration+=1;
    pass; # save model
开发者ID:bluekingsong,项目名称:lda-varational,代码行数:34,代码来源:lda-train.py


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