use of structures.MyPriorityQueue in project IR_Base by Linda-sunshine.
the class DCMLDA_test method printTopBeta.
protected void printTopBeta(int k, String topBetaFile) {
System.out.println("TopWord FilePath:" + topBetaFile);
Arrays.fill(m_sstat, 0);
for (_Doc d : m_trainSet) {
for (int i = 0; i < number_of_topics; i++) m_sstat[i] += m_logSpace ? Math.exp(d.m_topics[i]) : d.m_topics[i];
}
Utils.L1Normalization(m_sstat);
try {
PrintWriter topWordWriter = new PrintWriter(new File(topBetaFile));
for (int i = 0; i < m_beta.length; i++) {
MyPriorityQueue<_RankItem> fVector = new MyPriorityQueue<_RankItem>(k);
for (int j = 0; j < vocabulary_size; j++) fVector.add(new _RankItem(m_corpus.getFeature(j), m_beta[i][j]));
topWordWriter.format("Topic %d(%.5f):\t", i, m_sstat[i]);
for (_RankItem it : fVector) topWordWriter.format("%s(%.5f)\t", it.m_name, m_logSpace ? Math.exp(it.m_value) : it.m_value);
topWordWriter.write("\n");
}
topWordWriter.close();
} catch (Exception ex) {
System.err.print("File Not Found");
}
}
use of structures.MyPriorityQueue in project IR_Base by Linda-sunshine.
the class DCMLDA_test method printTopWord.
protected void printTopWord(int k, String topWordFile) {
System.out.println("TopWord FilePath:" + topWordFile);
Arrays.fill(m_sstat, 0);
for (_Doc d : m_trainSet) {
for (int i = 0; i < number_of_topics; i++) m_sstat[i] += m_logSpace ? Math.exp(d.m_topics[i]) : d.m_topics[i];
}
Utils.L1Normalization(m_sstat);
try {
PrintWriter topWordWriter = new PrintWriter(new File(topWordFile));
for (int i = 0; i < topic_term_probabilty.length; i++) {
MyPriorityQueue<_RankItem> fVector = new MyPriorityQueue<_RankItem>(k);
for (int j = 0; j < vocabulary_size; j++) fVector.add(new _RankItem(m_corpus.getFeature(j), topic_term_probabilty[i][j]));
topWordWriter.format("Topic %d(%.5f):\t", i, m_sstat[i]);
for (_RankItem it : fVector) topWordWriter.format("%s(%.5f)\t", it.m_name, m_logSpace ? Math.exp(it.m_value) : it.m_value);
topWordWriter.write("\n");
}
topWordWriter.close();
} catch (Exception ex) {
System.err.print("File Not Found");
}
}
use of structures.MyPriorityQueue in project IR_Base by Linda-sunshine.
the class sparseClusterDCMLDA_test method printWordTopicDistribution.
protected void printWordTopicDistribution(int cID, File wordTopicDistributionFolder, int k) {
String wordTopicDistributionFile = cID + ".txt";
try {
PrintWriter pw = new PrintWriter(new File(wordTopicDistributionFolder, wordTopicDistributionFile));
for (int i = 0; i < number_of_topics; i++) {
MyPriorityQueue<_RankItem> fVector = new MyPriorityQueue<_RankItem>(k);
for (int v = 0; v < vocabulary_size; v++) {
String featureName = m_corpus.getFeature(v);
double wordProb = m_clusterTopicWordProb[cID][i][v];
_RankItem ri = new _RankItem(featureName, wordProb);
fVector.add(ri);
}
pw.format("Topic %d(%.5f):\t", i, m_clusterTopicProb[cID][i]);
for (_RankItem it : fVector) pw.format("%s(%.5f)\t", it.m_name, m_logSpace ? Math.exp(it.m_value) : it.m_value);
pw.write("\n");
}
pw.flush();
pw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
use of structures.MyPriorityQueue in project IR_Base by Linda-sunshine.
the class sparseDCMLDA_test method printTopWord.
protected void printTopWord(int k, String topWordFile) {
System.out.println("TopWord FilePath:" + topWordFile);
Arrays.fill(m_sstat, 0);
for (_Doc d : m_trainSet) {
for (int i = 0; i < number_of_topics; i++) m_sstat[i] += m_logSpace ? Math.exp(d.m_topics[i]) : d.m_topics[i];
}
Utils.L1Normalization(m_sstat);
try {
PrintWriter topWordWriter = new PrintWriter(new File(topWordFile));
for (int i = 0; i < topic_term_probabilty.length; i++) {
MyPriorityQueue<_RankItem> fVector = new MyPriorityQueue<_RankItem>(k);
for (int j = 0; j < vocabulary_size; j++) fVector.add(new _RankItem(m_corpus.getFeature(j), topic_term_probabilty[i][j]));
topWordWriter.format("Topic %d(%.5f):\t", i, m_sstat[i]);
for (_RankItem it : fVector) topWordWriter.format("%s(%.5f)\t", it.m_name, m_logSpace ? Math.exp(it.m_value) : it.m_value);
topWordWriter.write("\n");
}
topWordWriter.close();
} catch (Exception ex) {
System.err.print("File Not Found");
}
}
use of structures.MyPriorityQueue in project IR_Base by Linda-sunshine.
the class sparseDCMLDA_test method printWordTopicDistribution.
protected void printWordTopicDistribution(_Doc d, File wordTopicDistributionFolder, int k) {
String wordTopicDistributionFile = d.getName() + ".txt";
try {
PrintWriter pw = new PrintWriter(new File(wordTopicDistributionFolder, wordTopicDistributionFile));
_Doc4DCMLDA DCMDoc = (_Doc4DCMLDA) d;
for (int i = 0; i < number_of_topics; i++) {
MyPriorityQueue<_RankItem> fVector = new MyPriorityQueue<_RankItem>(k);
for (int v = 0; v < vocabulary_size; v++) {
String featureName = m_corpus.getFeature(v);
double wordProb = DCMDoc.m_wordTopic_prob[i][v];
_RankItem ri = new _RankItem(featureName, wordProb);
fVector.add(ri);
}
pw.format("Topic %d(%.5f):\t", i, d.m_topics[i]);
for (_RankItem it : fVector) pw.format("%s(%.5f)\t", it.m_name, m_logSpace ? Math.exp(it.m_value) : it.m_value);
pw.write("\n");
}
pw.flush();
pw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
Aggregations