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


Java ParallelTopicModel.getTopicProbabilities方法代码示例

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


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

示例1: getMaxTopicsByDocs

import cc.mallet.topics.ParallelTopicModel; //导入方法依赖的package包/类
private List<Map<Integer, Double>> getMaxTopicsByDocs(ParallelTopicModel LDA, int maxTopicsPerDoc) {
	List<Map<Integer, Double>> docList = new ArrayList<Map<Integer, Double>>();
       int numDocs = this.instances.size();
       for (int doc = 0; doc < numDocs; ++doc) {
       	Map<Integer, Double> topicList = new LinkedHashMap<Integer, Double>();
       	double[] topicProbs = LDA.getTopicProbabilities(doc);
       	//double probSum = 0.0;
       	for (int topic = 0; topic < topicProbs.length && topic < maxTopicsPerDoc; topic++) {
       		//if (topicProbs[topic] > 0.01) { // TODO
       			topicList.put(topic, topicProbs[topic]);
       			//probSum += topicProbs[topic];
       		//}
       	}
		//System.out.println("Topic Sum: " + probSum);
       	Map<Integer, Double> sortedTopicList = new TreeMap<Integer, Double>(new DoubleMapComparator(topicList));
       	sortedTopicList.putAll(topicList);
       	docList.add(sortedTopicList);
       }       
	return docList;
}
 
开发者ID:domkowald,项目名称:tagrecommender,代码行数:21,代码来源:MalletCalculator.java

示例2: getMaxTopicsByDocs

import cc.mallet.topics.ParallelTopicModel; //导入方法依赖的package包/类
private List<Map<Integer, Double>> getMaxTopicsByDocs(ParallelTopicModel LDA, int maxTopicsPerDoc) {
	List<Map<Integer, Double>> docList = new ArrayList<Map<Integer, Double>>();
	Map<Integer, Double> unsortedMostPopularTopics = new LinkedHashMap<Integer, Double>();
       int numDocs = this.instances.size();
       for (int doc = 0; doc < numDocs; ++doc) {
       	Map<Integer, Double> topicList = new LinkedHashMap<Integer, Double>();
       	double[] topicProbs = LDA.getTopicProbabilities(doc);
       	//double probSum = 0.0;
       	for (int topic = 0; topic < topicProbs.length && topic < maxTopicsPerDoc; topic++) {
       		if (topicProbs[topic] > TOPIC_THRESHOLD) { // TODO
       			double newTopicProb = topicProbs[topic];
       			topicList.put(topic, newTopicProb);
       			Double oldTopicProb = unsortedMostPopularTopics.get(topic);
       			unsortedMostPopularTopics.put(topic, oldTopicProb == null ? newTopicProb : oldTopicProb.doubleValue() + newTopicProb);
       			//probSum += topicProbs[topic];
       		}
       	}
		//System.out.println("Topic Sum: " + probSum);
       	Map<Integer, Double> sortedTopicList = new TreeMap<Integer, Double>(new DoubleMapComparator(topicList));
       	sortedTopicList.putAll(topicList);
       	docList.add(sortedTopicList);
       }
       
       Map<Integer, Double> sortedMostPopularTopics = new TreeMap<Integer, Double>(new DoubleMapComparator(unsortedMostPopularTopics));
       sortedMostPopularTopics.putAll(unsortedMostPopularTopics);
       for (Map.Entry<Integer, Double> entry : sortedMostPopularTopics.entrySet()) {
       	if (this.mostPopularTopics.size() < MAX_RECOMMENDATIONS) {
       		this.mostPopularTopics.put(entry.getKey(), entry.getValue());
       	}
       }
       
	return docList;
}
 
开发者ID:learning-layers,项目名称:TagRec,代码行数:34,代码来源:MalletCalculator.java

示例3: getMaxTopicsByDocs

import cc.mallet.topics.ParallelTopicModel; //导入方法依赖的package包/类
/**
 * What does this function returns.
 * @param LDA
 * @param maxTopicsPerDoc
 * @return
 */
