summaryrefslogtreecommitdiff
path: root/utils/weights.cc
diff options
context:
space:
mode:
authorMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-17 22:05:32 -0700
committerMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-17 22:05:32 -0700
commitf96397d3a34fd5279c92a21f66cfa7538f60cb52 (patch)
tree0e656ef19ae8f1fb6402adc44000b3aa704eb387 /utils/weights.cc
parent769dfa1e69c22d4aea37840a955db7fd2cf3a4d7 (diff)
Save/load state in realtime
Diffstat (limited to 'utils/weights.cc')
-rw-r--r--utils/weights.cc10
1 files changed, 4 insertions, 6 deletions
diff --git a/utils/weights.cc b/utils/weights.cc
index 1284f686..effdfc5e 100644
--- a/utils/weights.cc
+++ b/utils/weights.cc
@@ -163,15 +163,13 @@ string Weights::GetString(const vector<weight_t>& w,
os.precision(17);
int nf = FD::NumFeats();
for (unsigned i = 1; i < nf; i++) {
- if (hide_zero_value_features && w[i] == 0.0) {
+ weight_t val = (i < w.size() ? w[i] : 0.0);
+ if (hide_zero_value_features && val == 0.0) {
continue;
}
- os << FD::Convert(i) << '=' << w[i];
- if (i < nf - 1) {
- os << ' ';
- }
+ os << ' ' << FD::Convert(i) << '=' << val;
}
- return os.str();
+ return os.str().substr(1);
}
void Weights::UpdateFromString(string& w_string,