summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorepapoutsellis <epapoutsellis@gmail.com>2019-04-16 19:05:10 +0100
committerepapoutsellis <epapoutsellis@gmail.com>2019-04-16 19:05:10 +0100
commit48cffabc0879f9e61d932b654e497382ebfaa995 (patch)
tree70c548bd743798c95e277cdbbb7089b464e8e35a
parente23a45a61a8f185efe564088daea45de714d94ac (diff)
downloadframework-48cffabc0879f9e61d932b654e497382ebfaa995.tar.gz
framework-48cffabc0879f9e61d932b654e497382ebfaa995.tar.bz2
framework-48cffabc0879f9e61d932b654e497382ebfaa995.tar.xz
framework-48cffabc0879f9e61d932b654e497382ebfaa995.zip
fix KL methods
-rw-r--r--Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py b/Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py
index ae25bdb..40dddd7 100644
--- a/Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py
+++ b/Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py
@@ -20,6 +20,7 @@
import numpy
from ccpi.optimisation.functions import Function
from ccpi.optimisation.functions.ScaledFunction import ScaledFunction
+from ccpi.framework import ImageData
class KullbackLeibler(Function):
@@ -39,14 +40,17 @@ class KullbackLeibler(Function):
# TODO check
- self.sum_value = self.b + self.bnoise
+ self.sum_value = x + self.bnoise
if (self.sum_value.as_array()<0).any():
self.sum_value = numpy.inf
if self.sum_value==numpy.inf:
return numpy.inf
else:
- return numpy.sum( x.as_array() - self.b.as_array() * numpy.log(self.sum_value.as_array()))
+ tmp = self.sum_value.as_array()
+ return (x - self.b * ImageData( numpy.log(tmp))).sum()
+
+# return numpy.sum( x.as_array() - self.b.as_array() * numpy.log(self.sum_value.as_array()))
def gradient(self, x, out=None):
@@ -60,7 +64,10 @@ class KullbackLeibler(Function):
def convex_conjugate(self, x):
- return self.b * ( numpy.log(self.b/(1-x)) - 1 ) - self.bnoise * (x - 1)
+ tmp = self.b.as_array()/( 1 - x.as_array() )
+
+ return (self.b * ( ImageData( numpy.log(tmp) ) - 1 ) - self.bnoise * (x - 1)).sum()
+# return self.b * ( ImageData(numpy.log(self.b/(1-x)) - 1 )) - self.bnoise * (x - 1)
def proximal(self, x, tau, out=None):