本文整理汇总了Python中Model.Model.lowerbound_likelihood方法的典型用法代码示例。如果您正苦于以下问题:Python Model.lowerbound_likelihood方法的具体用法?Python Model.lowerbound_likelihood怎么用?Python Model.lowerbound_likelihood使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model.Model
的用法示例。
在下文中一共展示了Model.lowerbound_likelihood方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train
# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import lowerbound_likelihood [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