From ad4ba705e2c9265c829c00ff96306070bf045988 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Mon, 1 Apr 2019 16:59:48 +0100 Subject: added norm --- Wrappers/Python/ccpi/optimisation/ops.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Wrappers/Python') diff --git a/Wrappers/Python/ccpi/optimisation/ops.py b/Wrappers/Python/ccpi/optimisation/ops.py index 6afb97a..fcd0d9e 100755 --- a/Wrappers/Python/ccpi/optimisation/ops.py +++ b/Wrappers/Python/ccpi/optimisation/ops.py @@ -115,8 +115,8 @@ class TomoIdentity(Operator): def adjoint(self,x, out=None): return self.direct(x, out) - def size(self): - return NotImplemented + def norm(self): + return self.s1 def get_max_sing_val(self): return self.s1 -- cgit v1.2.3 From 2b483605262a756a3bbbcab689f1e6db6e36b8d3 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Mon, 1 Apr 2019 17:00:50 +0100 Subject: fixed tests --- Wrappers/Python/test/test_algorithms.py | 1 + Wrappers/Python/test/test_run_test.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'Wrappers/Python') diff --git a/Wrappers/Python/test/test_algorithms.py b/Wrappers/Python/test/test_algorithms.py index b5959b5..a35ffc1 100755 --- a/Wrappers/Python/test/test_algorithms.py +++ b/Wrappers/Python/test/test_algorithms.py @@ -86,6 +86,7 @@ class TestAlgorithms(unittest.TestCase): identity = TomoIdentity(geometry=ig) norm2sq = Norm2sq(identity, b) + norm2sq.L = 2 * norm2sq.c * identity.norm()**2 opt = {'tol': 1e-4, 'memopt':False} alg = FISTA(x_init=x_init, f=norm2sq, g=None, opt=opt) alg.max_iteration = 2 diff --git a/Wrappers/Python/test/test_run_test.py b/Wrappers/Python/test/test_run_test.py index 3c7d9ab..8cef925 100755 --- a/Wrappers/Python/test/test_run_test.py +++ b/Wrappers/Python/test/test_run_test.py @@ -9,7 +9,7 @@ from ccpi.framework import AcquisitionGeometry from ccpi.optimisation.algs import FISTA from ccpi.optimisation.algs import FBPD from ccpi.optimisation.funcs import Norm2sq -from ccpi.optimisation.funcs import ZeroFun +from ccpi.optimisation.functions import ZeroFun from ccpi.optimisation.funcs import Norm1 from ccpi.optimisation.funcs import TV2D from ccpi.optimisation.funcs import Norm2 -- cgit v1.2.3 From aaa4eae2f43df1a1ed3c15ba2dacdc4dce5a43d6 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Mon, 1 Apr 2019 17:03:52 +0100 Subject: added tau to call to proximal --- Wrappers/Python/ccpi/optimisation/functions/Function.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Wrappers/Python') diff --git a/Wrappers/Python/ccpi/optimisation/functions/Function.py b/Wrappers/Python/ccpi/optimisation/functions/Function.py index 82f24a6..ba33666 100644 --- a/Wrappers/Python/ccpi/optimisation/functions/Function.py +++ b/Wrappers/Python/ccpi/optimisation/functions/Function.py @@ -59,7 +59,7 @@ class Function(object): '''Alias of proximal(x, tau, None)''' warnings.warn('''This method will disappear in following versions of the CIL. Use proximal instead''', DeprecationWarning) - return self.proximal(x, out=None) + return self.proximal(x, tau, out=None) def __rmul__(self, scalar): '''Defines the multiplication by a scalar on the left -- cgit v1.2.3 From 47e743cf3ff3474b516d492b0c5b3d47d4b73848 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Mon, 1 Apr 2019 17:40:08 +0100 Subject: python2.7 fixes --- .../ccpi/optimisation/functions/L2NormSquared.py | 25 +++++++++++++++------- Wrappers/Python/test/test_functions.py | 6 +++--- 2 files changed, 20 insertions(+), 11 deletions(-) (limited to 'Wrappers/Python') diff --git a/Wrappers/Python/ccpi/optimisation/functions/L2NormSquared.py b/Wrappers/Python/ccpi/optimisation/functions/L2NormSquared.py index 5489d92..597d4d8 100644 --- a/Wrappers/Python/ccpi/optimisation/functions/L2NormSquared.py +++ b/Wrappers/Python/ccpi/optimisation/functions/L2NormSquared.py @@ -1,12 +1,21 @@ # -*- coding: utf-8 -*- +# This work is part of the Core Imaging Library developed by +# Visual Analytics and Imaging System Group of the Science Technology +# Facilities Council, STFC -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on Thu Feb 7 13:10:56 2019 +# Copyright 2018-2019 Evangelos Papoutsellis and Edoardo Pasca + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 -@author: evangelos -""" +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import numpy from ccpi.optimisation.functions import Function @@ -75,10 +84,10 @@ class L2NormSquared(Function): if out is None: # FIXME: this is a number - return (1/4) * x.squared_norm() + tmp + return (1./4.) * x.squared_norm() + tmp else: # FIXME: this is a DataContainer - out.fill((1/4) * x.squared_norm() + tmp) + out.fill((1./4.) * x.squared_norm() + tmp) def proximal(self, x, tau, out = None): diff --git a/Wrappers/Python/test/test_functions.py b/Wrappers/Python/test/test_functions.py index 3e5f26f..54dfa57 100644 --- a/Wrappers/Python/test/test_functions.py +++ b/Wrappers/Python/test/test_functions.py @@ -62,7 +62,7 @@ class TestFunction(unittest.TestCase): self.assertEqual(a2, g(d)) # Compare convex conjugate of g - a3 = 0.5 * d.power(2).sum() + (d*noisy_data).sum() + a3 = 0.5 * d.squared_norm() + d.dot(noisy_data) self.assertEqual(a3, g.convex_conjugate(d)) #print( a3, g.convex_conjugate(d)) @@ -91,12 +91,12 @@ class TestFunction(unittest.TestCase): #check convex conjuagate no data c1 = f.convex_conjugate(u) - c2 = 1/4 * u.squared_norm() + c2 = 1/4. * u.squared_norm() numpy.testing.assert_equal(c1, c2) #check convex conjuagate with data d1 = f1.convex_conjugate(u) - d2 = (1/4) * u.squared_norm() + (u*b).sum() + d2 = (1./4.) * u.squared_norm() + (u*b).sum() numpy.testing.assert_equal(d1, d2) # check proximal no data -- cgit v1.2.3