response_operators.py 2.5 KB
Newer Older
1
from ..field import exp
Philipp Arras's avatar
Philipp Arras committed
2
from ..operators.linear_operator import LinearOperator
3 4 5


class LinearizedSignalResponse(LinearOperator):
Martin Reinecke's avatar
Martin Reinecke committed
6 7
    def __init__(self, Instrument, nonlinearity, FFT, power, m):
        super(LinearizedSignalResponse, self).__init__()
8 9 10
        self.Instrument = Instrument
        self.FFT = FFT
        self.power = power
11
        position = FFT.adjoint_times(self.power*m)
12 13
        self.linearization = nonlinearity.derivative(position)

Martin Reinecke's avatar
Martin Reinecke committed
14
    def _times(self, x):
15 16 17
        tmp = self.FFT.adjoint_times(self.power*x)
        tmp *= self.linearization
        return self.Instrument(tmp)
18

Martin Reinecke's avatar
Martin Reinecke committed
19
    def _adjoint_times(self, x):
20 21 22 23 24
        tmp = self.Instrument.adjoint_times(x)
        tmp *= self.linearization
        tmp = self.FFT(tmp)
        tmp *= self.power
        return tmp
25 26 27

    @property
    def domain(self):
28
        return self.FFT.target
29 30 31

    @property
    def target(self):
32
        return self.Instrument.target
33

Martin Reinecke's avatar
Martin Reinecke committed
34 35 36 37 38 39 40 41
    @property
    def capability(self):
        return self.TIMES | self.ADJOINT_TIMES

    def apply(self, x, mode):
        self._check_input(x, mode)
        return self._times(x) if mode & self.TIMES else self._adjoint_times(x)

42 43

class LinearizedPowerResponse(LinearOperator):
Martin Reinecke's avatar
Martin Reinecke committed
44 45
    def __init__(self, Instrument, nonlinearity, FFT, Projection, t, m):
        super(LinearizedPowerResponse, self).__init__()
46 47 48
        self.Instrument = Instrument
        self.FFT = FFT
        self.Projection = Projection
49
        self.power = exp(0.5*t)
50 51 52 53 54
        self.m = m
        position = FFT.adjoint_times(
            self.Projection.adjoint_times(self.power) * self.m)
        self.linearization = nonlinearity.derivative(position)

Martin Reinecke's avatar
Martin Reinecke committed
55
    def _times(self, x):
56 57 58 59 60 61 62
        tmp = self.Projection.adjoint_times(self.power*x)
        tmp *= self.m
        tmp = self.FFT.adjoint_times(tmp)
        tmp *= self.linearization
        tmp = self.Instrument(tmp)
        tmp *= 0.5
        return tmp
63

Martin Reinecke's avatar
Martin Reinecke committed
64
    def _adjoint_times(self, x):
65 66 67 68 69 70 71 72
        tmp = self.Instrument.adjoint_times(x)
        tmp *= self.linearization
        tmp = self.FFT(tmp)
        tmp *= self.m.conjugate()
        tmp = self.Projection(tmp)
        tmp *= self.power
        tmp *= 0.5
        return tmp
73 74 75

    @property
    def domain(self):
76
        return self.power.domain
77 78 79

    @property
    def target(self):
80
        return self.Instrument.target
Martin Reinecke's avatar
Martin Reinecke committed
81 82 83 84 85 86 87 88

    @property
    def capability(self):
        return self.TIMES | self.ADJOINT_TIMES

    def apply(self, x, mode):
        self._check_input(x, mode)
        return self._times(x) if mode & self.TIMES else self._adjoint_times(x)