From 6b19aa3fa80b6ce0c6b9e6e26ca4a8fcfc41c4fb Mon Sep 17 00:00:00 2001 From: graehl Date: Wed, 7 Jul 2010 21:26:51 +0000 Subject: safe hg pruning without needing additional inside reachability pass (max margin tightness is less at bottom of derivation tree) git-svn-id: https://ws10smt.googlecode.com/svn/trunk@181 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/logval.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'decoder/logval.h') diff --git a/decoder/logval.h b/decoder/logval.h index 622b308e..457818e7 100644 --- a/decoder/logval.h +++ b/decoder/logval.h @@ -1,6 +1,8 @@ #ifndef LOGVAL_H_ #define LOGVAL_H_ +#define LOGVAL_CHECK_NEG_POW false + #include #include #include @@ -11,9 +13,12 @@ class LogVal { public: LogVal() : s_(), v_(-std::numeric_limits::infinity()) {} explicit LogVal(double x) : s_(std::signbit(x)), v_(s_ ? std::log(-x) : std::log(x)) {} + LogVal(double lnx,bool sign) : s_(sign),v_(lnx) {} + static LogVal exp(T lnx) { return LogVal(lnx,false); } + static LogVal One() { return LogVal(1); } static LogVal Zero() { return LogVal(); } - + static LogVal e() { return LogVal(1,false); } void logeq(const T& v) { s_ = false; v_ = v; } LogVal& operator+=(const LogVal& a) { @@ -54,12 +59,13 @@ class LogVal { } LogVal& poweq(const T& power) { +#if LOGVAL_CHECK_NEG_POW if (s_) { std::cerr << "poweq(T) not implemented when s_ is true\n"; std::abort(); - } else { + } else +#endif v_ *= power; - } return *this; } @@ -71,6 +77,10 @@ class LogVal { return res; } + LogVal root(const T& root) const { + return pow(1/root); + } + operator T() const { if (s_) return -std::exp(v_); else return std::exp(v_); } -- cgit v1.2.3