private List<Map<Integer, Double>> getMaxTopicsByDocs(ParallelTopicModel LDA, int maxTopicsPerDoc){

    List<Map<Integer, Double>> docList = new ArrayList<Map<Integer, Double>>();
    Map<Integer, Double> unsortedMostPopularTopics = new LinkedHashMap<Integer, Double>();
    int numDocs = this.instances.size();
    for (int doc = 0; doc < numDocs; ++doc) {
        Map<Integer, Double> topicList = new LinkedHashMap<Integer, Double>();
        double[] topicProbs = LDA.getTopicProbabilities(doc);
        //double probSum = 0.0;
        for (int topic = 0; topic < topicProbs.length && topic < maxTopicsPerDoc; topic++) {
            if (topicProbs[topic] > TOPIC_THRESHOLD) { // TODO
                double newTopicProb = topicProbs[topic];
                topicList.put(topic, newTopicProb);
                Double oldTopicProb = unsortedMostPopularTopics.get(topic);
                unsortedMostPopularTopics.put(topic, oldTopicProb == null ? newTopicProb : oldTopicProb.doubleValue() + newTopicProb);
                //probSum += topicProbs[topic];
            }
        }
        //System.out.println("Topic Sum: " + probSum);
        Map<Integer, Double> sortedTopicList = new TreeMap<Integer, Double>(new DoubleMapComparator(topicList));
        sortedTopicList.putAll(topicList);
        docList.add(sortedTopicList);
    }
    
    
    Map<Integer, Double> sortedMostPopularTopics = new TreeMap<Integer, Double>(new DoubleMapComparator(unsortedMostPopularTopics));
    sortedMostPopularTopics.putAll(unsortedMostPopularTopics);
    for (Map.Entry<Integer, Double> entry : sortedMostPopularTopics.entrySet()) {
        if (this.mostPopularTopics.size() < MAX_RECOMMENDATIONS) {
            this.mostPopularTopics.put(entry.getKey(), entry.getValue());
        }
    }
    
    return docList;
}
 
开发者ID:learning-layers,项目名称:TagRec,代码行数:42,代码来源:MalletCalculatorTweet.java

示例4: printTopics

import cc.mallet.topics.ParallelTopicModel; //导入方法依赖的package包/类
public void printTopics(ParallelTopicModel model, String writePathDocTopic, String writePathTopicTerm, String writePathTopicTermMatrix) throws Exception {
		ArrayList<String> topicKeys = new ArrayList<String>();  
		
		BufferedWriter writerDocTopic = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(writePathDocTopic), "UTF8"));
		BufferedWriter writerTopicTerm = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(writePathTopicTerm), "UTF8"));
		File file = new File(writePathTopicTerm); 
		String path = file.getName().substring(0, file.getName().length()-4) + "-T" + String.valueOf(maxCount) + ".txt";
		String parentPath = new File(writePathTopicTerm).getParentFile().getAbsolutePath();
		BufferedWriter writerTopicTermShort = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(parentPath,path))));
		BufferedWriter writerTopicTermMatrix = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(writePathTopicTermMatrix), "UTF8")); 
		
		/* Write header */
		writerDocTopic.write("Class,Document"); 
		for(int j = 0; j < model.numTopics; j++) {
			writerDocTopic.write(",T" + j);
		}		
		writerDocTopic.newLine();
		
		/* Write document-topic probabilities to file */
		for(int i=0;i<this.textList.size(); i++){
			double[] topicProbs = model.getTopicProbabilities(i);

			//writerDocTopic.write(i  + ",");
			String docName = this.idDocMapping.get(i); 
			writerDocTopic.write(this.classDocMapping.get(docName) + ",");
			writerDocTopic.write(docName);
			for(int j=0; j < topicProbs.length; j++){
				writerDocTopic.write("," + topicProbs[j]);

			}
			writerDocTopic.newLine(); 
		}

		
		/* Write topic-term probabilities to file */
//		Alphabet alphabet = model.getAlphabet();
//		for (int i = 0; i < model.getSortedWords().size(); i++) {
//			writerTopicTermMatrix.write("TOPIC " + i + ": ");
//			/**topic for the label*/
//			TreeSet<IDSorter> set = model.getSortedWords().get(i); 
//			for (IDSorter s : set) {				
//				 							
//			}
//			writerTopicTerm.newLine(); 
//			writerTopicTermShort.newLine(); 
//		}
//		
		
		/* Write topic term associations */
		Alphabet alphabet = model.getAlphabet();
		for (int i = 0; i < model.getSortedWords().size(); i++) {
			writerTopicTerm.write("TOPIC " + i + ": ");
			writerTopicTermShort.write("TOPIC " + i + ": "); 
			writerTopicTermMatrix.write("TOPIC " + i + ": ");
			/**topic for the label*/
			String tmpTopic = "";
			int count = 0; 
			TreeSet<IDSorter> set = model.getSortedWords().get(i); 
			for (IDSorter s : set) {				
				if(count <= maxCount) {
					writerTopicTermShort.write(alphabet.lookupObject(s.getID()) + ", " ); 					
				}
				count++;
				writerTopicTerm.write(alphabet.lookupObject(s.getID()) + ", "); 			
				writerTopicTermMatrix.write(alphabet.lookupObject(s.getID()) + " (" + s.getWeight() + "), ");
				/**add to topic label*/
				tmpTopic += alphabet.lookupObject(s.getID()) + "\t";
			}
			topicKeys.add(tmpTopic);
			writerTopicTerm.newLine(); 
			writerTopicTermShort.newLine(); 
			writerTopicTermMatrix.newLine();
		}
		
		writerTopicTermMatrix.close();
		writerDocTopic.close();
		writerTopicTerm.close();
		writerTopicTermShort.close();

	}
 
开发者ID:HendrikStrobelt,项目名称:ditop_wrangler,代码行数:81,代码来源:MalletLDA.java


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