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


Java Randoms.nextDiscrete方法代码示例

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


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

示例1: sampleTopicsForOneDoc

import cc.mallet.util.Randoms; //导入方法依赖的package包/类
private void sampleTopicsForOneDoc (FeatureSequence oneDocTokens, int[] oneDocTopics, // indexed by seq position
                                    int[] oneDocTopicCounts, // indexed by topic index
                                    double[] topicWeights, Randoms r)
{
	int[] currentTypeTopicCounts;
	int type, oldTopic, newTopic;
	double topicWeightsSum;
	int docLen = oneDocTokens.getLength();
	double tw;
	// Iterate over the positions (words) in the document
	for (int si = 0; si < docLen; si++) {
		type = oneDocTokens.getIndexAtPosition(si);
		oldTopic = oneDocTopics[si];
		// Remove this token from all counts
		oneDocTopicCounts[oldTopic]--;
		typeTopicCounts[type][oldTopic]--;
		tokensPerTopic[oldTopic]--;
		// Build a distribution over topics for this token
		Arrays.fill (topicWeights, 0.0);
		topicWeightsSum = 0;
		currentTypeTopicCounts = typeTopicCounts[type];
		for (int ti = 0; ti < numTopics; ti++) {
			tw = ((currentTypeTopicCounts[ti] + beta) / (tokensPerTopic[ti] + vBeta))
			      * ((oneDocTopicCounts[ti] + alpha)); // (/docLen-1+tAlpha); is constant across all topics
			topicWeightsSum += tw;
			topicWeights[ti] = tw;
		}
		// Sample a topic assignment from this distribution
		newTopic = r.nextDiscrete (topicWeights, topicWeightsSum);

		// Put that new topic into the counts
		oneDocTopics[si] = newTopic;
		oneDocTopicCounts[newTopic]++;
		typeTopicCounts[type][newTopic]++;
		tokensPerTopic[newTopic]++;
	}
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:38,代码来源:LDA.java


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