log_normal_wiener_filter_energy.py 2.93 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
from ..minimization.energy import Energy
from ..utilities import memo
from .log_normal_wiener_filter_curvature import LogNormalWienerFilterCurvature
22
from ..sugar import create_composed_ht_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
    """

46
    def __init__(self, position, d, R, N, S, inverter, ht=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

54
        if ht is None:
55
            self._ht = create_composed_ht_operator(self.S.domain)
56
        else:
57
            self._ht = ht
Martin Reinecke's avatar
cleanup  
Martin Reinecke committed
58

59
        self._expp_sspace = exp(self._ht(self.position))
Martin Reinecke's avatar
cleanup  
Martin Reinecke committed
60
61

        Sp = self.S.inverse_times(self.position)
62
        expp = self._ht.adjoint_times(self._expp_sspace)
Martin Reinecke's avatar
cleanup  
Martin Reinecke committed
63
64
        Rexppd = self.R(expp) - self.d
        NRexppd = self.N.inverse_times(Rexppd)
65
        self._value = 0.5*(self.position.vdot(Sp) + Rexppd.vdot(NRexppd))
66
67
        exppRNRexppd = self._ht.adjoint_times(
            self._expp_sspace * self._ht(self.R.adjoint_times(NRexppd)))
Martin Reinecke's avatar
cleanup  
Martin Reinecke committed
68
        self._gradient = Sp + exppRNRexppd
69

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

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

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

    @property
Martin Reinecke's avatar
Martin Reinecke committed
83
    @memo
84
    def curvature(self):
85
        return LogNormalWienerFilterCurvature(
Philipp Arras's avatar
Fixups  
Philipp Arras committed
86
            R=self.R, N=self.N, S=self.S, ht=self._ht,
Martin Reinecke's avatar
cleanup  
Martin Reinecke committed
87
            expp_sspace=self._expp_sspace, inverter=self._inverter)