use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class ACCTM_test method printParameter.
public void printParameter(String parentParameterFile, String childParameterFile, ArrayList<_Doc> docList) {
System.out.println("printing parameter");
try {
System.out.println(parentParameterFile);
System.out.println(childParameterFile);
PrintWriter parentParaOut = new PrintWriter(new File(parentParameterFile));
PrintWriter childParaOut = new PrintWriter(new File(childParameterFile));
for (_Doc d : docList) {
if (d instanceof _ParentDoc) {
parentParaOut.print(d.getName() + "\t");
parentParaOut.print("topicProportion\t");
for (int k = 0; k < number_of_topics; k++) {
parentParaOut.print(d.m_topics[k] + "\t");
}
for (_Stn stnObj : d.getSentences()) {
parentParaOut.print("sentence" + (stnObj.getIndex() + 1) + "\t");
for (int k = 0; k < number_of_topics; k++) {
parentParaOut.print(stnObj.m_topics[k] + "\t");
}
}
parentParaOut.println();
for (_ChildDoc cDoc : ((_ParentDoc) d).m_childDocs) {
childParaOut.print(d.getName() + "\t");
childParaOut.print(cDoc.getName() + "\t");
childParaOut.print("topicProportion\t");
for (int k = 0; k < number_of_topics; k++) {
childParaOut.print(cDoc.m_topics + "\t");
}
childParaOut.println();
}
}
}
parentParaOut.flush();
parentParaOut.close();
childParaOut.flush();
childParaOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class DCMCorrLDA method cal_logLikelihood_partial4Child.
protected double cal_logLikelihood_partial4Child(_ChildDoc cDoc) {
double childLikelihood = 0;
_ParentDoc4DCM pDoc = (_ParentDoc4DCM) cDoc.m_parentDoc;
for (_Word w : cDoc.getTestWords()) {
int wid = w.getIndex();
double wordLogLikelihood = 0;
for (int k = 0; k < number_of_topics; k++) {
double wordPerTopicLikelihood = cDoc.m_topics[k] * pDoc.m_wordTopic_prob[k][wid];
wordLogLikelihood += wordPerTopicLikelihood;
}
childLikelihood += Math.log(wordLogLikelihood);
}
return childLikelihood;
}
use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class DCMCorrLDA method updateAlphaC.
protected void updateAlphaC() {
double diff = 0;
int iteration = 0;
do {
diff = 0;
double totalAlphaDenominator = 0;
double[] totalAlphaNumerator = new double[number_of_topics];
Arrays.fill(totalAlphaNumerator, 0);
m_totalAlpha_c = Utils.sumOfArray(m_alpha_c);
double deltaAlpha = 0;
for (_Doc d : m_trainSet) {
if (d instanceof _ParentDoc) {
_ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
double pDocLen = pDoc.getTotalDocLength();
for (_ChildDoc cDoc : pDoc.m_childDocs) {
double muDp = cDoc.getMu() / pDocLen;
double t_totalAlpha_c = m_totalAlpha_c + cDoc.getMu();
double digAlpha = Utils.digamma(t_totalAlpha_c);
totalAlphaDenominator += Utils.digamma(cDoc.getTotalDocLength() + t_totalAlpha_c) - digAlpha;
for (int k = 0; k < number_of_topics; k++) totalAlphaNumerator[k] += Utils.digamma(m_alpha_c[k] + muDp * pDoc.m_sstat[k] + cDoc.m_sstat[k]) - Utils.digamma(m_alpha_c[k] + muDp * pDoc.m_sstat[k]);
}
}
}
for (int k = 0; k < number_of_topics; k++) {
deltaAlpha = totalAlphaNumerator[k] * 1.0 / totalAlphaDenominator;
double newAlpha = m_alpha_c[k] * deltaAlpha;
double t_diff = Math.abs(m_alpha_c[k] - newAlpha);
if (t_diff > diff)
diff = t_diff;
m_alpha_c[k] = newAlpha;
}
iteration++;
if (iteration > m_newtonIter)
break;
} while (diff > m_newtonConverge);
// System.out.println("iteration\t" + iteration);
m_totalAlpha_c = 0;
for (int k = 0; k < number_of_topics; k++) {
m_totalAlpha_c += m_alpha_c[k];
}
}
use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class DCMCorrLDA method initTest.
protected void initTest(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 : cDoc.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();
// cDoc computeMu
computeTestMu4Doc(cDoc);
}
}
use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class DCMCorrLDA method parentChildInfluenceProb.
protected double parentChildInfluenceProb(int tid, _ParentDoc4DCM d) {
double term = 1.0;
if (tid == 0)
return term;
for (_ChildDoc cDoc : d.m_childDocs) {
double muDp = cDoc.getMu() / d.getTotalDocLength();
term *= gammaFuncRatio((int) cDoc.m_sstat[tid], muDp, d_alpha + d.m_sstat[tid] * muDp) / gammaFuncRatio((int) cDoc.m_sstat[0], muDp, d_alpha + d.m_sstat[0] * muDp);
}
return term;
}
Aggregations