use of structures._ParentDoc in project IR_Base by Linda-sunshine.
the class DCMCorrLDA method computeMu4Doc.
protected void computeMu4Doc(_ChildDoc d) {
_ParentDoc tempParent = d.m_parentDoc;
double mu = Utils.cosine(tempParent.getSparse(), d.getSparse());
mu = 0.5;
d.setMu(mu);
}
use of structures._ParentDoc in project IR_Base by Linda-sunshine.
the class DCMCorrLDA method updateBeta.
protected void updateBeta(int tid) {
double diff = 0;
double smoothingBeta = 0.1;
int iteration = 0;
do {
diff = 0;
double deltaBeta = 0;
double wordNum4Tid = 0;
double[] wordNum4Tid4V = new double[vocabulary_size];
double totalBetaDenominator = 0;
double[] totalBetaNumerator = new double[vocabulary_size];
Arrays.fill(totalBetaNumerator, 0);
Arrays.fill(wordNum4Tid4V, 0);
m_totalBeta[tid] = Utils.sumOfArray(m_beta[tid]);
double digBeta4Tid = Utils.digamma(m_totalBeta[tid]);
for (_Doc d : m_trainSet) {
if (d instanceof _ParentDoc) {
_ParentDoc4DCM pDoc = (_ParentDoc4DCM) d;
totalBetaDenominator += Utils.digamma(m_totalBeta[tid] + pDoc.m_topic_stat[tid]) - digBeta4Tid;
for (int v = 0; v < vocabulary_size; v++) {
wordNum4Tid += pDoc.m_wordTopic_stat[tid][v];
wordNum4Tid4V[v] += pDoc.m_wordTopic_stat[tid][v];
totalBetaNumerator[v] += Utils.digamma(m_beta[tid][v] + pDoc.m_wordTopic_stat[tid][v]);
totalBetaNumerator[v] -= Utils.digamma(m_beta[tid][v]);
}
}
}
for (int v = 0; v < vocabulary_size; v++) {
if (wordNum4Tid == 0)
break;
if (wordNum4Tid4V[v] == 0) {
deltaBeta = 0;
} else {
deltaBeta = totalBetaNumerator[v] / totalBetaDenominator;
}
double newBeta = m_beta[tid][v] * deltaBeta + d_beta;
double t_diff = Math.abs(m_beta[tid][v] - newBeta);
if (t_diff > diff)
diff = t_diff;
m_beta[tid][v] = newBeta;
}
iteration++;
// System.out.println("beta iteration\t"+iteration);
} while (diff > m_newtonConverge);
// System.out.println("beta iteration\t" + iteration);
}
use of structures._ParentDoc in project IR_Base by Linda-sunshine.
the class DCMCorrLDA_multi_E_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._ParentDoc in project IR_Base by Linda-sunshine.
the class DCMCorrLDA_test method debugOutput.
protected 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 parentWordTopicDistributionFolder = new File(filePrefix + "wordTopicDistribution");
if (!parentWordTopicDistributionFolder.exists()) {
System.out.println("creating word topic distribution folder\t" + parentWordTopicDistributionFolder);
parentWordTopicDistributionFolder.mkdir();
}
for (_Doc d : m_trainSet) {
if (d instanceof _ParentDoc) {
// printParentTopicAssignment(d, parentTopicFolder);
printWordTopicDistribution(d, parentWordTopicDistributionFolder, topK);
} else {
printChildTopicAssignment(d, childTopicFolder);
}
}
String parentParameterFile = filePrefix + "parentParameter.txt";
String childParameterFile = filePrefix + "childParameter.txt";
printParameter(parentParameterFile, childParameterFile, m_trainSet);
printTopKChild4Stn(filePrefix, topK);
}
use of structures._ParentDoc in project IR_Base by Linda-sunshine.
the class ACCTM method childTopicInDocProb.
protected double childTopicInDocProb(int tid, _ChildDoc d) {
_ParentDoc pDoc = (_ParentDoc) (d.m_parentDoc);
double pDocTopicSum = Utils.sumOfArray(pDoc.m_sstat);
double cDocTopicSum = Utils.sumOfArray(d.m_sstat);
return (d_alpha + d.getMu() * d.m_parentDoc.m_sstat[tid] / pDocTopicSum + d.m_sstat[tid]) / (m_kAlpha + d.getMu() + cDocTopicSum);
}
Aggregations