use of structures._Stn in project IR_Base by Linda-sunshine.
the class ACCTM method initTest.
protected void initTest(ArrayList<_Doc> sampleTestSet, _Doc d) {
_ParentDoc pDoc = (_ParentDoc) d;
for (_Stn stnObj : pDoc.getSentences()) {
stnObj.setTopicsVct(number_of_topics);
}
int testLength = 0;
pDoc.setTopics4GibbsTest(number_of_topics, 0, testLength);
sampleTestSet.add(pDoc);
pDoc.createSparseVct4Infer();
for (_ChildDoc cDoc : pDoc.m_childDocs) {
testLength = (int) (m_testWord4PerplexityProportion * cDoc.getTotalDocLength());
cDoc.setTopics4GibbsTest(number_of_topics, 0, testLength);
sampleTestSet.add(cDoc);
cDoc.createSparseVct4Infer();
computeTestMu4Doc(cDoc);
}
}
use of structures._Stn in project IR_Base by Linda-sunshine.
the class ACCTM_C method initTest.
@Override
protected void initTest(ArrayList<_Doc> sampleTestSet, _Doc d) {
_ParentDoc pDoc = (_ParentDoc) d;
for (_Stn stnObj : pDoc.getSentences()) {
stnObj.setTopicsVct(number_of_topics);
}
// //for conditional perplexity
int testLength = 0;
pDoc.setTopics4GibbsTest(number_of_topics, 0, testLength);
sampleTestSet.add(pDoc);
pDoc.createSparseVct4Infer();
for (_ChildDoc cDoc : pDoc.m_childDocs) {
testLength = (int) (m_testWord4PerplexityProportion * cDoc.getTotalDocLength());
((_ChildDoc4BaseWithPhi) cDoc).createXSpace(number_of_topics, m_gamma.length, vocabulary_size, d_beta);
((_ChildDoc4BaseWithPhi) cDoc).setTopics4GibbsTest(number_of_topics, 0, testLength);
sampleTestSet.add(cDoc);
cDoc.createSparseVct4Infer();
computeTestMu4Doc(cDoc);
}
}
use of structures._Stn in project IR_Base by Linda-sunshine.
the class ACCTM_CHard 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) {
d.setTopics4Gibbs(number_of_topics, 0);
for (_Stn stnObj : d.getSentences()) stnObj.setTopic(number_of_topics);
} else if (d instanceof _ChildDoc4BaseWithPhi) {
((_ChildDoc4BaseWithPhi_Hard) d).createXSpace(number_of_topics, m_gamma.length, vocabulary_size, d_beta);
((_ChildDoc4BaseWithPhi_Hard) d).setTopics4Gibbs(number_of_topics, 0);
computeMu4Doc((_ChildDoc) d);
}
if (d instanceof _ParentDoc) {
for (_Word w : d.getWords()) {
word_topic_sstat[w.getTopic()][w.getIndex()]++;
m_sstat[w.getTopic()]++;
}
} else if (d instanceof _ChildDoc4BaseWithPhi) {
for (_Word w : d.getWords()) {
int xid = w.getX();
int tid = w.getTopic();
int wid = w.getIndex();
// update global
if (xid == 0) {
word_topic_sstat[tid][wid]++;
m_sstat[tid]++;
}
}
}
}
imposePrior();
m_statisticsNormalized = false;
}
use of structures._Stn in project IR_Base by Linda-sunshine.
the class ACCTM_CHard method initTest.
@Override
protected void initTest(ArrayList<_Doc> sampleTestSet, _Doc d) {
_ParentDoc pDoc = (_ParentDoc) d;
for (_Stn stnObj : pDoc.getSentences()) {
stnObj.setTopicsVct(number_of_topics);
}
int testLength = (int) (m_testWord4PerplexityProportion * d.getTotalDocLength());
testLength = 0;
pDoc.setTopics4GibbsTest(number_of_topics, 0, testLength);
sampleTestSet.add(pDoc);
pDoc.createSparseVct4Infer();
for (_ChildDoc cDoc : pDoc.m_childDocs) {
testLength = (int) (m_testWord4PerplexityProportion * cDoc.getTotalDocLength());
((_ChildDoc4BaseWithPhi_Hard) cDoc).createXSpace(number_of_topics, m_gamma.length, vocabulary_size, d_beta);
((_ChildDoc4BaseWithPhi_Hard) cDoc).setTopics4GibbsTest(number_of_topics, 0, testLength);
sampleTestSet.add(cDoc);
cDoc.createSparseVct4Infer();
computeTestMu4Doc(cDoc);
}
}
use of structures._Stn in project IR_Base by Linda-sunshine.
the class ACCTM_C_test method printParameter.
public 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(d.getName() + "\t");
childParaOut.print(cDoc.getName() + "\t");
childParaOut.print("topicProportion\t");
for (int k = 0; k < number_of_topics; k++) {
childParaOut.print(cDoc.m_xTopics[0][k] + "\t");
}
childParaOut.print("xProportion\t");
for (int x = 0; x < m_gamma.length; x++) {
childParaOut.print(cDoc.m_xProportion[x] + "\t");
}
childParaOut.println();
}
}
}
parentParaOut.flush();
parentParaOut.close();
childParaOut.flush();
childParaOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations