diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2012-03-05 16:06:45 -0500 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2012-03-05 16:06:45 -0500 |
commit | 2048ac9943e2695a75b5f0303ca869e66ee32202 (patch) | |
tree | 35de13bff0ce7f1fde619d04d165f7e6ac5b0631 /gi/pf/align-lexonly-pyp.cc | |
parent | ce58cb44771a5194b71682d1602abe2fef9e6f13 (diff) |
use template parameter inference to figure out what type to use for probability computations, templatatize number of floors in MFCR rather than compile-time set
Diffstat (limited to 'gi/pf/align-lexonly-pyp.cc')
-rw-r--r-- | gi/pf/align-lexonly-pyp.cc | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/gi/pf/align-lexonly-pyp.cc b/gi/pf/align-lexonly-pyp.cc index 87f7f6b5..ac0590e0 100644 --- a/gi/pf/align-lexonly-pyp.cc +++ b/gi/pf/align-lexonly-pyp.cc @@ -68,7 +68,7 @@ struct AlignedSentencePair { struct HierarchicalWordBase { explicit HierarchicalWordBase(const unsigned vocab_e_size) : - base(prob_t::One()), r(1,1,1,25,25), u0(-log(vocab_e_size)), l(1,1.0), v(1, 0.0) {} + base(prob_t::One()), r(1,1,1,1), u0(-log(vocab_e_size)), l(1,prob_t::One()), v(1, prob_t::Zero()) {} void ResampleHyperparameters(MT19937* rng) { r.resample_hyperparameters(rng); @@ -80,14 +80,14 @@ struct HierarchicalWordBase { // return p0 of rule.e_ prob_t operator()(const TRule& rule) const { - v[0] = exp(logp0(rule.e_)); - return prob_t(r.prob(rule.e_, v, l)); + v[0].logeq(logp0(rule.e_)); + return r.prob(rule.e_, v.begin(), l.begin()); } void Increment(const TRule& rule) { - v[0] = exp(logp0(rule.e_)); - if (r.increment(rule.e_, v, l, &*prng).count) { - base *= prob_t(v[0] * l[0]); + v[0].logeq(logp0(rule.e_)); + if (r.increment(rule.e_, v.begin(), l.begin(), &*prng).count) { + base *= v[0] * l[0]; } } @@ -105,15 +105,15 @@ struct HierarchicalWordBase { void Summary() const { cerr << "NUMBER OF CUSTOMERS: " << r.num_customers() << " (d=" << r.discount() << ",s=" << r.strength() << ')' << endl; - for (MFCR<vector<WordID> >::const_iterator it = r.begin(); it != r.end(); ++it) + for (MFCR<1,vector<WordID> >::const_iterator it = r.begin(); it != r.end(); ++it) cerr << " " << it->second.total_dish_count_ << " (on " << it->second.table_counts_.size() << " tables)" << TD::GetString(it->first) << endl; } prob_t base; - MFCR<vector<WordID> > r; + MFCR<1,vector<WordID> > r; const double u0; - const vector<double> l; - mutable vector<double> v; + const vector<prob_t> l; + mutable vector<prob_t> v; }; struct BasicLexicalAlignment { |