diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-07 22:07:35 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-07 22:07:35 +0000 |
commit | 3cf76cc62341c04e0962705d011ab141190ae1da (patch) | |
tree | a9ec3142922ad248400eaa8105149f0f747d206c /decoder/viterbi.h | |
parent | c4cb48ad003de65f97e0a6013e9da4329c89faf1 (diff) |
compute viterbi result once only per node (for best edge)
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@182 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/viterbi.h')
-rw-r--r-- | decoder/viterbi.h | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/decoder/viterbi.h b/decoder/viterbi.h index d4a97516..6b8bbed1 100644 --- a/decoder/viterbi.h +++ b/decoder/viterbi.h @@ -29,20 +29,23 @@ WeightType Viterbi(const Hypergraph& hg, *cur_node_best_weight = WeightType(1); continue; } + Hypergraph::Edge const* edge_best=0; for (int j = 0; j < num_in_edges; ++j) { const Hypergraph::Edge& edge = hg.edges_[cur_node.in_edges_[j]]; WeightType score = weight(edge); - std::vector<const T*> ants(edge.tail_nodes_.size()); - for (int k = 0; k < edge.tail_nodes_.size(); ++k) { - const int tail_node_index = edge.tail_nodes_[k]; - score *= vit_weight[tail_node_index]; - ants[k] = &vit_result[tail_node_index]; - } - if (*cur_node_best_weight < score) { + for (int k = 0; k < edge.tail_nodes_.size(); ++k) + score *= vit_weight[edge.tail_nodes_[k]]; + if (!edge_best || *cur_node_best_weight < score) { *cur_node_best_weight = score; - traverse(edge, ants, cur_node_best_result); + edge_best=&edge; } } + assert(edge_best); + Hypergraph::Edge const& edgeb=*edge_best; + std::vector<const T*> antsb(edgeb.tail_nodes_.size()); + for (int k = 0; k < edgeb.tail_nodes_.size(); ++k) + antsb[k] = &vit_result[edgeb.tail_nodes_[k]]; + traverse(edgeb, antsb, cur_node_best_result); } std::swap(*result, vit_result.back()); return vit_weight.back(); |