use of structures._Stn in project IR_Base by Linda-sunshine.
the class LDAGibbs4AC_test method rankStn4ChildBySim.
// comment is a query, retrieve stn by topical similarity
protected HashMap<Integer, Double> rankStn4ChildBySim(_ParentDoc pDoc, _ChildDoc cDoc) {
HashMap<Integer, Double> stnSimMap = new HashMap<Integer, Double>();
for (_Stn stnObj : pDoc.getSentences()) {
// double stnSim = computeSimilarity(cDoc.m_topics,
// stnObj.m_topics);
// stnSimMap.put(stnObj.getIndex()+1, stnSim);
//
double stnKL = Utils.klDivergence(cDoc.m_topics, stnObj.m_topics);
// double stnKL = Utils.KLsymmetric(cDoc.m_topics, stnObj.m_topics);
// double stnKL = Utils.klDivergence(stnObj.m_topics,
// cDoc.m_topics);
stnSimMap.put(stnObj.getIndex() + 1, -stnKL);
}
return stnSimMap;
}
use of structures._Stn in project IR_Base by Linda-sunshine.
the class LDAGibbs4AC_test method printTopKChild4Stn.
protected void printTopKChild4Stn(int topK, _ParentDoc pDoc, File topKChildFolder) {
File topKChild4PDocFolder = new File(topKChildFolder, pDoc.getName());
if (!topKChild4PDocFolder.exists()) {
// System.out.println("creating top K stn directory\t"+topKChild4PDocFolder);
topKChild4PDocFolder.mkdir();
}
for (_Stn stnObj : pDoc.getSentences()) {
HashMap<String, Double> likelihoodMap = rankChild4StnByLikelihood(stnObj, pDoc);
String topChild4StnFile = (stnObj.getIndex() + 1) + ".txt";
try {
int i = 0;
PrintWriter pw = new PrintWriter(new File(topKChild4PDocFolder, topChild4StnFile));
for (Map.Entry<String, Double> e : sortHashMap4String(likelihoodMap, 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._Stn in project IR_Base by Linda-sunshine.
the class LDAGibbs4AC_test method printTopKChild4StnWithHybrid.
protected void printTopKChild4StnWithHybrid(String filePrefix, int topK) {
String topKChild4StnFile = filePrefix + "topChild4Stn_hybrid.txt";
try {
PrintWriter pw = new PrintWriter(new File(topKChild4StnFile));
m_LM.generateReferenceModel();
for (_Doc d : m_trainSet) {
if (d instanceof _ParentDoc) {
_ParentDoc pDoc = (_ParentDoc) d;
pw.println(pDoc.getName() + "\t" + pDoc.getSenetenceSize());
for (_Stn stnObj : pDoc.getSentences()) {
// HashMap<String, Double> likelihoodMap =
// rankChild4StnByLikelihood(stnObj, pDoc);
HashMap<String, Double> likelihoodMap = rankChild4StnByHybrid(stnObj, pDoc);
// HashMap<String, Double> likelihoodMap =
// rankChild4StnByLanguageModel(stnObj, pDoc);
int i = 0;
pw.print((stnObj.getIndex() + 1) + "\t");
for (Map.Entry<String, Double> e : sortHashMap4String(likelihoodMap, true)) {
// if(i==topK)
// break;
pw.print(e.getKey());
pw.print(":" + e.getValue());
pw.print("\t");
i++;
}
pw.println();
}
}
}
pw.flush();
pw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of structures._Stn 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._Stn 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;
}
Aggregations