use of structures._ParentDoc in project IR_Base by Linda-sunshine.
the class LDAGibbs4AC_test method printParameter.
protected 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(cDoc.getName() + "\t");
childParaOut.print("topicProportion\t");
for (int k = 0; k < number_of_topics; k++) {
childParaOut.print(cDoc.m_topics[k] + "\t");
}
childParaOut.println();
}
}
}
parentParaOut.flush();
parentParaOut.close();
childParaOut.flush();
childParaOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of structures._ParentDoc in project IR_Base by Linda-sunshine.
the class LDAGibbs4AC_test method rankChild4StnByLikelihood.
// stn is a query, retrieve comment by likelihood
protected HashMap<String, Double> rankChild4StnByLikelihood(_Stn stnObj, _ParentDoc pDoc) {
HashMap<String, Double> childLikelihoodMap = new HashMap<String, Double>();
for (_ChildDoc cDoc : pDoc.m_childDocs) {
int cDocLen = cDoc.getTotalDocLength();
double stnLogLikelihood = 0;
for (_Word w : stnObj.getWords()) {
double wordLikelihood = 0;
int wid = w.getIndex();
for (int k = 0; k < number_of_topics; k++) {
wordLikelihood += (word_topic_sstat[k][wid] / m_sstat[k]) * (topicInDocProb(k, cDoc) / (d_alpha * number_of_topics + cDocLen));
// wordLikelihood +=
// topic_term_probabilty[k][wid]*cDoc.m_topics[k];
}
stnLogLikelihood += Math.log(wordLikelihood);
}
childLikelihoodMap.put(cDoc.getName(), stnLogLikelihood);
}
return childLikelihoodMap;
}
use of structures._ParentDoc in project IR_Base by Linda-sunshine.
the class LDAGibbs4AC_test method printTopKStn4Child.
protected void printTopKStn4Child(int topK, _ParentDoc pDoc, File topKStnFolder) {
File topKStn4PDocFolder = new File(topKStnFolder, pDoc.getName());
if (!topKStn4PDocFolder.exists()) {
// System.out.println("creating top K stn directory\t"+topKStn4PDocFolder);
topKStn4PDocFolder.mkdir();
}
for (_ChildDoc cDoc : pDoc.m_childDocs) {
String topKStn4ChildFile = cDoc.getName() + ".txt";
HashMap<Integer, Double> stnSimMap = rankStn4ChildBySim(pDoc, cDoc);
try {
int i = 0;
PrintWriter pw = new PrintWriter(new File(topKStn4PDocFolder, topKStn4ChildFile));
for (Map.Entry<Integer, Double> e : sortHashMap4Integer(stnSimMap, true)) {
if (i == topK)
break;
pw.print(e.getKey());
pw.print("\t" + e.getValue());
pw.println();
i++;
}
pw.flush();
pw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of structures._ParentDoc in project IR_Base by Linda-sunshine.
the class corrLDA_Gibbs method collectParentStats.
protected void collectParentStats(_Doc d) {
_ParentDoc pDoc = (_ParentDoc) d;
for (int k = 0; k < number_of_topics; k++) pDoc.m_topics[k] += pDoc.m_sstat[k] + d_alpha;
pDoc.collectTopicWordStat();
}
use of structures._ParentDoc in project IR_Base by Linda-sunshine.
the class corrLDA_Gibbs method initTest4Dynamical.
public void initTest4Dynamical(ArrayList<_Doc> sampleTestSet, _Doc d, int commentNum) {
_ParentDoc pDoc = (_ParentDoc) d;
pDoc.m_childDocs4Dynamic = new ArrayList<_ChildDoc>();
pDoc.setTopics4Gibbs(number_of_topics, 0);
for (_Stn stnObj : pDoc.getSentences()) {
stnObj.setTopicsVct(number_of_topics);
}
sampleTestSet.add(pDoc);
int count = 0;
for (_ChildDoc cDoc : pDoc.m_childDocs) {
if (count >= commentNum) {
break;
}
count++;
cDoc.setTopics4Gibbs_LDA(number_of_topics, 0);
sampleTestSet.add(cDoc);
pDoc.addChildDoc4Dynamics(cDoc);
}
}
Aggregations