Commit 6751d5bc authored by Philipp Arras's avatar Philipp Arras

Revert unit stuff

This stuff may be merged separately.
parent 367e0628
Pipeline #24218 passed with stage
in 5 minutes and 3 seconds
......@@ -25,26 +25,23 @@ from ..minimization.energy import Energy
class NoiseEnergy(Energy):
def __init__(self, position, d, xi, D, t, ht, Instrument,
nonlinearity, alpha, q, Projection, munit=1., sunit=1.,
dunit=1., samples=3, xi_sample_list=None, inverter=None):
nonlinearity, alpha, q, Projection, samples=3,
xi_sample_list=None, inverter=None):
super(NoiseEnergy, self).__init__(position=position)
self.xi = xi
self.D = D
self.d = d
self.N = DiagonalOperator(diagonal=dunit**2 * exp(self.position))
self.N = DiagonalOperator(diagonal=exp(self.position))
self.t = t
self.samples = samples
self.ht = ht
self.Instrument = Instrument
self.nonlinearity = nonlinearity
self.munit = munit
self.sunit = sunit
self.dunit = dunit
self.alpha = alpha
self.q = q
self.Projection = Projection
self.power = self.Projection.adjoint_times(munit * exp(0.5 * self.t))
self.power = self.Projection.adjoint_times(exp(0.5 * self.t))
if xi_sample_list is None:
if samples is None or samples == 0:
xi_sample_list = [xi]
......@@ -54,14 +51,14 @@ class NoiseEnergy(Energy):
self.xi_sample_list = xi_sample_list
self.inverter = inverter
A = Projection.adjoint_times(munit * exp(.5 * self.t)) # unit: munit
A = Projection.adjoint_times(exp(.5 * self.t))
self._gradient = None
for sample in self.xi_sample_list:
map_s = self.ht(A * sample)
residual = self.d - \
self.Instrument(sunit * self.nonlinearity(map_s))
self.Instrument(self.nonlinearity(map_s))
lh = .5 * residual.vdot(self.N.inverse_times(residual))
grad = -.5 * self.N.inverse_times(residual.conjugate() * residual)
......@@ -84,8 +81,7 @@ class NoiseEnergy(Energy):
return self.__class__(
position, self.d, self.xi, self.D, self.t, self.ht,
self.Instrument, self.nonlinearity, self.alpha, self.q,
self.Projection, munit=self.munit, sunit=self.sunit,
dunit=self.dunit, xi_sample_list=self.xi_sample_list,
self.Projection, xi_sample_list=self.xi_sample_list,
samples=self.samples, inverter=self.inverter)
@property
......
......@@ -20,22 +20,12 @@ from ..operators.inversion_enabler import InversionEnabler
from .response_operators import LinearizedPowerResponse
def NonlinearPowerCurvature(
tau,
ht,
Instrument,
nonlinearity,
Projection,
N,
T,
xi_sample_list,
inverter,
munit=1.,
sunit=1.):
def NonlinearPowerCurvature(tau, ht, Instrument, nonlinearity, Projection, N,
T, xi_sample_list, inverter):
result = None
for xi_sample in xi_sample_list:
LinearizedResponse = LinearizedPowerResponse(
Instrument, nonlinearity, ht, Projection, tau, xi_sample, munit, sunit)
Instrument, nonlinearity, ht, Projection, tau, xi_sample)
op = LinearizedResponse.adjoint * N.inverse * LinearizedResponse
result = op if result is None else result + op
result = result * (1. / len(xi_sample_list)) + T
......
......@@ -53,7 +53,7 @@ class NonlinearPowerEnergy(Energy):
def __init__(self, position, d, N, xi, D, ht, Instrument, nonlinearity,
Projection, sigma=0., samples=3, xi_sample_list=None,
inverter=None, munit=1., sunit=1.):
inverter=None):
super(NonlinearPowerEnergy, self).__init__(position)
self.xi = xi
self.D = D
......@@ -66,8 +66,6 @@ class NonlinearPowerEnergy(Energy):
self.nonlinearity = nonlinearity
self.Projection = Projection
self.sigma = sigma
self.munit = munit
self.sunit = sunit
if xi_sample_list is None:
if samples is None or samples == 0:
xi_sample_list = [xi]
......@@ -77,7 +75,7 @@ class NonlinearPowerEnergy(Energy):
self.xi_sample_list = xi_sample_list
self.inverter = inverter
A = Projection.adjoint_times(munit * exp(.5 * position)) # unit: munit
A = Projection.adjoint_times(exp(.5 * position))
map_s = self.ht(A * xi)
Tpos = self.T(position)
......@@ -86,10 +84,10 @@ class NonlinearPowerEnergy(Energy):
map_s = self.ht(A * xi_sample)
LinR = LinearizedPowerResponse(
self.Instrument, self.nonlinearity, self.ht, self.Projection,
self.position, xi_sample, munit=self.munit, sunit=self.sunit)
self.position, xi_sample)
residual = self.d - \
self.Instrument(sunit * self.nonlinearity(map_s))
self.Instrument(self.nonlinearity(map_s))
lh = 0.5 * residual.vdot(self.N.inverse_times(residual))
grad = LinR.adjoint_times(self.N.inverse_times(residual))
......@@ -111,8 +109,6 @@ class NonlinearPowerEnergy(Energy):
self.Projection, sigma=self.sigma,
samples=len(self.xi_sample_list),
xi_sample_list=self.xi_sample_list,
munit=self.munit,
sunit=self.sunit,
inverter=self.inverter)
@property
......@@ -129,4 +125,4 @@ class NonlinearPowerEnergy(Energy):
return NonlinearPowerCurvature(
self.position, self.ht, self.Instrument, self.nonlinearity,
self.Projection, self.N, self.T, self.xi_sample_list,
self.inverter, self.munit, self.sunit)
self.inverter)
......@@ -24,19 +24,18 @@ from .response_operators import LinearizedSignalResponse
class NonlinearWienerFilterEnergy(Energy):
def __init__(self, position, d, Instrument, nonlinearity, ht, power, N, S,
inverter=None, sunit=1.):
inverter=None):
super(NonlinearWienerFilterEnergy, self).__init__(position=position)
self.d = d
self.sunit = sunit
self.Instrument = Instrument
self.nonlinearity = nonlinearity
self.ht = ht
self.power = power
m = self.ht(self.power * self.position)
self.LinearizedResponse = LinearizedSignalResponse(
Instrument, nonlinearity, ht, power, m, sunit)
Instrument, nonlinearity, ht, power, m)
residual = d - Instrument(sunit * nonlinearity(m))
residual = d - Instrument(nonlinearity(m))
self.N = N
self.S = S
self.inverter = inverter
......@@ -49,7 +48,7 @@ class NonlinearWienerFilterEnergy(Energy):
def at(self, position):
return self.__class__(position, self.d, self.Instrument,
self.nonlinearity, self.ht, self.power, self.N,
self.S, self.inverter, self.sunit)
self.S, self.inverter)
@property
def value(self):
......
......@@ -19,21 +19,12 @@
from ..field import exp
def LinearizedSignalResponse(Instrument, nonlinearity, ht, power, m, sunit):
return sunit * (Instrument * nonlinearity.derivative(m) * ht * power)
def LinearizedSignalResponse(Instrument, nonlinearity, ht, power, m):
return (Instrument * nonlinearity.derivative(m) * ht * power)
def LinearizedPowerResponse(
Instrument,
nonlinearity,
ht,
Projection,
tau,
xi,
munit,
sunit):
power = exp(0.5 * tau) * munit
def LinearizedPowerResponse(Instrument, nonlinearity, ht, Projection, tau, xi):
power = exp(0.5 * tau)
position = ht(Projection.adjoint_times(power) * xi)
linearization = nonlinearity.derivative(position)
return sunit * (0.5 * Instrument * linearization * ht * xi *
Projection.adjoint * power)
return (0.5 * Instrument * linearization * ht * xi * Projection.adjoint * power)
......@@ -209,9 +209,6 @@ def plot(f, **kwargs):
ax.set_xlabel(_get_kw("xlabel", "", **kwargs))
ax.set_ylabel(_get_kw("ylabel", "", **kwargs))
cmap = _get_kw("colormap", plt.rcParams['image.cmap'], **kwargs)
unit = kwargs.get('xunit')
if not unit:
unit = 1.
if isinstance(dom, RGSpace):
if len(dom.shape) == 1:
npoints = dom.shape[0]
......@@ -231,8 +228,8 @@ def plot(f, **kwargs):
ny = dom.shape[1]
dx = dom.distances[0]
dy = dom.distances[1]
xc = np.arange(nx, dtype=np.float64)*dx/unit
yc = np.arange(ny, dtype=np.float64)*dy/unit
xc = np.arange(nx, dtype=np.float64)*dx
yc = np.arange(ny, dtype=np.float64)*dy
im = ax.imshow(dobj.to_global_data(f.val),
extent=[xc[0], xc[-1], yc[0], yc[-1]],
vmin=kwargs.get("zmin"),
......@@ -249,7 +246,7 @@ def plot(f, **kwargs):
plt.xscale('log')
plt.yscale('log')
plt.title('power')
xcoord = dom.k_lengths / unit
xcoord = dom.k_lengths
for i, fld in enumerate(f):
ycoord = dobj.to_global_data(fld.val)
plt.plot(xcoord, ycoord, label=label[i])
......
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