diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2011-05-03 01:02:45 -0400 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2011-05-03 01:02:45 -0400 |
commit | 5403c3cc854b061e9c5c8b3ef783b7b4d2e9387c (patch) | |
tree | 51e4340c58f1783f30089e181f946d981668aa2d | |
parent | a53e3f0f5d1a4a96479544b5c48a2eb1dcdb4064 (diff) |
weight setting bug
-rw-r--r-- | decoder/decoder.cc | 5 | ||||
-rw-r--r-- | decoder/ff.h | 3 | ||||
-rw-r--r-- | utils/sparse_vector.h | 10 |
3 files changed, 12 insertions, 6 deletions
diff --git a/decoder/decoder.cc b/decoder/decoder.cc index 0d7e84ad..d8dd0c61 100644 --- a/decoder/decoder.cc +++ b/decoder/decoder.cc @@ -176,8 +176,11 @@ struct DecoderImpl { bool Decode(const string& input, DecoderObserver*); void SetWeights(const vector<double>& weights) { init_weights = weights; - for (int i = 0; i < rescoring_passes.size(); ++i) + for (int i = 0; i < rescoring_passes.size(); ++i) { + if (rescoring_passes[i].models) + rescoring_passes[i].models->SetWeights(weights); rescoring_passes[i].weight_vector = weights; + } } void SetId(int next_sent_id) { sent_id = next_sent_id - 1; } diff --git a/decoder/ff.h b/decoder/ff.h index 89b8b067..c3aa9b6d 100644 --- a/decoder/ff.h +++ b/decoder/ff.h @@ -264,6 +264,9 @@ class ModelSet { ModelSet(const std::vector<double>& weights, const std::vector<const FeatureFunction*>& models); + // TODO stop stupid copy + void SetWeights(const std::vector<double>& w) { weights_ = w; } + // sets edge->feature_values_ and edge->edge_prob_ // NOTE: edge must not necessarily be in hg.edges_ but its TAIL nodes // must be. edge features are supposed to be overwritten, not added to (possibly because rule features aren't in ModelSet so need to be left alone diff --git a/utils/sparse_vector.h b/utils/sparse_vector.h index 274220ef..e3721b50 100644 --- a/utils/sparse_vector.h +++ b/utils/sparse_vector.h @@ -54,16 +54,16 @@ SparseVector<T> operator*(const SparseVector<T>& a, const T& b) { return result *= b; } -template <class T> -SparseVector<T> operator/(const SparseVector<T>& a, const double& b) { +template <class T, typename S> +SparseVector<T> operator/(const SparseVector<T>& a, const S& b) { SparseVector<T> result = a; - return result *= b; + return result /= b; } template <class T> -SparseVector<T> operator/(const SparseVector<T>& a, const T& b) { +SparseVector<T> operator/(const SparseVector<T>& a, const double& b) { SparseVector<T> result = a; - return result *= b; + return result /= b; } #include "fdict.h" |