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
commitc4cb48ad003de65f97e0a6013e9da4329c89faf1 (patch)
tree1d96a2224375bfbb0a8fb97c975147d37a4e324d /decoder/logval.h
parentffe002f8792dd8693c12e9bc6a7f715ca170acfc (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_);
}