summaryrefslogtreecommitdiff
path: root/decoder/hg.cc
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-12 03:42:47 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-12 03:42:47 +0000
commitf6b270b85bc23ae8310ec7848e1e574f33d63e38 (patch)
tree843c9a0a2d751cb0203f356e2ad855e61044498b /decoder/hg.cc
parent7220bd3685bb7cbd6a68749f55314892af5605c9 (diff)
DEBUG_PROMISE - looks ok
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@220 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/hg.cc')
-rw-r--r--decoder/hg.cc15
1 files changed, 11 insertions, 4 deletions
diff --git a/decoder/hg.cc b/decoder/hg.cc
index b017b183..0a257092 100644
--- a/decoder/hg.cc
+++ b/decoder/hg.cc
@@ -192,16 +192,23 @@ void Hypergraph::SetPromise(NodeProbs const& inside,NodeProbs const& outside,dou
if (!nn) return;
assert(inside.size()==nn);
assert(outside.size()==nn);
- double sum; //TODO: prevent underflow by using prob_t?
+ double sum=0; //TODO: prevent underflow by using prob_t?
if (normalize)
for (int i=0;i<nn;++i) {
sum+=(nodes_[i].promise=pow(inside[i]*outside[i],power));
}
+ double by=nn/sum; // so avg promise is 1
if (normalize) {
- double by=nn/sum; // so avg promise is 1
for (int i=0;i<nn;++i)
nodes_[i].promise*=by;
}
+//#define DEBUG_PROMISE
+#ifdef DEBUG_PROMISE
+ cerr << "\n\nPer-node promises:\n";
+ cerr << "promise\tinside\toutside\t(power="<<power<<" normalize="<<normalize<<" sum="<<sum<<" by="<<by<<")"<<endl;
+ for (int i=0;i<nn;++i)
+ cerr <<nodes_[i].promise<<'\t'<<inside[i]<<'\t'<<outside[i]<<endl;
+#endif
}
@@ -247,11 +254,11 @@ bool Hypergraph::PruneInsideOutside(double alpha,double density,const EdgeMask*
assert(!use_beam||alpha>0);
assert(!use_density||density>=1);
assert(!use_sum_prod_semiring||scale>0);
- int rnum;
+ int rnum=edges_.size();
if (use_density) {
const int plen = ViterbiPathLength(*this);
vector<WordID> bp;
- rnum = min(static_cast<int>(edges_.size()), static_cast<int>(density * static_cast<double>(plen)));
+ rnum = min(rnum, static_cast<int>(density * static_cast<double>(plen)));
cerr << "Density pruning: keep "<<rnum<<" of "<<edges_.size()<<" edges (viterbi = "<<plen<<" edges)"<<endl;
if (rnum == edges_.size()) {
cerr << "No pruning required: denisty already sufficient\n";