wiener_filter_energy.py 2.38 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-2017 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 20
from ..minimization.energy import Energy
from .wiener_filter_curvature import WienerFilterCurvature
21

22

23 24 25
class WienerFilterEnergy(Energy):
    """The Energy for the Wiener filter.

26
    It covers the case of linear measurement with
Martin Reinecke's avatar
Martin Reinecke committed
27
    Gaussian noise and Gaussian signal prior with known covariance.
28 29 30

    Parameters
    ----------
Jakob Knollmueller's avatar
Jakob Knollmueller committed
31 32
    position: Field,
        The current position.
Martin Reinecke's avatar
Martin Reinecke committed
33 34 35 36 37 38 39 40
    d: Field,
       the data
    R: LinearOperator,
       The response operator, description of the measurement process.
    N: EndomorphicOperator,
       The noise covariance in data space.
    S: EndomorphicOperator,
       The prior signal covariance in harmonic space.
41 42
    """

Martin Reinecke's avatar
Martin Reinecke committed
43
    def __init__(self, position, d, R, N, S, inverter, _j=None):
44
        super(WienerFilterEnergy, self).__init__(position=position)
45 46 47
        self.R = R
        self.N = N
        self.S = S
Martin Reinecke's avatar
Martin Reinecke committed
48
        self._curvature = WienerFilterCurvature(R, N, S, inverter)
Martin Reinecke's avatar
tweaks  
Martin Reinecke committed
49
        self._inverter = inverter
Martin Reinecke's avatar
tweaks  
Martin Reinecke committed
50 51 52 53 54 55
        if _j is None:
            _j = self.R.adjoint_times(self.N.inverse_times(d))
        self._j = _j
        Dx = self._curvature(self.position)
        self._value = 0.5*self.position.vdot(Dx) - self._j.vdot(self.position)
        self._gradient = Dx - self._j
56

57
    def at(self, position):
Martin Reinecke's avatar
tweaks  
Martin Reinecke committed
58 59
        return self.__class__(position=position, d=None, R=self.R, N=self.N,
                              S=self.S, inverter=self._inverter, _j=self._j)
60 61 62

    @property
    def value(self):
Martin Reinecke's avatar
tweaks  
Martin Reinecke committed
63
        return self._value
64 65 66

    @property
    def gradient(self):
Martin Reinecke's avatar
tweaks  
Martin Reinecke committed
67
        return self._gradient
68 69 70

    @property
    def curvature(self):
Martin Reinecke's avatar
tweaks  
Martin Reinecke committed
71
        return self._curvature