use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class LDAGibbs4AC_test method debugOutput.
public void debugOutput(String filePrefix) {
File topicFolder = new File(filePrefix + "topicAssignment");
if (!topicFolder.exists()) {
System.out.println("creating directory" + topicFolder);
topicFolder.mkdir();
}
File childTopKStnFolder = new File(filePrefix + "topKStn");
if (!childTopKStnFolder.exists()) {
System.out.println("creating top K stn directory\t" + childTopKStnFolder);
childTopKStnFolder.mkdir();
}
File stnTopKChildFolder = new File(filePrefix + "topKChild");
if (!stnTopKChildFolder.exists()) {
System.out.println("creating top K child directory\t" + stnTopKChildFolder);
stnTopKChildFolder.mkdir();
}
int topKStn = 10;
int topKChild = 10;
for (_Doc d : m_trainSet) {
if (d instanceof _ParentDoc) {
printParentTopicAssignment(d, topicFolder);
} else if (d instanceof _ChildDoc) {
printChildTopicAssignment(d, topicFolder);
}
// if(d instanceof _ParentDoc){
// printTopKChild4Stn(topKChild, (_ParentDoc)d, stnTopKChildFolder);
// printTopKStn4Child(topKStn, (_ParentDoc)d, childTopKStnFolder);
// }
}
String parentParameterFile = filePrefix + "parentParameter.txt";
String childParameterFile = filePrefix + "childParameter.txt";
printParameter(parentParameterFile, childParameterFile, m_trainSet);
// printTestParameter4Spam(filePrefix);
String similarityFile = filePrefix + "topicSimilarity.txt";
discoverSpecificComments(similarityFile);
printEntropy(filePrefix);
printTopKChild4Parent(filePrefix, topKChild);
printTopKChild4Stn(filePrefix, topKChild);
printTopKChild4StnWithHybrid(filePrefix, topKChild);
printTopKChild4StnWithHybridPro(filePrefix, topKChild);
printTopKStn4Child(filePrefix, topKStn);
}
use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class LDAGibbs4AC_test method rankChild4StnByHybrid.
protected HashMap<String, Double> rankChild4StnByHybrid(_Stn stnObj, _ParentDoc pDoc) {
HashMap<String, Double> childLikelihoodMap = new HashMap<String, Double>();
double smoothingMu = m_LM.m_smoothingMu;
for (_ChildDoc cDoc : pDoc.m_childDocs) {
double cDocLen = cDoc.getTotalDocLength();
_SparseFeature[] fv = cDoc.getSparse();
double stnLogLikelihood = 0;
double alphaDoc = smoothingMu / (smoothingMu + cDocLen);
_SparseFeature[] sv = stnObj.getFv();
for (_SparseFeature svWord : sv) {
double featureLikelihood = 0;
int wid = svWord.getIndex();
double stnVal = svWord.getValue();
int featureIndex = Utils.indexOf(fv, wid);
double docVal = 0;
if (featureIndex != -1) {
docVal = fv[featureIndex].getValue();
}
double LMLikelihood = (1 - alphaDoc) * docVal / (cDocLen);
LMLikelihood += alphaDoc * m_LM.getReferenceProb(wid);
double TMLikelihood = 0;
for (int k = 0; k < number_of_topics; k++) {
// double likelihoodPerTopic =
// topic_term_probabilty[k][wid];
// System.out.println("likelihoodPerTopic1-----\t"+likelihoodPerTopic);
//
// likelihoodPerTopic *= cDoc.m_topics[k];
// System.out.println("likelihoodPerTopic2-----\t"+likelihoodPerTopic);
TMLikelihood += (word_topic_sstat[k][wid] / m_sstat[k]) * (topicInDocProb(k, cDoc) / (d_alpha * number_of_topics + cDocLen));
// TMLikelihood +=
// topic_term_probabilty[k][wid]*cDoc.m_topics[k];
// System.out.println("TMLikelihood\t"+TMLikelihood);
}
featureLikelihood = m_tau * LMLikelihood + (1 - m_tau) * TMLikelihood;
// featureLikelihood = TMLikelihood;
featureLikelihood = Math.log(featureLikelihood);
stnLogLikelihood += stnVal * featureLikelihood;
}
childLikelihoodMap.put(cDoc.getName(), stnLogLikelihood);
}
return childLikelihoodMap;
}
use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class corrLDA_Gibbs method childTopicInDocProb.
protected double childTopicInDocProb(int tid, _ChildDoc d) {
_ParentDoc pDoc = (_ParentDoc) (d.m_parentDoc);
double pDocTopicSum = Utils.sumOfArray(pDoc.m_sstat);
double term = (pDoc.m_sstat[tid] + m_smoothingParam) / (pDocTopicSum + m_smoothingParam * number_of_topics);
return term;
}
use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class corrLDA_Gibbs method initialize_probability.
@Override
protected void initialize_probability(Collection<_Doc> collection) {
createSpace();
for (int i = 0; i < number_of_topics; i++) Arrays.fill(word_topic_sstat[i], d_beta);
Arrays.fill(m_sstat, d_beta * vocabulary_size);
for (_Doc d : collection) {
if (d instanceof _ParentDoc) {
for (_Stn stnObj : d.getSentences()) {
stnObj.setTopicsVct(number_of_topics);
}
d.setTopics4Gibbs(number_of_topics, 0);
} else if (d instanceof _ChildDoc) {
((_ChildDoc) d).setTopics4Gibbs_LDA(number_of_topics, 0);
}
for (_Word w : d.getWords()) {
word_topic_sstat[w.getTopic()][w.getIndex()]++;
m_sstat[w.getTopic()]++;
}
}
imposePrior();
m_statisticsNormalized = false;
}
use of structures._ChildDoc in project IR_Base by Linda-sunshine.
the class corrLDA_Gibbs method sampleInChildDoc.
protected void sampleInChildDoc(_Doc d) {
_ChildDoc cDoc = (_ChildDoc) d;
int wid, tid;
double normalizedProb = 0;
for (_Word w : cDoc.getWords()) {
wid = w.getIndex();
tid = w.getTopic();
cDoc.m_sstat[tid]--;
if (m_collectCorpusStats) {
word_topic_sstat[tid][wid]--;
m_sstat[tid]--;
}
normalizedProb = 0;
for (tid = 0; tid < number_of_topics; tid++) {
double pWordTopic = childWordByTopicProb(tid, wid);
double pTopicDoc = childTopicInDocProb(tid, cDoc);
m_topicProbCache[tid] = pWordTopic * pTopicDoc;
normalizedProb += m_topicProbCache[tid];
}
normalizedProb *= m_rand.nextDouble();
for (tid = 0; tid < number_of_topics; tid++) {
normalizedProb -= m_topicProbCache[tid];
if (normalizedProb < 0)
break;
}
if (tid == number_of_topics)
tid--;
w.setTopic(tid);
cDoc.m_sstat[tid]++;
if (m_collectCorpusStats) {
word_topic_sstat[tid][wid]++;
m_sstat[tid]++;
}
}
}
Aggregations