use of structures._ParentDoc4DCM 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;
}
use of structures._ParentDoc4DCM in project IR_Base by Linda-sunshine.
the class DCMCorrLDA_multi_E method initialize_probability.
protected void initialize_probability(Collection<_Doc> collection) {
int cores = Runtime.getRuntime().availableProcessors();
m_threadpool = new Thread[cores];
m_workers = new DCMCorrLDA_worker[cores];
for (int i = 0; i < cores; i++) m_workers[i] = new DCMCorrLDA_worker(number_of_topics, vocabulary_size);
int workerID = 0;
for (_Doc d : collection) {
if (d instanceof _ParentDoc) {
m_workers[workerID % cores].addDoc(d);
_ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
for (_ChildDoc cDoc : pDoc.m_childDocs) {
m_workers[workerID % cores].addDoc(cDoc);
}
workerID++;
}
}
super.initialize_probability(collection);
}
use of structures._ParentDoc4DCM in project IR_Base by Linda-sunshine.
the class DCMCorrLDA_multi_E_test method printTopKChild4Stn.
protected void printTopKChild4Stn(String filePrefix, int topK) {
String topKChild4StnFile = filePrefix + "topChild4Stn.txt";
try {
PrintWriter pw = new PrintWriter(new File(topKChild4StnFile));
for (_Doc d : m_trainSet) {
if (d instanceof _ParentDoc4DCM) {
_ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
pw.println(pDoc.getName() + "\t" + pDoc.getSenetenceSize());
for (_Stn stnObj : pDoc.getSentences()) {
HashMap<String, Double> likelihoodMap = rankChild4StnByLikelihood(stnObj, pDoc);
int i = 0;
pw.print((stnObj.getIndex() + 1) + "\t");
for (String e : likelihoodMap.keySet()) {
pw.print(e);
pw.print(":" + likelihoodMap.get(e));
pw.print("\t");
i++;
}
pw.println();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of structures._ParentDoc4DCM in project IR_Base by Linda-sunshine.
the class DCMCorrLDA_multi_E_test method rankChild4StnByLikelihood.
protected HashMap<String, Double> rankChild4StnByLikelihood(_Stn stnObj, _ParentDoc4DCM pDoc) {
HashMap<String, Double> likelihoodMap = new HashMap<String, Double>();
for (_ChildDoc cDoc : pDoc.m_childDocs) {
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 += cDoc.m_topics[k] * pDoc.m_wordTopic_prob[k][wid];
}
stnLogLikelihood += wordLikelihood;
}
likelihoodMap.put(cDoc.getName(), stnLogLikelihood);
}
return likelihoodMap;
}
use of structures._ParentDoc4DCM in project IR_Base by Linda-sunshine.
the class DCMCorrLDA_test method printTopKChild4Stn.
protected void printTopKChild4Stn(String filePrefix, int topK) {
String topKChild4StnFile = filePrefix + "topChild4Stn.txt";
try {
PrintWriter pw = new PrintWriter(new File(topKChild4StnFile));
for (_Doc d : m_trainSet) {
if (d instanceof _ParentDoc4DCM) {
_ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
pw.println(pDoc.getName() + "\t" + pDoc.getSenetenceSize());
for (_Stn stnObj : pDoc.getSentences()) {
HashMap<String, Double> likelihoodMap = rankChild4StnByLikelihood(stnObj, pDoc);
int i = 0;
pw.print((stnObj.getIndex() + 1) + "\t");
for (String e : likelihoodMap.keySet()) {
pw.print(e);
pw.print(":" + likelihoodMap.get(e));
pw.print("\t");
i++;
}
pw.println();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations