summaryrefslogtreecommitdiff
path: root/gi
diff options
context:
space:
mode:
Diffstat (limited to 'gi')
-rw-r--r--gi/pf/align-lexonly-pyp.cc20
-rw-r--r--gi/pf/conditional_pseg.h22
-rw-r--r--gi/pf/learn_cfg.cc8
3 files changed, 25 insertions, 25 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 {
diff --git a/gi/pf/conditional_pseg.h b/gi/pf/conditional_pseg.h
index 86403d8d..ef73e332 100644
--- a/gi/pf/conditional_pseg.h
+++ b/gi/pf/conditional_pseg.h
@@ -17,13 +17,13 @@
template <typename ConditionalBaseMeasure>
struct MConditionalTranslationModel {
explicit MConditionalTranslationModel(ConditionalBaseMeasure& rcp0) :
- rp0(rcp0), lambdas(1, 1.0), p0s(1) {}
+ rp0(rcp0), lambdas(1, prob_t::One()), p0s(1) {}
void Summary() const {
std::cerr << "Number of conditioning contexts: " << r.size() << std::endl;
for (RuleModelHash::const_iterator it = r.begin(); it != r.end(); ++it) {
std::cerr << TD::GetString(it->first) << " \t(d=" << it->second.discount() << ",s=" << it->second.strength() << ") --------------------------" << std::endl;
- for (MFCR<TRule>::const_iterator i2 = it->second.begin(); i2 != it->second.end(); ++i2)
+ for (MFCR<1,TRule>::const_iterator i2 = it->second.begin(); i2 != it->second.end(); ++i2)
std::cerr << " " << -1 << '\t' << i2->first << std::endl;
}
}
@@ -46,10 +46,10 @@ struct MConditionalTranslationModel {
int IncrementRule(const TRule& rule, MT19937* rng) {
RuleModelHash::iterator it = r.find(rule.f_);
if (it == r.end()) {
- it = r.insert(make_pair(rule.f_, MFCR<TRule>(1, 1.0, 1.0, 1.0, 1.0, 1e-9, 4.0))).first;
+ it = r.insert(make_pair(rule.f_, MFCR<1,TRule>(1.0, 1.0, 1.0, 1.0, 1e-9, 4.0))).first;
}
- p0s[0] = rp0(rule).as_float();
- TableCount delta = it->second.increment(rule, p0s, lambdas, rng);
+ p0s[0] = rp0(rule);
+ TableCount delta = it->second.increment(rule, p0s.begin(), lambdas.begin(), rng);
return delta.count;
}
@@ -57,10 +57,10 @@ struct MConditionalTranslationModel {
prob_t p;
RuleModelHash::const_iterator it = r.find(rule.f_);
if (it == r.end()) {
- p.logeq(log(rp0(rule)));
+ p = rp0(rule);
} else {
- p0s[0] = rp0(rule).as_float();
- p = prob_t(it->second.prob(rule, p0s, lambdas));
+ p0s[0] = rp0(rule);
+ p = it->second.prob(rule, p0s.begin(), lambdas.begin());
}
return p;
}
@@ -80,11 +80,11 @@ struct MConditionalTranslationModel {
const ConditionalBaseMeasure& rp0;
typedef std::tr1::unordered_map<std::vector<WordID>,
- MFCR<TRule>,
+ MFCR<1, TRule>,
boost::hash<std::vector<WordID> > > RuleModelHash;
RuleModelHash r;
- std::vector<double> lambdas;
- mutable std::vector<double> p0s;
+ std::vector<prob_t> lambdas;
+ mutable std::vector<prob_t> p0s;
};
template <typename ConditionalBaseMeasure>
diff --git a/gi/pf/learn_cfg.cc b/gi/pf/learn_cfg.cc
index bf157828..ed1772bf 100644
--- a/gi/pf/learn_cfg.cc
+++ b/gi/pf/learn_cfg.cc
@@ -127,20 +127,20 @@ struct HieroLMModel {
nts(num_nts, CCRP<TRule>(1,1,1,1)) {}
prob_t Prob(const TRule& r) const {
- return nts[nt_id_to_index[-r.lhs_]].probT<prob_t>(r, p0(r));
+ return nts[nt_id_to_index[-r.lhs_]].prob(r, p0(r));
}
inline prob_t p0(const TRule& r) const {
if (kHIERARCHICAL_PRIOR)
- return q0.probT<prob_t>(r, base(r));
+ return q0.prob(r, base(r));
else
return base(r);
}
int Increment(const TRule& r, MT19937* rng) {
- const int delta = nts[nt_id_to_index[-r.lhs_]].incrementT<prob_t>(r, p0(r), rng);
+ const int delta = nts[nt_id_to_index[-r.lhs_]].increment(r, p0(r), rng);
if (kHIERARCHICAL_PRIOR && delta)
- q0.incrementT<prob_t>(r, base(r), rng);
+ q0.increment(r, base(r), rng);
return delta;
// return x.increment(r);
}