use of structures._ChildDoc 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._ChildDoc 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._ChildDoc in project IR_Base by Linda-sunshine.
the class DCMCorrLDA_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");
}
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._ChildDoc in project IR_Base by Linda-sunshine.
the class DCMCorrLDA_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 += childTopicInDocProb(k, cDoc, pDoc) * childWordByTopicProb(k, wid, pDoc);
}
stnLogLikelihood += wordLikelihood;
}
likelihoodMap.put(cDoc.getName(), stnLogLikelihood);
}
return likelihoodMap;
}
use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class DCMLDA4AC method calculate_M_step.
public void calculate_M_step(int iter, File weightFolder) {
for (_Doc d : m_trainSet) {
if (d instanceof _ParentDoc4DCM)
collectParentStats((_ParentDoc4DCM) d);
else
collectChildStats((_ChildDoc) d);
}
for (int k = 0; k < number_of_topics; k++) for (int v = 0; v < vocabulary_size; v++) m_topic_word_prob[k][v] += word_topic_sstat[k][v] + m_beta[k][v];
File weightIterFolder = new File(weightFolder, "_" + iter);
if (!weightIterFolder.exists()) {
weightIterFolder.mkdir();
}
updateParameter(iter, weightIterFolder);
}
Aggregations