diff options
Diffstat (limited to 'decoder/viterbi.cc')
-rw-r--r-- | decoder/viterbi.cc | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/decoder/viterbi.cc b/decoder/viterbi.cc index 6a7a970b..ea0cd95e 100644 --- a/decoder/viterbi.cc +++ b/decoder/viterbi.cc @@ -116,15 +116,20 @@ inline bool close_enough(double a,double b,double epsilon) return diff<=epsilon*fabs(a) || diff<=epsilon*fabs(b); } -FeatureVector ViterbiFeatures(Hypergraph const& hg,FeatureWeights const* weights) { +FeatureVector ViterbiFeatures(Hypergraph const& hg,FeatureWeights const* weights,bool fatal_dotprod_disagreement) { FeatureVector r; const prob_t p = Viterbi<FeatureVectorTraversal>(hg, &r); if (weights) { double logp=log(p); double fv=r.dot(*weights); const double EPSILON=1e-5; - if (!close_enough(logp,fv,EPSILON)) - throw std::runtime_error("ViterbiFeatures log prob disagrees with features.dot(weights)"+boost::lexical_cast<string>(logp)+"!="+boost::lexical_cast<string>(fv)); + if (!close_enough(logp,fv,EPSILON)) { + complaint="ViterbiFeatures log prob disagrees with features.dot(weights)"+boost::lexical_cast<string>(logp)+"!="+boost::lexical_cast<string>(fv); + if (fatal_dotprod_disagreement) + throw std::runtime_error(complaint); + else + cerr<<complaint<<endl; + } return r; } |