nonlinear_wiener_filter_energy.py 2.46 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):
26
    def __init__(self, position, d, Instrument, nonlinearity, ht, power, N, S,
Philipp Arras's avatar
Philipp Arras committed
27
                 inverter=None):
28
        super(NonlinearWienerFilterEnergy, self).__init__(position=position)
Martin Reinecke's avatar
Martin Reinecke committed
29
        self.d = d.lock()
30
31
        self.Instrument = Instrument
        self.nonlinearity = nonlinearity
32
        self.ht = ht
33
        self.power = power
Philipp Arras's avatar
Philipp Arras committed
34
        m = self.ht(self.power * self.position)
Philipp Arras's avatar
Philipp Arras committed
35
        self.LinearizedResponse = LinearizedSignalResponse(
Philipp Arras's avatar
Philipp Arras committed
36
            Instrument, nonlinearity, ht, power, m)
37

Philipp Arras's avatar
Philipp Arras committed
38
        residual = d - Instrument(nonlinearity(m))
39
40
41
        self.N = N
        self.S = S
        self.inverter = inverter
Martin Reinecke's avatar
tweaks    
Martin Reinecke committed
42
43
44
45
46
        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)
Martin Reinecke's avatar
Martin Reinecke committed
47
        self._gradient.lock()
48
49
50

    def at(self, position):
        return self.__class__(position, self.d, self.Instrument,
51
                              self.nonlinearity, self.ht, self.power, self.N,
Philipp Arras's avatar
Philipp Arras committed
52
                              self.S, 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)