use of structures._ParentDoc in project IR_Base by Linda-sunshine.
the class ACCTM_test method printParentPhi.
protected void printParentPhi(_Doc d, File phiFolder) {
_ParentDoc pDoc = (_ParentDoc) d;
String parentPhiFileName = pDoc.getName() + ".txt";
_SparseFeature[] fv = pDoc.getSparse();
try {
PrintWriter parentPW = new PrintWriter(new File(phiFolder, parentPhiFileName));
for (int n = 0; n < fv.length; n++) {
int index = fv[n].getIndex();
String featureName = m_corpus.getFeature(index);
parentPW.print(featureName + ":\t");
for (int k = 0; k < number_of_topics; k++) parentPW.print(pDoc.m_phi[n][k] + "\t");
parentPW.println();
}
parentPW.flush();
parentPW.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of structures._ParentDoc in project IR_Base by Linda-sunshine.
the class ACCTM_test method rankChild4StnByLikelihood.
protected HashMap<String, Double> rankChild4StnByLikelihood(_Stn stnObj, _ParentDoc pDoc) {
HashMap<String, Double> childLikelihoodMap = new HashMap<String, Double>();
for (_ChildDoc cDoc : pDoc.m_childDocs) {
double stnLogLikelihood = 0;
for (_Word w : stnObj.getWords()) {
int wid = w.getIndex();
double wordLogLikelihood = 0;
for (int k = 0; k < number_of_topics; k++) {
double wordPerTopicLikelihood = childWordByTopicProb(k, wid) * childTopicInDocProb(k, cDoc);
wordLogLikelihood += wordPerTopicLikelihood;
}
stnLogLikelihood += Math.log(wordLogLikelihood);
}
childLikelihoodMap.put(cDoc.getName(), stnLogLikelihood);
}
return childLikelihoodMap;
}
use of structures._ParentDoc 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._ParentDoc in project IR_Base by Linda-sunshine.
the class ACCTM_test method printParentTopicAssignment.
protected void printParentTopicAssignment(_Doc d, File topicFolder) {
// System.out.println("printing topic assignment parent documents");
_ParentDoc pDoc = (_ParentDoc) d;
String topicAssignmentFile = pDoc.getName() + ".txt";
try {
PrintWriter pw = new PrintWriter(new File(topicFolder, topicAssignmentFile));
for (_Stn stnObj : pDoc.getSentences()) {
pw.print(stnObj.getIndex() + "\t");
for (_Word w : stnObj.getWords()) {
int index = w.getIndex();
int topic = w.getTopic();
String featureName = m_corpus.getFeature(index);
// System.out.println("test\t"+featureName+"\tdocName\t"+d.getName());
pw.print(featureName + ":" + topic + "\t");
}
pw.println();
}
pw.flush();
pw.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of structures._ParentDoc in project IR_Base by Linda-sunshine.
the class DCMCorrLDA method computeTestMu4Doc.
protected void computeTestMu4Doc(_ChildDoc d) {
_ParentDoc pDoc = d.m_parentDoc;
double mu = Utils.cosine(d.getSparseVct4Infer(), pDoc.getSparseVct4Infer());
mu = 0.05;
d.setMu(mu);
}
Aggregations