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


Java IDSorter.getWeight方法代码示例

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


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

示例1: getTopicWords

import cc.mallet.types.IDSorter; //导入方法依赖的package包/类
private Map<Integer, Map<String, Double>> getTopicWords(int w) {
	Map<Integer, Map<String, Double>> map = new HashMap<Integer, Map<String, Double>>();
	Alphabet topicAlphabet = _model.getAlphabet();
	
	ArrayList<TreeSet<IDSorter>> topicSortedWords = _model.getSortedWords();		
	
	for (int topic = 0; topic < _model.numTopics; topic++) {
		TreeSet<IDSorter> set = topicSortedWords.get(topic);		
		
		double sum = 0.0;
		for ( IDSorter s : set ) {
			sum += s.getWeight();
		}
		
		Map<String, Double> words = new HashMap<String, Double>();
		for(IDSorter idSorter : set) {
			double weight = idSorter.getWeight() / sum;
			String word = (String) topicAlphabet.lookupObject(idSorter.getID());
			words.put(word, weight);
		}
		
		// Sort by weight
		List<Entry<String, Double>> sortedWords = Sorter.sort(words);
		
		w = Math.min(w, sortedWords.size());
		Map<String, Double> temp = new HashMap<String, Double>();
		for(int i=0; i<w; i++) {
			Entry<String, Double> first = sortedWords.get(i);
			temp.put(first.getKey(), first.getValue());
		}
		
		map.put(topic, temp);
	}
	return map;
}
 
开发者ID:MKLab-ITI,项目名称:mgraph-summarization,代码行数:36,代码来源:LDA.java

示例2: topicXMLReport

import cc.mallet.types.IDSorter; //导入方法依赖的package包/类
public void topicXMLReport (int iterationNo, int numWords) {
	List<String> lines = new ArrayList<String>();
	ArrayList<TreeSet<IDSorter>> topicSortedWords = getSortedWords();
	lines.add("<?xml version='1.0' ?>");
	lines.add("<topicModel>");
	for (int topic = 0; topic < numTopics; topic++) {
		lines.add("  <topic id='" + topic + "' alpha='" + alpha[topic] +
					"' totalTokens='" + tokensPerTopic[topic] + "'>");
		int word = 1;
		Iterator<IDSorter> iterator = topicSortedWords.get(topic).iterator();
		while (iterator.hasNext() && word < numWords) {
			IDSorter info = iterator.next();
			double weight = info.getWeight();
			if(weight>this.weightThreshold) {
				lines.add("	<word rank='" + word +"' "+"weight='" + weight  + "'>" +
						  alphabet.lookupObject(info.getID()) +
						  "</word>");
				
				word++;
			}
		}
		lines.add("  </topic>");
	}
	lines.add("</topicModel>");
	if(this.tDir!=null){
		try{
			if(tDir.exists()){
				File f= new File(tDir.getAbsolutePath() + "/topicsAtIteration"+iterationNo+".xml");
				logger.info("Writing Topic File at Iteration " + iterationNo + " to path ===" +f.getAbsolutePath());
				FileUtils.writeLines(f, lines);
			}
		}
		catch(Exception e){
			throw new RuntimeException(e);
		}		
	}
	else{
		logger.info("Writing Topic File at Iteration " + iterationNo + " System.out------" );
		for(String l:lines){
			System.out.println(l);
		}
		System.out.println("\n\n");	
	}

}
 
开发者ID:sameeraxiomine,项目名称:largelda,代码行数:46,代码来源:ParallelTopicModel.java


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