Commit 4df6cfa6 authored by Philipp Arras's avatar Philipp Arras

Some renamings

parent 75c8e777
......@@ -37,7 +37,8 @@ class CriticalPowerEnergy(Energy):
position : Field,
The current position of this energy. (Logarithm of power spectrum)
m : Field,
The map whose power spectrum has to be inferred
The map whose power spectrum is inferred. Needs to live in harmonic
signal space.
D : EndomorphicOperator,
The curvature of the Gaussian encoding the posterior covariance.
If not specified, the map is assumed to be no reconstruction.
......
......@@ -24,11 +24,11 @@ from ..minimization.energy import Energy
class NoiseEnergy(Energy):
def __init__(self, position, d, m, D, t, ht, Instrument,
def __init__(self, position, d, xi, D, t, ht, Instrument,
nonlinearity, alpha, q, Projection, munit=1., sunit=1.,
dunit=1., samples=3, sample_list=None, inverter=None):
dunit=1., samples=3, xi_sample_list=None, inverter=None):
super(NoiseEnergy, self).__init__(position=position)
self.m = m
self.xi = xi
self.D = D
self.d = d
self.N = DiagonalOperator(diagonal=dunit**2 * exp(self.position))
......@@ -45,21 +45,19 @@ class NoiseEnergy(Energy):
self.q = q
self.Projection = Projection
self.power = self.Projection.adjoint_times(munit * exp(0.5 * self.t))
self.one = Field(self.position.domain, val=1.)
if sample_list is None:
if xi_sample_list is None:
if samples is None or samples == 0:
sample_list = [m]
xi_sample_list = [xi]
else:
sample_list = [D.generate_posterior_sample() + m
xi_sample_list = [D.generate_posterior_sample() + xi
for _ in range(samples)]
self.sample_list = sample_list
self.xi_sample_list = xi_sample_list
self.inverter = inverter
A = Projection.adjoint_times(munit * exp(.5 * self.t)) # unit: munit
map_s = self.ht(A * m)
self._gradient = None
for sample in self.sample_list:
for sample in self.xi_sample_list:
map_s = self.ht(A * sample)
residual = self.d - \
......@@ -74,12 +72,12 @@ class NoiseEnergy(Energy):
self._value += lh
self._gradient += grad
self._value *= 1. / len(self.sample_list)
self._value *= 1. / len(self.xi_sample_list)
self._value += .5 * self.position.sum()
self._value += (self.alpha - 1.).vdot(self.position) + \
self.q.vdot(exp(-self.position))
self._gradient *= 1. / len(self.sample_list)
self._gradient *= 1. / len(self.xi_sample_list)
self._gradient += (self.alpha - 0.5) - self.q * (exp(-self.position))
def at(self, position):
......@@ -87,7 +85,7 @@ class NoiseEnergy(Energy):
position, self.d, self.m, 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, sample_list=self.sample_list,
dunit=self.dunit, xi_sample_list=self.xi_sample_list,
samples=self.samples, inverter=self.inverter)
@property
......
......@@ -52,7 +52,7 @@ class NonlinearPowerEnergy(Energy):
"""
def __init__(self, position, d, N, xi, D, ht, Instrument, nonlinearity,
Projection, sigma=0., samples=3, sample_list=None,
Projection, sigma=0., samples=3, xi_sample_list=None,
inverter=None, munit=1., sunit=1.):
super(NonlinearPowerEnergy, self).__init__(position)
self.xi = xi
......@@ -68,13 +68,13 @@ class NonlinearPowerEnergy(Energy):
self.sigma = sigma
self.munit = munit
self.sunit = sunit
if sample_list is None:
if xi_sample_list is None:
if samples is None or samples == 0:
sample_list = [xi]
xi_sample_list = [xi]
else:
sample_list = [D.generate_posterior_sample() + xi
xi_sample_list = [D.generate_posterior_sample() + xi
for _ in range(samples)]
self.sample_list = sample_list
self.xi_sample_list = xi_sample_list
self.inverter = inverter
A = Projection.adjoint_times(munit * exp(.5 * position)) # unit: munit
......@@ -82,7 +82,7 @@ class NonlinearPowerEnergy(Energy):
Tpos = self.T(position)
self._gradient = None
for xi_sample in self.sample_list:
for xi_sample in self.xi_sample_list:
map_s = self.ht(A * xi_sample)
LinR = LinearizedPowerResponse(
self.Instrument, self.nonlinearity, self.ht, self.Projection,
......@@ -100,17 +100,17 @@ class NonlinearPowerEnergy(Energy):
self._value += lh
self._gradient += grad
self._value *= 1. / len(self.sample_list)
self._value *= 1. / len(self.xi_sample_list)
self._value += 0.5 * self.position.vdot(Tpos)
self._gradient *= -1. / len(self.sample_list)
self._gradient *= -1. / len(self.xi_sample_list)
self._gradient += Tpos
def at(self, position):
return self.__class__(position, self.d, self.N, self.xi, self.D,
self.ht, self.Instrument, self.nonlinearity,
self.Projection, sigma=self.sigma,
samples=len(self.sample_list),
sample_list=self.sample_list,
samples=len(self.xi_sample_list),
xi_sample_list=self.xi_sample_list,
munit=self.munit,
sunit=self.sunit,
inverter=self.inverter)
......@@ -128,5 +128,5 @@ class NonlinearPowerEnergy(Energy):
def curvature(self):
return NonlinearPowerCurvature(
self.position, self.ht, self.Instrument, self.nonlinearity,
self.Projection, self.N, self.T, self.sample_list,
self.Projection, self.N, self.T, self.xi_sample_list,
self.inverter, self.munit, self.sunit)
......@@ -19,8 +19,8 @@
from ..field import exp
def LinearizedSignalResponse(Instrument, nonlinearity, ht, power, s, sunit):
return sunit * (Instrument * nonlinearity.derivative(s) * ht * power)
def LinearizedSignalResponse(Instrument, nonlinearity, ht, power, m, sunit):
return sunit * (Instrument * nonlinearity.derivative(m) * ht * power)
def LinearizedPowerResponse(Instrument, nonlinearity, ht, Projection, tau, xi, munit, sunit):
......
......@@ -29,11 +29,12 @@ class WienerFilterEnergy(Energy):
Parameters
----------
position: Field,
The current position.
The current map in harmonic space.
d: Field,
the data
R: LinearOperator,
The response operator, description of the measurement process.
The response operator, description of the measurement process. It needs
to map from harmonic signal space to data space.
N: EndomorphicOperator,
The noise covariance in data space.
S: EndomorphicOperator,
......
......@@ -80,16 +80,16 @@ class Noise_Energy_Tests(unittest.TestCase):
S=S,
inverter=inverter).curvature
Nsamples = 10
sample_list = [D.generate_posterior_sample() + xi for i in range(Nsamples)]
xi_sample_list = [D.generate_posterior_sample() + xi for i in range(Nsamples)]
energy0 = ift.library.NoiseEnergy(
position=eta0, d=d, m=xi, D=D, t=tau, Instrument=R,
position=eta0, d=d, xi=xi, D=D, t=tau, Instrument=R,
alpha=alpha, q=q, Projection=P, nonlinearity=f,
ht=ht, sample_list=sample_list)
ht=ht, xi_sample_list=xi_sample_list)
energy1 = ift.library.NoiseEnergy(
position=eta1, d=d, m=xi, D=D, t=tau, Instrument=R,
position=eta1, d=d, xi=xi, D=D, t=tau, Instrument=R,
alpha=alpha, q=q, Projection=P, nonlinearity=f,
ht=ht, sample_list=sample_list)
ht=ht, xi_sample_list=xi_sample_list)
a = (energy1.value - energy0.value) / eps
b = energy0.gradient.vdot(direction)
......
......@@ -132,7 +132,7 @@ class Energy_Tests(unittest.TestCase):
ht=ht,
inverter=inverter).curvature
Nsamples = 10
sample_list = [D.generate_posterior_sample() + xi for _ in range(Nsamples)]
xi_sample_list = [D.generate_posterior_sample() + xi for _ in range(Nsamples)]
energy0 = ift.library.NonlinearPowerEnergy(
position=tau0,
......@@ -144,7 +144,7 @@ class Energy_Tests(unittest.TestCase):
nonlinearity=f,
ht=ht,
N=N,
sample_list=sample_list)
xi_sample_list=xi_sample_list)
energy1 = ift.library.NonlinearPowerEnergy(
position=tau1,
d=d,
......@@ -155,7 +155,7 @@ class Energy_Tests(unittest.TestCase):
nonlinearity=f,
ht=ht,
N=N,
sample_list=sample_list)
xi_sample_list=xi_sample_list)
a = (energy1.value - energy0.value) / eps
b = energy0.gradient.vdot(direction)
......@@ -271,7 +271,7 @@ class Curvature_Tests(unittest.TestCase):
ht=ht,
inverter=inverter).curvature
Nsamples = 10
sample_list = [D.generate_posterior_sample() + xi for _ in range(Nsamples)]
xi_sample_list = [D.generate_posterior_sample() + xi for _ in range(Nsamples)]
energy0 = ift.library.NonlinearPowerEnergy(
position=tau0,
......@@ -283,7 +283,7 @@ class Curvature_Tests(unittest.TestCase):
nonlinearity=f,
ht=ht,
N=N,
sample_list=sample_list)
xi_sample_list=xi_sample_list)
gradient0 = energy0.gradient
gradient1 = energy0.at(tau1).gradient
......
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