diff options
Diffstat (limited to 'Wrappers')
| -rwxr-xr-x | Wrappers/Python/ccpi/optimisation/functions/IndicatorBox.py | 119 | 
1 files changed, 88 insertions, 31 deletions
| diff --git a/Wrappers/Python/ccpi/optimisation/functions/IndicatorBox.py b/Wrappers/Python/ccpi/optimisation/functions/IndicatorBox.py index df8dc89..dd2162c 100755 --- a/Wrappers/Python/ccpi/optimisation/functions/IndicatorBox.py +++ b/Wrappers/Python/ccpi/optimisation/functions/IndicatorBox.py @@ -1,21 +1,25 @@ -# -*- 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 +#======================================================================== +# Copyright 2019 Science Technology Facilities Council +# Copyright 2019 University of Manchester +# +# This work is part of the Core Imaging Library developed by Science Technology +# Facilities Council and University of Manchester +# +# 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.txt +# +# 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. +# +#========================================================================= -#   Copyright 2018-2019 Jakob Jorgensen, Daniil Kazantsev 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 - -#   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.  from ccpi.optimisation.functions import Function  import numpy @@ -43,23 +47,76 @@ class IndicatorBox(Function):              val = numpy.inf          return val -    def prox(self,x,tau=None): -        return  (x.maximum(self.lower)).minimum(self.upper) +    def gradient(self,x): +        return ValueError('Not Differentiable')  +     +    def convex_conjugate(self,x): +        # support function sup <x^*, x> +        return 0       def proximal(self, x, tau, out=None): +                  if out is None: -            return self.prox(x, tau) +            return (x.maximum(self.lower)).minimum(self.upper)         +        else:                    +            x.maximum(self.lower, out=out) +            out.minimum(self.upper, out=out)  +             +    def proximal_conjugate(self, x, tau, out=None): + +        if out is None: +             +            return x - tau * self.proximal(x/tau, tau) +                  else: -            if not x.shape == out.shape: -                raise ValueError('Norm1 Incompatible size:', -                                 x.shape, out.shape) -            #(x.abs() - tau*self.gamma).maximum(0) * x.sign() -            x.abs(out = out) -            out.__isub__(tau*self.gamma) -            out.maximum(0, out=out) -            if self.sign_x is None or not x.shape == self.sign_x.shape: -                self.sign_x = x.sign() -            else: -                x.sign(out=self.sign_x) +             +            self.proximal(x/tau, tau, out=out) +            out *= -1*tau +            out += x + +             +             +if __name__ == '__main__':   + +    from ccpi.framework import ImageGeometry + +    N, M = 2,3 +    ig = ImageGeometry(voxel_num_x = N, voxel_num_y = M)             +     +    u = ig.allocate('random_int') +    tau = 10 +     +    f = IndicatorBox(2, 3) +     +    lower = 10 +    upper = 30 +     +    x = u +     +    z1 = (x.maximum(lower)).minimum(upper) +     +    z2 = x - tau * ((x/tau).maximum(lower)).minimum(upper) +     +    z = z1 + z2/tau +     +    print(z.array, x.array) +     +     +#    prox = f.proximal(u, tau) +#    prox_conj = f.proximal_conjugate(u/tau, tau)  +#     +#     +#    z = prox + tau * prox_conj +#    print(z.as_array(), u.array) +     +     +#    x - tau * ((x/tau).maximum(self.lower)).minimum(self.upper) +  +             +             +             + + -            out.__imul__( self.sign_x ) +             +             +     | 
