本文整理汇总了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]++;
}
}