summaryrefslogtreecommitdiff
path: root/decoder/inside_outside.h
diff options
context:
space:
mode:
authorgraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-02 07:57:23 +0000
committergraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-02 07:57:23 +0000
commitf9859ad4116733e145d7b8eb31c3cc9318ff7564 (patch)
tree92f6942fc7fd7066eb400bce6d2cbd2fee46c801 /decoder/inside_outside.h
parent6da285dfa7b0a1929dcec882d7e48a585e878d18 (diff)
fake tdict names for non-ids, push viterbi cost to root in hg, store as feature. type erased fsa feature via virtual interface. made lexical_cast assume C locale for speed.
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@465 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/inside_outside.h')
-rw-r--r--decoder/inside_outside.h26
1 files changed, 17 insertions, 9 deletions
diff --git a/decoder/inside_outside.h b/decoder/inside_outside.h
index 128d89da..48e31bb3 100644
--- a/decoder/inside_outside.h
+++ b/decoder/inside_outside.h
@@ -40,13 +40,14 @@ WeightType Inside(const Hypergraph& hg,
for (int i = 0; i < num_nodes; ++i) {
const Hypergraph::Node& cur_node = hg.nodes_[i];
WeightType* const cur_node_inside_score = &inside_score[i];
- const int num_in_edges = cur_node.in_edges_.size();
+ Hypergraph::EdgesVector const& in=cur_node.in_edges_;
+ const int num_in_edges = in.size();
if (num_in_edges == 0) {
- *cur_node_inside_score = WeightType(1);
+ *cur_node_inside_score = WeightType(1); //FIXME: why not call weight(edge) instead?
continue;
}
for (int j = 0; j < num_in_edges; ++j) {
- const Hypergraph::Edge& edge = hg.edges_[cur_node.in_edges_[j]];
+ const Hypergraph::Edge& edge = hg.edges_[in[j]];
WeightType score = weight(edge);
for (int k = 0; k < edge.tail_nodes_.size(); ++k) {
const int tail_node_index = edge.tail_nodes_[k];
@@ -76,9 +77,10 @@ void Outside(const Hypergraph& hg,
for (int i = num_nodes - 1; i >= 0; --i) {
const Hypergraph::Node& cur_node = hg.nodes_[i];
const WeightType& head_node_outside_score = outside_score[i];
- const int num_in_edges = cur_node.in_edges_.size();
+ Hypergraph::EdgesVector const& in=cur_node.in_edges_;
+ const int num_in_edges = in.size();
for (int j = 0; j < num_in_edges; ++j) {
- const Hypergraph::Edge& edge = hg.edges_[cur_node.in_edges_[j]];
+ const Hypergraph::Edge& edge = hg.edges_[in[j]];
WeightType head_and_edge_weight = weight(edge);
head_and_edge_weight *= head_node_outside_score;
const int num_tail_nodes = edge.tail_nodes_.size();
@@ -122,6 +124,10 @@ struct InsideOutsides {
KType compute(Hypergraph const& hg,KWeightFunction const& kwf=KWeightFunction()) {
return compute(hg,Outside1<KType>(),kwf);
}
+ template <class KWeightFunction>
+ KType compute_inside(Hypergraph const& hg,KWeightFunction const& kwf=KWeightFunction()) {
+ }
+
template <class KWeightFunction,class O1>
KType compute(Hypergraph const& hg,O1 outside1,KWeightFunction const& kwf=KWeightFunction()) {
typedef typename KWeightFunction::Weight KType2;
@@ -139,9 +145,10 @@ struct InsideOutsides {
typename XWeightFunction::Result x; // default constructor is semiring 0
for (int i = 0,num_nodes=hg.nodes_.size(); i < num_nodes; ++i) {
const Hypergraph::Node& cur_node = hg.nodes_[i];
- const int num_in_edges = cur_node.in_edges_.size();
+ Hypergraph::EdgesVector const& in=cur_node.in_edges_;
+ const int num_in_edges = in.size();
for (int j = 0; j < num_in_edges; ++j) {
- const Hypergraph::Edge& edge = hg.edges_[cur_node.in_edges_[j]];
+ const Hypergraph::Edge& edge = hg.edges_[in[j]];
KType kbar_e = outside[i];
const int num_tail_nodes = edge.tail_nodes_.size();
for (int k = 0; k < num_tail_nodes; ++k)
@@ -156,9 +163,10 @@ struct InsideOutsides {
vs.resize(hg.edges_.size());
for (int i = 0,num_nodes=hg.nodes_.size(); i < num_nodes; ++i) {
const Hypergraph::Node& cur_node = hg.nodes_[i];
- const int num_in_edges = cur_node.in_edges_.size();
+ Hypergraph::EdgesVector const& in=cur_node.in_edges_;
+ const int num_in_edges = in.size();
for (int j = 0; j < num_in_edges; ++j) {
- int edgei=cur_node.in_edges_[j];
+ int edgei=in[j];
const Hypergraph::Edge& edge = hg.edges_[edgei];
V x=weight(edge)*outside[i];
const int num_tail_nodes = edge.tail_nodes_.size();