log_normal_wiener_filter_energy.py 3.02 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
20
21
22
from ..minimization.energy import Energy
from ..utilities import memo
from .log_normal_wiener_filter_curvature import LogNormalWienerFilterCurvature
from ..sugar import create_composed_fft_operator
Martin Reinecke's avatar
Martin Reinecke committed
23
from ..field import exp
Martin Reinecke's avatar
Martin Reinecke committed
24

25
26
27
28
29
30
31
32
33
34

class LogNormalWienerFilterEnergy(Energy):
    """The Energy for the log-normal Wiener filter.

    It covers the case of linear measurement with
    Gaussian noise and Gaussain signal prior with known covariance.

    Parameters
    ----------
    position: Field,
Martin Reinecke's avatar
Martin Reinecke committed
35
36
37
38
39
40
41
42
43
       The current position.
    d: Field,
       the data.
    R: Operator,
       The response operator, describtion of the measurement process.
    N: EndomorphicOperator,
       The noise covariance in data space.
    S: EndomorphicOperator,
       The prior signal covariance in harmonic space.
44
45
    """

Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
46
    def __init__(self, position, d, R, N, S, inverter, fft=None):
47
        super(LogNormalWienerFilterEnergy, self).__init__(position=position)
48
49
50
51
        self.d = d
        self.R = R
        self.N = N
        self.S = S
Martin Reinecke's avatar
adjust    
Martin Reinecke committed
52
        self._inverter = inverter
53

Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
54
        if fft is None:
55
56
57
            self._fft = create_composed_fft_operator(self.S.domain,
                                                     all_to='position')
        else:
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
58
59
60
61
62
63
64
65
66
67
68
69
            self._fft = fft

        self._expp_sspace = exp(self._fft(self.position))

        Sp = self.S.inverse_times(self.position)
        expp = self._fft.adjoint_times(self._expp_sspace)
        Rexppd = self.R(expp) - self.d
        NRexppd = self.N.inverse_times(Rexppd)
        self._value = 0.5*(self.position.vdot(Sp) + Rexppd.vdot(NRexppd))
        exppRNRexppd = self._fft.adjoint_times(
            self._expp_sspace * self._fft(self.R.adjoint_times(NRexppd)))
        self._gradient = Sp + exppRNRexppd
70

71
    def at(self, position):
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
72
73
        return self.__class__(position, self.d, self.R, self.N, self.S,
                              self._inverter, self._fft)
74
75
76

    @property
    def value(self):
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
77
        return self._value
78
79
80

    @property
    def gradient(self):
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
81
        return self._gradient
82
83

    @property
Martin Reinecke's avatar
Martin Reinecke committed
84
    @memo
85
    def curvature(self):
86
        return LogNormalWienerFilterCurvature(
Martin Reinecke's avatar
Martin Reinecke committed
87
            R=self.R, N=self.N, S=self.S, fft=self._fft,
Martin Reinecke's avatar
cleanup    
Martin Reinecke committed
88
            expp_sspace=self._expp_sspace, inverter=self._inverter)