summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-09-21 20:10:27 +0000
committerredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-09-21 20:10:27 +0000
commit1cc6a37d1a93cbcb14a980fc64d7bdbe6db486fd (patch)
tree4ef09d87e88c3cfd5d950d388644502d0d4a92ed /utils
parente5625218ad4e0ea8216ad55125fc1099ccab0e19 (diff)
fix for lattice cost bug
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@653 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'utils')
-rw-r--r--utils/weights.cc18
-rw-r--r--utils/weights.h2
2 files changed, 13 insertions, 7 deletions
diff --git a/utils/weights.cc b/utils/weights.cc
index 84647585..ea8bd816 100644
--- a/utils/weights.cc
+++ b/utils/weights.cc
@@ -4,11 +4,12 @@
#include "fdict.h"
#include "filelib.h"
+#include "verbose.h"
using namespace std;
void Weights::InitFromFile(const std::string& filename, vector<string>* feature_list) {
- cerr << "Reading weights from " << filename << endl;
+ if (!SILENT) cerr << "Reading weights from " << filename << endl;
ReadFile in_file(filename);
istream& in = *in_file.stream();
assert(in);
@@ -38,17 +39,22 @@ void Weights::InitFromFile(const std::string& filename, vector<string>* feature_
wv_[fid] = val;
if (feature_list) { feature_list->push_back(FD::Convert(fid)); }
++weight_count;
- if (weight_count % 50000 == 0) { cerr << '.' << flush; fl = true; }
- if (weight_count % 2000000 == 0) { cerr << " [" << weight_count << "]\n"; fl = false; }
+ if (!SILENT) {
+ if (weight_count % 50000 == 0) { cerr << '.' << flush; fl = true; }
+ if (weight_count % 2000000 == 0) { cerr << " [" << weight_count << "]\n"; fl = false; }
+ }
+ }
+ if (!SILENT) {
+ if (fl) { cerr << endl; }
+ cerr << "Loaded " << weight_count << " feature weights\n";
}
- if (fl) { cerr << endl; }
- cerr << "Loaded " << weight_count << " feature weights\n";
}
-void Weights::WriteToFile(const std::string& fname, bool hide_zero_value_features) const {
+void Weights::WriteToFile(const std::string& fname, bool hide_zero_value_features, const string* extra) const {
WriteFile out(fname);
ostream& o = *out.stream();
assert(o);
+ if (extra) { o << "# " << *extra << endl; }
o.precision(17);
const int num_feats = FD::NumFeats();
for (int i = 1; i < num_feats; ++i) {
diff --git a/utils/weights.h b/utils/weights.h
index f19aa3ce..1849f959 100644
--- a/utils/weights.h
+++ b/utils/weights.h
@@ -10,7 +10,7 @@ class Weights {
public:
Weights() {}
void InitFromFile(const std::string& fname, std::vector<std::string>* feature_list = NULL);
- void WriteToFile(const std::string& fname, bool hide_zero_value_features = true) const;
+ void WriteToFile(const std::string& fname, bool hide_zero_value_features = true, const std::string* extra = NULL) const;
void InitVector(std::vector<double>* w) const;
void InitSparseVector(SparseVector<double>* w) const;
void InitFromVector(const std::vector<double>& w);