aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/PLRsearch/log_plus.py
diff options
context:
space:
mode:
authorJan Gelety <jgelety@cisco.com>2019-11-12 05:27:43 +0100
committerJan Gelety <jgelety@cisco.com>2019-11-28 18:26:21 +0100
commitd68951ac245150eeefa6e0f4156e4c1b5c9e9325 (patch)
tree487554a7547218d27f0a61ec02b70502c32cdcb4 /resources/libraries/python/PLRsearch/log_plus.py
parented0258a440cfad7023d643f717ab78ac568dc59b (diff)
Python3: resources and libraries
Change-Id: I1392c06b1d64f62b141d24c0d42a8e36913b15e2 Signed-off-by: Jan Gelety <jgelety@cisco.com>
Diffstat (limited to 'resources/libraries/python/PLRsearch/log_plus.py')
-rw-r--r--resources/libraries/python/PLRsearch/log_plus.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/resources/libraries/python/PLRsearch/log_plus.py b/resources/libraries/python/PLRsearch/log_plus.py
index 1c802a5599..62378f6f2c 100644
--- a/resources/libraries/python/PLRsearch/log_plus.py
+++ b/resources/libraries/python/PLRsearch/log_plus.py
@@ -24,7 +24,7 @@ functions of this module use None as -inf.
TODO: Figure out a more performant way of handling -inf.
-The functions handle the common task of adding or substracting
+The functions handle the common task of adding or subtracting
two numbers where both operands and the result is given in logarithm form.
There are conditionals to make sure overflow does not happen (if possible)
during the computation."""
@@ -33,7 +33,7 @@ import math
def log_plus(first, second):
- """Return logarithm of the sum of two exponentials.
+ """Return logarithm of the sum of two exponents.
Basically math.log(math.exp(first) + math.exp(second))
which avoids overflow and uses None as math.log(0.0).
@@ -47,19 +47,19 @@ def log_plus(first, second):
:returns: Logarithm of the sum (or None if zero).
:rtype: float
"""
-
if first is None:
return second
if second is None:
return first
if second > first:
- return second + math.log(1.0 + math.exp(first - second))
+ retval = second + math.log(1.0 + math.exp(first - second))
else:
- return first + math.log(1.0 + math.exp(second - first))
+ retval = first + math.log(1.0 + math.exp(second - first))
+ return retval
def log_minus(first, second):
- """Return logarithm of the difference of two exponentials.
+ """Return logarithm of the difference of two exponents.
Basically math.log(math.exp(first) - math.exp(second))
which avoids overflow and uses None as math.log(0.0).
@@ -75,18 +75,18 @@ def log_minus(first, second):
:rtype: float
:raises RuntimeError: If the difference would be non-positive.
"""
-
if first is None:
- raise RuntimeError("log_minus: does not suport None first")
+ raise RuntimeError(u"log_minus: does not support None first")
if second is None:
return first
if second >= first:
- raise RuntimeError("log_minus: first has to be bigger than second")
+ raise RuntimeError(u"log_minus: first has to be bigger than second")
factor = -math.expm1(second - first)
if factor <= 0.0:
- raise RuntimeError("log_minus: non-positive number to log")
+ msg = u"log_minus: non-positive number to log"
else:
return first + math.log(factor)
+ raise RuntimeError(msg)
def safe_exp(log_value):