nonlinear_wiener_filter_energy.py 2.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2013-2018 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.

Martin Reinecke's avatar
Martin Reinecke committed
19
from .wiener_filter_curvature import WienerFilterCurvature
Philipp Arras's avatar
Philipp Arras committed
20 21
from ..utilities import memo
from ..minimization.energy import Energy
22 23 24 25
from .response_operators import LinearizedSignalResponse


class NonlinearWienerFilterEnergy(Energy):
Martin Reinecke's avatar
Martin Reinecke committed
26 27
    def __init__(self, position, d, Instrument, nonlinearity, FFT, power, N, S,
                 inverter=None):
28 29 30 31 32 33
        super(NonlinearWienerFilterEnergy, self).__init__(position=position)
        self.d = d
        self.Instrument = Instrument
        self.nonlinearity = nonlinearity
        self.FFT = FFT
        self.power = power
Martin Reinecke's avatar
Martin Reinecke committed
34 35 36
        self.LinearizedResponse = \
            LinearizedSignalResponse(Instrument, nonlinearity, FFT, power,
                                     self.position)
37 38

        position_map = FFT.adjoint_times(self.power * self.position)
Martin Reinecke's avatar
tweaks  
Martin Reinecke committed
39
        residual = d - Instrument(nonlinearity(position_map))
40 41 42
        self.N = N
        self.S = S
        self.inverter = inverter
Martin Reinecke's avatar
tweaks  
Martin Reinecke committed
43 44 45 46 47
        t1 = self.S.inverse_times(self.position)
        t2 = self.N.inverse_times(residual)
        tmp = self.position.vdot(t1) + residual.vdot(t2)
        self._value = 0.5 * tmp.real
        self._gradient = t1 - self.LinearizedResponse.adjoint_times(t2)
48 49 50

    def at(self, position):
        return self.__class__(position, self.d, self.Instrument,
Martin Reinecke's avatar
Martin Reinecke committed
51 52
                              self.nonlinearity, self.FFT, self.power, self.N,
                              self.S, inverter=self.inverter)
53 54 55

    @property
    def value(self):
Martin Reinecke's avatar
tweaks  
Martin Reinecke committed
56
        return self._value
57 58 59

    @property
    def gradient(self):
Martin Reinecke's avatar
tweaks  
Martin Reinecke committed
60
        return self._gradient
61 62 63 64

    @property
    @memo
    def curvature(self):
65 66
        return WienerFilterCurvature(R=self.LinearizedResponse, N=self.N,
                                     S=self.S, inverter=self.inverter)