use of structures._Word in project IR_Base by Linda-sunshine.
the class DCMLDA4AC method initialize_probability.
protected void initialize_probability(Collection<_Doc> collection) {
m_alpha = new double[number_of_topics];
m_beta = new double[number_of_topics][vocabulary_size];
m_totalAlpha = 0;
m_totalBeta = new double[number_of_topics];
m_topic_word_prob = new double[number_of_topics][vocabulary_size];
for (_Doc d : collection) {
if (d instanceof _ParentDoc4DCM) {
_ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
pDoc.setTopics4Gibbs(number_of_topics, 0, vocabulary_size);
for (_Word w : pDoc.getWords()) {
int wid = w.getIndex();
int tid = w.getTopic();
word_topic_sstat[tid][wid]++;
}
for (_ChildDoc cDoc : pDoc.m_childDocs) {
cDoc.setTopics4Gibbs_LDA(number_of_topics, 0);
for (_Word w : cDoc.getWords()) {
int wid = w.getIndex();
int tid = w.getTopic();
pDoc.m_wordTopic_stat[tid][wid]++;
pDoc.m_topic_stat[tid]++;
word_topic_sstat[tid][wid]++;
}
}
}
}
initialAlphaBeta();
imposePrior();
}
use of structures._Word in project IR_Base by Linda-sunshine.
the class DCMLDA4AC method cal_logLikelihood_partial4Child.
protected double cal_logLikelihood_partial4Child(_ChildDoc d) {
double likelihood = 0;
_ParentDoc4DCM pDoc = (_ParentDoc4DCM) d.m_parentDoc;
for (_Word w : d.getWords()) {
int wid = w.getIndex();
double wordLikelihood = 0;
for (int k = 0; k < number_of_topics; k++) {
wordLikelihood += d.m_topics[k] * pDoc.m_wordTopic_prob[k][wid];
}
likelihood += Math.log(wordLikelihood);
}
return likelihood;
}
use of structures._Word in project IR_Base by Linda-sunshine.
the class DCMLDA4AC method initTestDoc.
public void initTestDoc(ArrayList<_Doc> sampleTestSet, _Doc d) {
_ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
for (_Stn stnObj : pDoc.getSentences()) {
stnObj.setTopicsVct(number_of_topics);
}
int testLength = 0;
pDoc.setTopics4GibbsTest(number_of_topics, 0, testLength, vocabulary_size);
sampleTestSet.add(pDoc);
for (_ChildDoc cDoc : pDoc.m_childDocs) {
testLength = (int) (m_testWord4PerplexityProportion * cDoc.getTotalDocLength());
cDoc.setTopics4GibbsTest(number_of_topics, d_alpha, testLength);
for (_Word w : d.getWords()) {
int wid = w.getIndex();
int tid = w.getTopic();
pDoc.m_wordTopic_stat[tid][wid]++;
pDoc.m_topic_stat[tid]++;
}
sampleTestSet.add(cDoc);
cDoc.createSparseVct4Infer();
}
}
use of structures._Word in project IR_Base by Linda-sunshine.
the class DCMLDA4AC_test method printParentTopicAssignment.
protected void printParentTopicAssignment(_Doc d, File topicFolder) {
String topicAssignmentFile = d.getName() + ".txt";
try {
PrintWriter pw = new PrintWriter(new File(topicFolder, topicAssignmentFile));
for (_Word w : d.getWords()) {
int index = w.getIndex();
int topic = w.getTopic();
String featureName = m_corpus.getFeature(index);
pw.print(featureName + ":" + topic + "\t");
}
pw.flush();
pw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
use of structures._Word in project IR_Base by Linda-sunshine.
the class LDAGibbs4AC method cal_logLikelihood_partial4Child.
protected double cal_logLikelihood_partial4Child(_Doc d) {
double docLogLikelihood = 0.0;
for (_Word w : d.getTestWords()) {
int wid = w.getIndex();
double wordLogLikelihood = 0;
for (int k = 0; k < number_of_topics; k++) {
double wordPerTopicLikelihood = d.m_topics[k] * topic_term_probabilty[k][wid];
wordLogLikelihood += wordPerTopicLikelihood;
}
docLogLikelihood += Math.log(wordLogLikelihood);
}
return docLogLikelihood;
}
Aggregations