Commit 54e2765b authored by Martin Reinecke's avatar Martin Reinecke
Browse files

adjustments

parent 95ec8d23
Pipeline #22081 failed with stage
in 3 minutes and 56 seconds
......@@ -285,6 +285,10 @@ def log(a, out=None):
return _math_helper(a, np.log, out)
def tanh(a, out=None):
return _math_helper(a, np.tanh, out)
def sqrt(a, out=None):
return _math_helper(a, np.sqrt, out)
......
......@@ -4,7 +4,7 @@ from __future__ import print_function
import numpy as np
from numpy import ndarray as data_object
from numpy import full, empty, empty_like, sqrt, ones, zeros, vdot, abs, \
exp, log
exp, log, tanh
from .random import Random
ntask = 1
......
......@@ -12,7 +12,7 @@ except ImportError:
__all__ = ["ntask", "rank", "master", "local_shape", "data_object", "full",
"empty", "zeros", "ones", "empty_like", "vdot", "abs", "exp",
"log", "sqrt", "from_object", "from_random",
"log", "tanh", "sqrt", "from_object", "from_random",
"local_data", "ibegin", "np_allreduce_sum", "distaxis",
"from_local_data", "from_global_data", "to_global_data",
"redistribute", "default_distaxis", "mprint"]
......@@ -540,5 +540,9 @@ def log(x, out=None):
return _math_helper(x, dobj.log, out)
def tanh(x, out=None):
return _math_helper(x, dobj.tanh, out)
def conjugate(x, out=None):
return _math_helper(x, dobj.conjugate, out)
......@@ -13,8 +13,7 @@ class NoiseEnergy(Energy):
self.m = m
self.D = D
self.d = d
self.N = DiagonalOperator(
self.position.domain, diagonal=exp(self.position))
self.N = DiagonalOperator(diagonal=exp(self.position))
self.t = t
self.samples = samples
self.FFT = FFT
......
......@@ -6,7 +6,7 @@ from .response_operators import LinearizedPowerResponse
class NonlinearPowerCurvature(EndomorphicOperator):
def __init__(self, position, FFT, Instrument, nonlinearity,
Projection, N, T, sample_list, inverter=None):
Projection, N, T, sample_list):
self.N = N
self.FFT = FFT
self.Instrument = Instrument
......@@ -20,7 +20,7 @@ class NonlinearPowerCurvature(EndomorphicOperator):
# if preconditioner is None:
# preconditioner = self.theta.inverse_times
self._domain = self.position.domain
super(NonlinearPowerCurvature, self).__init__(inverter=inverter)
super(NonlinearPowerCurvature, self).__init__()
@property
def domain(self):
......@@ -34,9 +34,7 @@ class NonlinearPowerCurvature(EndomorphicOperator):
def unitary(self):
return False
# ---Added properties and methods---
def _times(self, x, spaces):
def _times(self, x):
result = Field(self.domain, val=0.)
for i in range(self.samples):
......
......@@ -111,5 +111,5 @@ class NonlinearPowerEnergy(Energy):
@memo
def curvature(self):
curvature = NonlinearPowerCurvature(self.position, self.FFT, self.Instrument, self.nonlinearity,
self.Projection, self.N, self.T, self.sample_list, inverter=self.inverter)
self.Projection, self.N, self.T, self.sample_list)
return InversionEnabler(curvature, inverter=self.inverter)
from ..operators.endomorphic_operator import EndomorphicOperator
class NonlinearSignalCurvature(EndomorphicOperator):
def __init__(self, R, N, S, inverter=None):
self.R = R
self.N = N
self.S = S
# if preconditioner is None:
# preconditioner = self.S.times
self._domain = self.S.domain
super(NonlinearSignalCurvature, self).__init__(inverter=inverter)
@property
def domain(self):
return self._domain
@property
def self_adjoint(self):
return True
@property
def unitary(self):
return False
# ---Added properties and methods---
def _times(self, x, spaces):
return self.R.adjoint_times(self.N.inverse_times(self.R(x))) + self.S.inverse_times(x)
from .nonlinear_signal_curvature import NonlinearSignalCurvature
from .wiener_filter_curvature import WienerFilterCurvature
from .. import Field, exp
from ..utilities import memo
from ..sugar import generate_posterior_sample
......@@ -8,33 +8,17 @@ from .response_operators import LinearizedSignalResponse
class NonlinearWienerFilterEnergy(Energy):
"""The Energy for the Gaussian lognormal case.
It describes the situation of linear measurement of a
lognormal signal with Gaussian noise and Gaussain signal prior.
Parameters
----------
d : Field,
the data.
R : Operator,
The nonlinear response operator, describtion of the measurement process.
N : EndomorphicOperator,
The noise covariance in data space.
S : EndomorphicOperator,
The prior signal covariance in harmonic space.
"""
def __init__(self, position, d, Instrument, nonlinearity, FFT, power, N, S, inverter=None):
def __init__(self, position, d, Instrument, nonlinearity, FFT, power, N, S,
inverter=None):
super(NonlinearWienerFilterEnergy, self).__init__(position=position)
# print "init", position.norm()
self.d = d
self.Instrument = Instrument
self.nonlinearity = nonlinearity
self.FFT = FFT
self.power = power
self.LinearizedResponse = LinearizedSignalResponse(Instrument, nonlinearity,
FFT, power, self.position)
self.LinearizedResponse = \
LinearizedSignalResponse(Instrument, nonlinearity, FFT, power,
self.position)
position_map = FFT.adjoint_times(self.power * self.position)
# position_map = (Field(FFT.domain,val=position_map.val.real+0j))
......@@ -68,7 +52,6 @@ class NonlinearWienerFilterEnergy(Energy):
@property
@memo
def curvature(self):
curvature = NonlinearSignalCurvature(R=self.LinearizedResponse,
N=self.N,
S=self.S, inverter=self.inverter)
curvature = WienerFilterCurvature(R=self.LinearizedResponse,
N=self.N, S=self.S)
return InversionEnabler(curvature, inverter=self.inverter)
from numpy import logical_and, where
from ... import Field, exp, tanh
from .. import Field, exp, tanh
class Linear:
......
......@@ -2,36 +2,9 @@ from .. import exp
from ..operators.linear_operator import LinearOperator
class AdjointFFTResponse(LinearOperator):
def __init__(self, FFT, R, default_spaces=None):
super(AdjointFFTResponse, self).__init__(default_spaces)
self._domain = FFT.target
self._target = R.target
self.R = R
self.FFT = FFT
def _times(self, x, spaces=None):
return self.R(self.FFT.adjoint_times(x))
def _adjoint_times(self, x, spaces=None):
return self.FFT(self.R.adjoint_times(x))
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
@property
def unitary(self):
return False
class LinearizedSignalResponse(LinearOperator):
def __init__(self, Instrument, nonlinearity, FFT, power, m, default_spaces=None):
super(LinearizedSignalResponse, self).__init__(default_spaces)
def __init__(self, Instrument, nonlinearity, FFT, power, m):
super(LinearizedSignalResponse, self).__init__()
self._target = Instrument.target
self._domain = FFT.target
self.Instrument = Instrument
......@@ -40,10 +13,10 @@ class LinearizedSignalResponse(LinearOperator):
position = FFT.adjoint_times(self.power * m)
self.linearization = nonlinearity.derivative(position)
def _times(self, x, spaces):
def _times(self, x):
return self.Instrument(self.linearization * self.FFT.adjoint_times(self.power * x))
def _adjoint_times(self, x, spaces):
def _adjoint_times(self, x):
return self.power * self.FFT(self.linearization * self.Instrument.adjoint_times(x))
@property
......@@ -60,8 +33,8 @@ class LinearizedSignalResponse(LinearOperator):
class LinearizedPowerResponse(LinearOperator):
def __init__(self, Instrument, nonlinearity, FFT, Projection, t, m, default_spaces=None):
super(LinearizedPowerResponse, self).__init__(default_spaces)
def __init__(self, Instrument, nonlinearity, FFT, Projection, t, m):
super(LinearizedPowerResponse, self).__init__()
self._target = Instrument.target
self._domain = t.domain
self.Instrument = Instrument
......@@ -73,12 +46,12 @@ class LinearizedPowerResponse(LinearOperator):
self.Projection.adjoint_times(self.power) * self.m)
self.linearization = nonlinearity.derivative(position)
def _times(self, x, spaces):
def _times(self, x):
return 0.5 * self.Instrument(self.linearization
* self.FFT.adjoint_times(self.m
* self.Projection.adjoint_times(self.power * x)))
def _adjoint_times(self, x, spaces):
def _adjoint_times(self, x):
return 0.5 * self.power * self.Projection(self.m.conjugate()
* self.FFT(self.linearization
* self.Instrument.adjoint_times(x))) # .weight(-1)
......@@ -94,32 +67,3 @@ class LinearizedPowerResponse(LinearOperator):
@property
def unitary(self):
return False
class SignalResponse(LinearOperator):
def __init__(self, t, FFT, R, default_spaces=None):
super(SignalResponse, self).__init__(default_spaces)
self._domain = FFT.target
self._target = R.target
self.power = exp(t).power_synthesize(
mean=1, std=0, real_signal=False)
self.R = R
self.FFT = FFT
def _times(self, x, spaces=None):
return self.R(self.FFT.adjoint_times(self.power * x))
def _adjoint_times(self, x, spaces=None):
return self.power * self.FFT(self.R.adjoint_times(x))
@property
def domain(self):
return self._domain
@property
def target(self):
return self._target
@property
def unitary(self):
return False
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment