use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class ACCTM_test method printMu.
protected void printMu(String childMuFile) {
System.out.println("print mu");
try {
PrintWriter muPW = new PrintWriter(new File(childMuFile));
for (_Doc d : m_trainSet) {
if (d instanceof _ChildDoc) {
muPW.println(d.getName() + "\t" + ((_ChildDoc) d).getMu());
}
}
muPW.flush();
muPW.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class ACCTM_test method debugOutput.
public void debugOutput(int topK, String filePrefix) {
File parentTopicFolder = new File(filePrefix + "parentTopicAssignment");
File childTopicFolder = new File(filePrefix + "childTopicAssignment");
if (!parentTopicFolder.exists()) {
System.out.println("creating directory" + parentTopicFolder);
parentTopicFolder.mkdir();
}
if (!childTopicFolder.exists()) {
System.out.println("creating directory" + childTopicFolder);
childTopicFolder.mkdir();
}
File parentPhiFolder = new File(filePrefix + "parentPhi");
File childPhiFolder = new File(filePrefix + "childPhi");
if (!parentPhiFolder.exists()) {
System.out.println("creating directory" + parentPhiFolder);
parentPhiFolder.mkdir();
}
if (!childPhiFolder.exists()) {
System.out.println("creating directory" + childPhiFolder);
childPhiFolder.mkdir();
}
File childXFolder = new File(filePrefix + "xValue");
if (!childXFolder.exists()) {
System.out.println("creating x Value directory" + childXFolder);
childXFolder.mkdir();
}
for (_Doc d : m_trainSet) {
if (d instanceof _ParentDoc) {
printParentTopicAssignment((_ParentDoc) d, parentTopicFolder);
printParentPhi((_ParentDoc) d, parentPhiFolder);
} else if (d instanceof _ChildDoc) {
printChildTopicAssignment(d, childTopicFolder);
}
}
String parentParameterFile = filePrefix + "parentParameter.txt";
String childParameterFile = filePrefix + "childParameter.txt";
printParameter(parentParameterFile, childParameterFile, m_trainSet);
String similarityFile = filePrefix + "topicSimilarity.txt";
printEntropy(filePrefix);
printTopKChild4Stn(filePrefix, topK);
String childMuFile = filePrefix + "childMu.txt";
printMu(childMuFile);
}
use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class DCMCorrLDA method initialAlphaBeta.
protected void initialAlphaBeta() {
double parentDocNum = 0;
double childDocNum = 0;
Arrays.fill(m_sstat, 0);
Arrays.fill(m_alphaAuxilary, 0);
for (int k = 0; k < number_of_topics; k++) {
Arrays.fill(topic_term_probabilty[k], 0);
Arrays.fill(word_topic_sstat[k], 0);
}
for (_Doc d : m_trainSet) {
if (d instanceof _ParentDoc4DCM) {
_ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
for (int k = 0; k < number_of_topics; k++) {
double tempProb = pDoc.m_sstat[k] / pDoc.getTotalDocLength();
m_sstat[k] += tempProb;
if (pDoc.m_sstat[k] == 0)
continue;
for (int v = 0; v < vocabulary_size; v++) {
tempProb = pDoc.m_wordTopic_stat[k][v] / pDoc.m_topic_stat[k];
topic_term_probabilty[k][v] += tempProb;
}
}
parentDocNum += 1;
for (_ChildDoc cDoc : pDoc.m_childDocs) {
for (int k = 0; k < number_of_topics; k++) {
double tempProb = cDoc.m_sstat[k] / cDoc.getTotalDocLength();
m_alphaAuxilary[k] += tempProb;
}
childDocNum += 1;
}
}
}
for (int k = 0; k < number_of_topics; k++) {
m_sstat[k] /= parentDocNum;
m_alphaAuxilary[k] /= childDocNum;
for (int v = 0; v < vocabulary_size; v++) {
topic_term_probabilty[k][v] /= (parentDocNum + childDocNum);
}
}
for (int k = 0; k < number_of_topics; k++) {
m_alpha[k] = m_sstat[k];
m_alpha_c[k] = m_alphaAuxilary[k];
for (int v = 0; v < vocabulary_size; v++) m_beta[k][v] = topic_term_probabilty[k][v] + d_beta;
}
m_totalAlpha = Utils.sumOfArray(m_alpha);
m_totalAlpha_c = Utils.sumOfArray(m_alpha_c);
for (int k = 0; k < number_of_topics; k++) {
m_totalBeta[k] = Utils.sumOfArray(m_beta[k]);
}
}
use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class DCMCorrLDA method calculate_log_likelihood.
protected double calculate_log_likelihood(_ParentDoc4DCM d) {
double docLogLikelihood = 0;
int docID = d.getID();
double parentDocLength = d.getTotalDocLength();
for (int k = 0; k < number_of_topics; k++) {
double term = Utils.lgamma(d.m_sstat[k] + m_alpha[k]);
docLogLikelihood += term;
term = Utils.lgamma(m_alpha[k]);
docLogLikelihood -= term;
}
docLogLikelihood += Utils.lgamma(m_totalAlpha);
docLogLikelihood -= Utils.lgamma(parentDocLength + m_totalAlpha);
for (int k = 0; k < number_of_topics; k++) {
for (int v = 0; v < vocabulary_size; v++) {
double term = Utils.lgamma(d.m_wordTopic_stat[k][v] + m_beta[k][v]);
docLogLikelihood += term;
term = Utils.lgamma(m_beta[k][v]);
docLogLikelihood -= term;
}
docLogLikelihood += Utils.lgamma(m_totalBeta[k]);
docLogLikelihood -= Utils.lgamma(d.m_topic_stat[k] + m_totalBeta[k]);
}
for (_ChildDoc cDoc : d.m_childDocs) {
double muDp = cDoc.getMu() / parentDocLength;
docLogLikelihood += Utils.digamma(m_totalAlpha_c + cDoc.getMu());
docLogLikelihood += Utils.digamma(m_totalAlpha_c + cDoc.getMu() + cDoc.getTotalDocLength());
for (int k = 0; k < number_of_topics; k++) {
double term = Utils.digamma(m_alpha_c[k] + muDp * d.m_sstat[k] + cDoc.m_sstat[k]);
term -= Utils.digamma(m_alpha_c[k] + muDp * d.m_sstat[k]);
docLogLikelihood += term;
}
}
return docLogLikelihood;
}
use of structures._ChildDoc 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();
}
Aggregations