【发布时间】:2015-09-15 22:27:54
【问题描述】:
我有以下代码,这花费了我运行时间。关于如何优化它以使其更好更快的任何建议?
for (int tIndex = 0; tIndex < numTopics; tIndex++) {
double beta0 = sumTopicWordCount[tIndex] + betaSum;
int m0 = 0;
double expectWT = 1;
// getting the number of total words (or word w) in sentence i
List<String> sentenceStat = new ArrayList<String>();
for(int wIndex=0 ; wIndex<sentence.size() ; wIndex++){
sentenceStat.add(id2WordVocabulary.get(document.get(sIndex).get(wIndex)));
}
Set<String> unique = new HashSet<String>(sentenceStat);
for(String key : unique){
int cnt = Collections.frequency(sentenceStat, key);
double betaw = topicWordCount[tIndex][word2IdVocabulary.get(key)] + beta;
for (int m = 0; m < cnt; m++) {
expectWT *= (betaw + m) / (beta0 + m0);
m0++;
}
}
multiPros[tIndex] = (docTopicCount[sIndex][tIndex] + alpha) * expectWT;
}
【问题讨论】:
标签: java arrays performance list hashset