summaryrefslogtreecommitdiff
path: root/decoder/logval.h
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-07 21:26:51 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-07 21:26:51 +0000
commit6b19aa3fa80b6ce0c6b9e6e26ca4a8fcfc41c4fb (patch)
tree3e3b5048ae2f850f52fe7123e4032a7b5b928c6f /decoder/logval.h
parent40bc789dae572c3aa73171c3083326963fe41ffc (diff)
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
Diffstat (limited to 'decoder/logval.h')
-rw-r--r--decoder/logval.h16
1 files changed, 13 insertions, 3 deletions
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 <iostream>
#include <cstdlib>
#include <cmath>
@@ -11,9 +13,12 @@ class LogVal {
public:
LogVal() : s_(), v_(-std::numeric_limits<T>::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<T> exp(T lnx) { return LogVal(lnx,false); }
+
static LogVal<T> One() { return LogVal(1); }
static LogVal<T> Zero() { return LogVal(); }
-
+ static LogVal<T> 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_);
}