[opengm] 372/386: Added logsumexp op for log semiring (to work in log space for sum product alg)

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Aug 31 08:38:36 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/master
in repository opengm.

commit 408a124c10eb54d56302a306463c5c3dab2a42c8
Author: Jeffrey Yunes <jeff at yunes.us>
Date:   Fri Jul 29 12:47:21 2016 -0700

    Added logsumexp op for log semiring (to work in log space for sum product alg)
---
 include/opengm/operations/logsumexp.hxx | 83 +++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/include/opengm/operations/logsumexp.hxx b/include/opengm/operations/logsumexp.hxx
new file mode 100644
index 0000000..87f4d70
--- /dev/null
+++ b/include/opengm/operations/logsumexp.hxx
@@ -0,0 +1,83 @@
+#pragma once
+#ifndef OPENGM_OPERATIONS_LOGSUMEXP_HXX
+#define OPENGM_OPERATIONS_LOGSUMEXP_HXX
+
+#include "adder.hxx"
+#include <cmath>
+
+namespace opengm {
+
+/// Logsumexp (addition in log space) as a unary accumulation
+///
+/// \ingroup operators
+struct Logsumexp
+{
+   /// neutral element (with return)
+   template<class T>
+      static T neutral()
+         { return -std::numeric_limits<T>::infinity(); }
+
+   /// neutral element (call by reference)
+   template<class T>
+      static void neutral(T& out)
+         { out = -std::numeric_limits<T>::infinity(); }
+
+   /// inverse neutral element (with return)
+   template<class T>
+      static T ineutral()
+         { return std::numeric_limits<T>::infinity(); }
+
+   /// inverse neutral element (call by reference)
+   template<class T>
+      static void ineutral(T& out)
+         { out = std::numeric_limits<T>::infinity(); }
+
+   /// operation (in-place)
+   template<class T1, class T2>
+      static void op(const T1& in1, T2& out)
+//         { out = log(exp(out) + exp(in1)); }
+   {
+      T2 theMax = std::max(in1, out);
+      T2 theMin = std::min(in1, out);
+      out = theMax + log(1 + exp(theMin - theMax));  // numerically better
+   }
+
+   /// operation (not in-place)
+   template<class T1,class T2,class T3>
+      static void op(const T1 in1, const T2 in2, T3& out)
+//         { out = log(exp(in1) + exp(in2)); }
+   {
+      T2 theMax = std::max(in1, out);
+      T2 theMin = std::min(in1, out);
+      out = theMax + log(1 + exp(theMin - theMax));  // numerically better
+   }
+
+   /// inverse operation (in-place)
+   template<class T1, class T2>
+      static void iop(const T1& in1,  T2& out)
+//         { out - in1; }  // reference implementation has no effect?
+   { throw "not implemented"; }
+
+   /// inverse operation (call by reference)
+   template<class T1,class T2,class T3>
+      static void iop(const T1 in1, const T2 in2, T3& out)
+         { out = log(exp(in1) - exp(in2)); }
+
+   /// bool operation flag
+   static bool hasbop()
+      { return false; }
+   /// \obsolete inverse boolean operation 
+   /// boolean operation (obsolete)
+   template<class T>
+      static bool bop(const T& in1, const T& in2)
+         { return false; }
+   /// \obsolete inverse boolean operation 
+   /// inverse boolean operation (obsolete)
+   template<class T>
+      static bool ibop(const T& in1, const T& in2)
+         { return false; }
+};
+
+} // namespace opengm
+
+#endif // #ifndef OPENGM_OPERATIONS_INTEGRATOR_HXX

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/opengm.git



More information about the debian-science-commits mailing list