print feature counts to file

This commit is contained in:
Eva Hasler 2012-03-29 22:01:17 +01:00
parent 03d3cb6a7a
commit 0a537a9f58
4 changed files with 8 additions and 5 deletions

View File

@ -606,8 +606,10 @@ int main(int argc, char** argv) {
string f1 = "decode_hope_epoch0";
string f2 = "decode_fear_epoch0";
string s1 = "sparse_feature_hope_counts";
ofstream hopePlusFeatures(f1.c_str());
ofstream fearPlusFeatures(f2.c_str());
ofstream sparseFeatureCounts(s1.c_str());
if (!hopePlusFeatures || !fearPlusFeatures) {
ostringstream msg;
msg << "Unable to open file";
@ -1362,7 +1364,8 @@ int main(int argc, char** argv) {
if (weightEpochDump == weightDumpFrequency && printFeatureInfo) {
// print out all features with counts
mixedAverageWeights.PrintSparseFeatureCounts();
mixedAverageWeights.PrintSparseFeatureCounts(sparseFeatureCounts);
sparseFeatureCounts.close();
}
}
}

View File

@ -323,9 +323,9 @@ namespace Moses {
FName::incrementId((i->first).name());
}
void FVector::printSparseFeatureCounts() {
void FVector::printSparseFeatureCounts(std::ofstream& out) {
for (const_iterator i = cbegin(); i != cend(); ++i)
std::cerr << (i->first).name() << ": " << FName::getIdCount((i->first).name()) << std::endl;
out << (i->first).name() << ": " << FName::getIdCount((i->first).name()) << std::endl;
}
size_t FVector::pruneSparseFeatures(size_t threshold) {

View File

@ -202,7 +202,7 @@ namespace Moses {
void sparsePlusEquals(const FVector& rhs);
void incrementSparseFeatures();
void printSparseFeatureCounts();
void printSparseFeatureCounts(std::ofstream& out);
size_t pruneSparseFeatures(size_t threshold);
size_t pruneZeroWeightFeatures();

View File

@ -365,7 +365,7 @@ public:
void Save(std::ostream&) const;
void IncrementSparseFeatures() { m_scores.incrementSparseFeatures(); }
void PrintSparseFeatureCounts() { m_scores.printSparseFeatureCounts(); }
void PrintSparseFeatureCounts(std::ofstream& out) { m_scores.printSparseFeatureCounts(out); }
size_t PruneSparseFeatures(size_t threshold) { return m_scores.pruneSparseFeatures(threshold); }
size_t PruneZeroWeightFeatures() { return m_scores.pruneZeroWeightFeatures(); }