use of structures._Word in project IR_Base by Linda-sunshine.
the class DCMCorrLDA method initialize_probability.
protected void initialize_probability(Collection<_Doc> collection) {
m_alpha_c = new double[number_of_topics];
m_alphaAuxilary = new double[number_of_topics];
m_alpha = new double[number_of_topics];
m_beta = new double[number_of_topics][vocabulary_size];
m_totalAlpha = 0;
m_totalAlpha_c = 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 (_Stn stnObj : d.getSentences()) {
stnObj.setTopicsVct(number_of_topics);
}
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]++;
}
computeMu4Doc(cDoc);
}
}
}
initialAlphaBeta();
imposePrior();
}
use of structures._Word in project IR_Base by Linda-sunshine.
the class DCMCorrLDA method sampleInParentDoc.
protected void sampleInParentDoc(_Doc d) {
_ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
int wid, tid;
double normalizedProb;
for (_Word w : pDoc.getWords()) {
tid = w.getTopic();
wid = w.getIndex();
pDoc.m_sstat[tid]--;
pDoc.m_topic_stat[tid]--;
pDoc.m_wordTopic_stat[tid][wid]--;
normalizedProb = 0;
for (tid = 0; tid < number_of_topics; tid++) {
double pWordTopic = parentWordByTopicProb(tid, wid, pDoc);
double pTopicPDoc = parentTopicInDocProb(tid, pDoc);
double pTopicCDoc = parentChildInfluenceProb(tid, pDoc);
m_topicProbCache[tid] = pWordTopic * pTopicPDoc * pTopicCDoc;
normalizedProb += m_topicProbCache[tid];
}
normalizedProb *= m_rand.nextDouble();
for (tid = 0; tid < number_of_topics; tid++) {
normalizedProb -= m_topicProbCache[tid];
if (normalizedProb <= 0)
break;
}
if (tid == number_of_topics)
tid--;
w.setTopic(tid);
pDoc.m_sstat[tid]++;
pDoc.m_topic_stat[tid]++;
pDoc.m_wordTopic_stat[tid][wid]++;
}
}
use of structures._Word in project IR_Base by Linda-sunshine.
the class DCMCorrLDA method sampleInChildDoc.
protected void sampleInChildDoc(_ChildDoc d) {
int wid, tid;
double normalizedProb;
_ParentDoc4DCM pDoc = (_ParentDoc4DCM) d.m_parentDoc;
for (_Word w : d.getWords()) {
tid = w.getTopic();
wid = w.getIndex();
pDoc.m_wordTopic_stat[tid][wid]--;
pDoc.m_topic_stat[tid]--;
d.m_sstat[tid]--;
normalizedProb = 0;
for (tid = 0; tid < number_of_topics; tid++) {
double pWordTopic = childWordByTopicProb(tid, wid, pDoc);
double pTopic = childTopicInDocProb(tid, d, pDoc);
m_topicProbCache[tid] = pWordTopic * pTopic;
normalizedProb += m_topicProbCache[tid];
}
normalizedProb *= m_rand.nextDouble();
for (tid = 0; tid < m_topicProbCache.length; tid++) {
normalizedProb -= m_topicProbCache[tid];
if (normalizedProb <= 0)
break;
}
if (tid == m_topicProbCache.length)
tid--;
w.setTopic(tid);
d.m_sstat[tid]++;
pDoc.m_topic_stat[tid]++;
pDoc.m_wordTopic_stat[tid][wid]++;
}
}
use of structures._Word in project IR_Base by Linda-sunshine.
the class DCMCorrLDA_multi_E_test method printChildTopicAssignment.
protected void printChildTopicAssignment(_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 DCMCorrLDA_test method printChildTopicAssignment.
protected void printChildTopicAssignment(_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();
}
}
Aggregations