Commit ab97b34a authored by Philipp Arras's avatar Philipp Arras
Browse files

All energy test run through now :)

parent 43b247bb
Pipeline #24156 failed with stage
in 3 minutes and 59 seconds
...@@ -43,7 +43,7 @@ class LogNormalWienerFilterEnergy(Energy): ...@@ -43,7 +43,7 @@ class LogNormalWienerFilterEnergy(Energy):
The prior signal covariance in harmonic space. The prior signal covariance in harmonic space.
""" """
def __init__(self, position, d, R, N, S, inverter, fft=None): def __init__(self, position, d, R, N, S, inverter, ht=None):
super(LogNormalWienerFilterEnergy, self).__init__(position=position) super(LogNormalWienerFilterEnergy, self).__init__(position=position)
self.d = d self.d = d
self.R = R self.R = R
...@@ -51,21 +51,21 @@ class LogNormalWienerFilterEnergy(Energy): ...@@ -51,21 +51,21 @@ class LogNormalWienerFilterEnergy(Energy):
self.S = S self.S = S
self._inverter = inverter self._inverter = inverter
if fft is None: if ht is None:
self._fft = create_composed_fft_operator(self.S.domain, self._ht = create_composed_fft_operator(self.S.domain,
all_to='position') all_to='position')
else: else:
self._fft = fft self._ht = ht
self._expp_sspace = exp(self._fft(self.position)) self._expp_sspace = exp(self._ht(self.position))
Sp = self.S.inverse_times(self.position) Sp = self.S.inverse_times(self.position)
expp = self._fft.adjoint_times(self._expp_sspace) expp = self._ht.adjoint_times(self._expp_sspace)
Rexppd = self.R(expp) - self.d Rexppd = self.R(expp) - self.d
NRexppd = self.N.inverse_times(Rexppd) NRexppd = self.N.inverse_times(Rexppd)
self._value = 0.5*(self.position.vdot(Sp) + Rexppd.vdot(NRexppd)) self._value = 0.5*(self.position.vdot(Sp) + Rexppd.vdot(NRexppd))
exppRNRexppd = self._fft.adjoint_times( exppRNRexppd = self._ht.adjoint_times(
self._expp_sspace * self._fft(self.R.adjoint_times(NRexppd))) self._expp_sspace * self._ht(self.R.adjoint_times(NRexppd)))
self._gradient = Sp + exppRNRexppd self._gradient = Sp + exppRNRexppd
def at(self, position): def at(self, position):
......
...@@ -20,9 +20,11 @@ from .. import Field, exp ...@@ -20,9 +20,11 @@ from .. import Field, exp
from ..operators.diagonal_operator import DiagonalOperator from ..operators.diagonal_operator import DiagonalOperator
from ..minimization.energy import Energy from ..minimization.energy import Energy
# TODO Take only residual_sample_list as argument
class NoiseEnergy(Energy): class NoiseEnergy(Energy):
def __init__(self, position, d, m, D, t, FFT, Instrument, nonlinearity, def __init__(self, position, d, m, D, t, ht, Instrument, nonlinearity,
alpha, q, Projection, samples=3, sample_list=None, alpha, q, Projection, samples=3, sample_list=None,
inverter=None): inverter=None):
super(NoiseEnergy, self).__init__(position=position) super(NoiseEnergy, self).__init__(position=position)
...@@ -32,7 +34,7 @@ class NoiseEnergy(Energy): ...@@ -32,7 +34,7 @@ class NoiseEnergy(Energy):
self.N = DiagonalOperator(diagonal=exp(self.position)) self.N = DiagonalOperator(diagonal=exp(self.position))
self.t = t self.t = t
self.samples = samples self.samples = samples
self.FFT = FFT self.ht = ht
self.Instrument = Instrument self.Instrument = Instrument
self.nonlinearity = nonlinearity self.nonlinearity = nonlinearity
...@@ -53,7 +55,7 @@ class NoiseEnergy(Energy): ...@@ -53,7 +55,7 @@ class NoiseEnergy(Energy):
def at(self, position): def at(self, position):
return self.__class__( return self.__class__(
position, self.d, self.m, self.D, self.t, self.FFT, position, self.d, self.m, self.D, self.t, self.ht,
self.Instrument, self.nonlinearity, self.alpha, self.q, self.Instrument, self.nonlinearity, self.alpha, self.q,
self.Projection, sample_list=self.sample_list, self.Projection, sample_list=self.sample_list,
samples=self.samples, inverter=self.inverter) samples=self.samples, inverter=self.inverter)
...@@ -63,7 +65,7 @@ class NoiseEnergy(Energy): ...@@ -63,7 +65,7 @@ class NoiseEnergy(Energy):
for sample in self.sample_list: for sample in self.sample_list:
residual = self.d - \ residual = self.d - \
self.Instrument(self.nonlinearity( self.Instrument(self.nonlinearity(
self.FFT.adjoint_times(self.power*sample))) self.ht(self.power*sample)))
lh = 0.5 * residual.vdot(self.N.inverse_times(residual)) lh = 0.5 * residual.vdot(self.N.inverse_times(residual))
grad = -0.5 * self.N.inverse_times(residual.conjugate() * residual) grad = -0.5 * self.N.inverse_times(residual.conjugate() * residual)
if likelihood_gradient is None: if likelihood_gradient is None:
...@@ -74,7 +76,7 @@ class NoiseEnergy(Energy): ...@@ -74,7 +76,7 @@ class NoiseEnergy(Energy):
likelihood_gradient += grad likelihood_gradient += grad
likelihood = ((likelihood / float(len(self.sample_list))) + likelihood = ((likelihood / float(len(self.sample_list))) +
0.5 * self.position.integrate() + 0.5 * self.position.sum() +
(self.alpha - 1.).vdot(self.position) + (self.alpha - 1.).vdot(self.position) +
self.q.vdot(exp(-self.position))) self.q.vdot(exp(-self.position)))
likelihood_gradient = ( likelihood_gradient = (
......
...@@ -20,12 +20,12 @@ from ..operators.inversion_enabler import InversionEnabler ...@@ -20,12 +20,12 @@ from ..operators.inversion_enabler import InversionEnabler
from .response_operators import LinearizedPowerResponse from .response_operators import LinearizedPowerResponse
def NonlinearPowerCurvature(position, FFT, Instrument, nonlinearity, def NonlinearPowerCurvature(position, ht, Instrument, nonlinearity,
Projection, N, T, sample_list, inverter): Projection, N, T, sample_list, inverter):
result = None result = None
for sample in sample_list: for sample in sample_list:
LinearizedResponse = LinearizedPowerResponse( LinearizedResponse = LinearizedPowerResponse(
Instrument, nonlinearity, FFT, Projection, position, sample) Instrument, nonlinearity, ht, Projection, position, sample)
op = LinearizedResponse.adjoint*N.inverse*LinearizedResponse op = LinearizedResponse.adjoint*N.inverse*LinearizedResponse
result = op if result is None else result + op result = op if result is None else result + op
result = result*(1./len(sample_list)) + T result = result*(1./len(sample_list)) + T
......
...@@ -51,7 +51,7 @@ class NonlinearPowerEnergy(Energy): ...@@ -51,7 +51,7 @@ class NonlinearPowerEnergy(Energy):
default : 3 default : 3
""" """
def __init__(self, position, d, N, m, D, FFT, Instrument, nonlinearity, def __init__(self, position, d, N, m, D, ht, Instrument, nonlinearity,
Projection, sigma=0., samples=3, sample_list=None, Projection, sigma=0., samples=3, sample_list=None,
inverter=None): inverter=None):
super(NonlinearPowerEnergy, self).__init__(position) super(NonlinearPowerEnergy, self).__init__(position)
...@@ -61,7 +61,7 @@ class NonlinearPowerEnergy(Energy): ...@@ -61,7 +61,7 @@ class NonlinearPowerEnergy(Energy):
self.N = N self.N = N
self.T = SmoothnessOperator(domain=self.position.domain[0], self.T = SmoothnessOperator(domain=self.position.domain[0],
strength=sigma, logarithmic=True) strength=sigma, logarithmic=True)
self.FFT = FFT self.ht = ht
self.Instrument = Instrument self.Instrument = Instrument
self.nonlinearity = nonlinearity self.nonlinearity = nonlinearity
self.Projection = Projection self.Projection = Projection
...@@ -80,7 +80,7 @@ class NonlinearPowerEnergy(Energy): ...@@ -80,7 +80,7 @@ class NonlinearPowerEnergy(Energy):
def at(self, position): def at(self, position):
return self.__class__(position, self.d, self.N, self.m, self.D, return self.__class__(position, self.d, self.N, self.m, self.D,
self.FFT, self.Instrument, self.nonlinearity, self.ht, self.Instrument, self.nonlinearity,
self.Projection, sigma=self._sigma, self.Projection, sigma=self._sigma,
samples=len(self.sample_list), samples=len(self.sample_list),
sample_list=self.sample_list, sample_list=self.sample_list,
...@@ -91,10 +91,10 @@ class NonlinearPowerEnergy(Energy): ...@@ -91,10 +91,10 @@ class NonlinearPowerEnergy(Energy):
for sample in self.sample_list: for sample in self.sample_list:
residual = self.d - \ residual = self.d - \
self.Instrument(self.nonlinearity( self.Instrument(self.nonlinearity(
self.FFT.adjoint_times(self.power*sample))) self.ht(self.power*sample)))
lh = 0.5 * residual.vdot(self.N.inverse_times(residual)) lh = 0.5 * residual.vdot(self.N.inverse_times(residual))
LinR = LinearizedPowerResponse( LinR = LinearizedPowerResponse(
self.Instrument, self.nonlinearity, self.FFT, self.Projection, self.Instrument, self.nonlinearity, self.ht, self.Projection,
self.position, sample) self.position, sample)
grad = LinR.adjoint_times(self.N.inverse_times(residual)) grad = LinR.adjoint_times(self.N.inverse_times(residual))
if likelihood_gradient is None: if likelihood_gradient is None:
...@@ -122,6 +122,6 @@ class NonlinearPowerEnergy(Energy): ...@@ -122,6 +122,6 @@ class NonlinearPowerEnergy(Energy):
@memo @memo
def curvature(self): def curvature(self):
return NonlinearPowerCurvature( return NonlinearPowerCurvature(
self.position, self.FFT, self.Instrument, self.nonlinearity, self.position, self.ht, self.Instrument, self.nonlinearity,
self.Projection, self.N, self.T, self.sample_list, self.Projection, self.N, self.T, self.sample_list,
inverter=self.inverter) inverter=self.inverter)
...@@ -23,19 +23,19 @@ from .response_operators import LinearizedSignalResponse ...@@ -23,19 +23,19 @@ from .response_operators import LinearizedSignalResponse
class NonlinearWienerFilterEnergy(Energy): class NonlinearWienerFilterEnergy(Energy):
def __init__(self, position, d, Instrument, nonlinearity, FFT, power, N, S, def __init__(self, position, d, Instrument, nonlinearity, ht, power, N, S,
inverter=None): inverter=None):
super(NonlinearWienerFilterEnergy, self).__init__(position=position) super(NonlinearWienerFilterEnergy, self).__init__(position=position)
self.d = d self.d = d
self.Instrument = Instrument self.Instrument = Instrument
self.nonlinearity = nonlinearity self.nonlinearity = nonlinearity
self.FFT = FFT self.ht = ht
self.power = power self.power = power
self.LinearizedResponse = \ self.LinearizedResponse = \
LinearizedSignalResponse(Instrument, nonlinearity, FFT, power, LinearizedSignalResponse(Instrument, nonlinearity, ht, power,
self.position) self.position)
position_map = FFT.adjoint_times(self.power * self.position) position_map = ht(self.power * self.position)
residual = d - Instrument(nonlinearity(position_map)) residual = d - Instrument(nonlinearity(position_map))
self.N = N self.N = N
self.S = S self.S = S
...@@ -48,7 +48,7 @@ class NonlinearWienerFilterEnergy(Energy): ...@@ -48,7 +48,7 @@ class NonlinearWienerFilterEnergy(Energy):
def at(self, position): def at(self, position):
return self.__class__(position, self.d, self.Instrument, return self.__class__(position, self.d, self.Instrument,
self.nonlinearity, self.FFT, self.power, self.N, self.nonlinearity, self.ht, self.power, self.N,
self.S, inverter=self.inverter) self.S, inverter=self.inverter)
@property @property
......
...@@ -19,14 +19,15 @@ ...@@ -19,14 +19,15 @@
from ..field import exp from ..field import exp
def LinearizedSignalResponse(Instrument, nonlinearity, FFT, power, m): def LinearizedSignalResponse(Instrument, nonlinearity, ht, power, m):
position = FFT.adjoint_times(power*m) position = ht(power*m)
return (Instrument * nonlinearity.derivative(position) * return (Instrument * nonlinearity.derivative(position) *
FFT.adjoint * power) ht * power)
def LinearizedPowerResponse(Instrument, nonlinearity, FFT, Projection, t, m):
def LinearizedPowerResponse(Instrument, nonlinearity, ht, Projection, t, m):
power = exp(0.5*t) power = exp(0.5*t)
position = FFT.adjoint_times(Projection.adjoint_times(power) * m) position = ht(Projection.adjoint_times(power) * m)
linearization = nonlinearity.derivative(position) linearization = nonlinearity.derivative(position)
return (0.5 * Instrument * linearization * FFT.adjoint * m * return (0.5 * Instrument * linearization * ht * m *
Projection.adjoint * power) Projection.adjoint * power)
...@@ -25,13 +25,15 @@ from numpy.testing import assert_allclose ...@@ -25,13 +25,15 @@ from numpy.testing import assert_allclose
# TODO Add also other space types # TODO Add also other space types
# TODO Set tolerances to reasonable values # TODO Set tolerances and eps to reasonable values
class Map_Energy_Tests(unittest.TestCase): class Map_Energy_Tests(unittest.TestCase):
@expand(product([ift.RGSpace(64, distances=.789), @expand(product([ift.RGSpace(64, distances=.789),
ift.RGSpace([32, 32], distances=.789)])) ift.RGSpace([32, 32], distances=.789)],
def testLinearMap(self, space): [4, 78, 23]))
def testLinearMap(self, space, seed):
np.random.seed(seed)
dim = len(space.shape) dim = len(space.shape)
hspace = space.get_default_codomain() hspace = space.get_default_codomain()
ht = ift.HarmonicTransformOperator(hspace, target=space) ht = ift.HarmonicTransformOperator(hspace, target=space)
...@@ -54,7 +56,7 @@ class Map_Energy_Tests(unittest.TestCase): ...@@ -54,7 +56,7 @@ class Map_Energy_Tests(unittest.TestCase):
direction = ift.Field.from_random('normal', hspace) direction = ift.Field.from_random('normal', hspace)
direction /= np.sqrt(direction.var()) direction /= np.sqrt(direction.var())
eps = 1e-10 eps = 1e-7
s1 = s0 + eps * direction s1 = s0 + eps * direction
IC = ift.GradientNormController( IC = ift.GradientNormController(
...@@ -72,12 +74,14 @@ class Map_Energy_Tests(unittest.TestCase): ...@@ -72,12 +74,14 @@ class Map_Energy_Tests(unittest.TestCase):
a = (energy1.value - energy0.value) / eps a = (energy1.value - energy0.value) / eps
b = energy0.gradient.vdot(direction) b = energy0.gradient.vdot(direction)
tol = 1e-3 tol = 1e-5
assert_allclose(a, b, rtol=tol, atol=tol) assert_allclose(a, b, rtol=tol, atol=tol)
@expand(product([ift.RGSpace(64, distances=.789), @expand(product([ift.RGSpace(64, distances=.789),
ift.RGSpace([32, 32], distances=.789)])) ift.RGSpace([32, 32], distances=.789)],
def testLognormalMap(self, space): [4, 78, 23]))
def testLognormalMap(self, space, seed):
np.random.seed(seed)
dim = len(space.shape) dim = len(space.shape)
hspace = space.get_default_codomain() hspace = space.get_default_codomain()
ht = ift.HarmonicTransformOperator(hspace, target=space) ht = ift.HarmonicTransformOperator(hspace, target=space)
...@@ -101,7 +105,7 @@ class Map_Energy_Tests(unittest.TestCase): ...@@ -101,7 +105,7 @@ class Map_Energy_Tests(unittest.TestCase):
direction = ift.Field.from_random('normal', hspace) direction = ift.Field.from_random('normal', hspace)
direction /= np.sqrt(direction.var()) direction /= np.sqrt(direction.var())
eps = 1e-10 eps = 1e-6
sh1 = sh0 + eps * direction sh1 = sh0 + eps * direction
IC = ift.GradientNormController( IC = ift.GradientNormController(
...@@ -119,17 +123,19 @@ class Map_Energy_Tests(unittest.TestCase): ...@@ -119,17 +123,19 @@ class Map_Energy_Tests(unittest.TestCase):
a = (energy1.value - energy0.value) / eps a = (energy1.value - energy0.value) / eps
b = energy0.gradient.vdot(direction) b = energy0.gradient.vdot(direction)
tol = 1e-2 tol = 1e-3
assert_allclose(a, b, rtol=tol, atol=tol) assert_allclose(a, b, rtol=tol, atol=tol)
@expand(product([ift.RGSpace(64, distances=.789), @expand(product([ift.RGSpace(64, distances=.789),
ift.RGSpace([32, 32], distances=.789)], ift.RGSpace([32, 32], distances=.789)],
[ift.library.Exponential, ift.library.Linear])) [ift.library.Exponential, ift.library.Linear],
def testNonlinearMap(self, space, nonlinearity): [4, 78, 23]))
def testNonlinearMap(self, space, nonlinearity, seed):
np.random.seed(seed)
f = nonlinearity() f = nonlinearity()
dim = len(space.shape) dim = len(space.shape)
fft = ift.FFTOperator(space) hspace = space.get_default_codomain()
hspace = fft.target[0] ht = ift.HarmonicTransformOperator(hspace, target=space)
binbounds = ift.PowerSpace.useful_binbounds(hspace, logarithmic=False) binbounds = ift.PowerSpace.useful_binbounds(hspace, logarithmic=False)
pspace = ift.PowerSpace(hspace, binbounds=binbounds) pspace = ift.PowerSpace(hspace, binbounds=binbounds)
P = ift.PowerProjectionOperator(domain=hspace, power_space=pspace) P = ift.PowerProjectionOperator(domain=hspace, power_space=pspace)
...@@ -139,7 +145,7 @@ class Map_Energy_Tests(unittest.TestCase): ...@@ -139,7 +145,7 @@ class Map_Energy_Tests(unittest.TestCase):
pspec = ift.PS_field(pspace, pspec) pspec = ift.PS_field(pspace, pspec)
A = P.adjoint_times(ift.sqrt(pspec)) A = P.adjoint_times(ift.sqrt(pspec))
n = ift.Field.from_random(domain=space, random_type='normal') n = ift.Field.from_random(domain=space, random_type='normal')
s = fft.inverse_times(xi0 * A) s = ht(xi0 * A)
diag = ift.Field.ones(space) * 10 diag = ift.Field.ones(space) * 10
R = ift.DiagonalOperator(diag) R = ift.DiagonalOperator(diag)
diag = ift.Field.ones(space) diag = ift.Field.ones(space)
...@@ -148,16 +154,16 @@ class Map_Energy_Tests(unittest.TestCase): ...@@ -148,16 +154,16 @@ class Map_Energy_Tests(unittest.TestCase):
direction = ift.Field.from_random('normal', hspace) direction = ift.Field.from_random('normal', hspace)
direction /= np.sqrt(direction.var()) direction /= np.sqrt(direction.var())
eps = 1e-10 eps = 1e-7
xi1 = xi0 + eps * direction xi1 = xi0 + eps * direction
S = ift.create_power_operator(hspace, power_spectrum=lambda k: 1.) S = ift.create_power_operator(hspace, power_spectrum=lambda k: 1.)
energy0 = ift.library.NonlinearWienerFilterEnergy( energy0 = ift.library.NonlinearWienerFilterEnergy(
position=xi0, d=d, Instrument=R, nonlinearity=f, FFT=fft, power=A, N=N, S=S) position=xi0, d=d, Instrument=R, nonlinearity=f, ht=ht, power=A, N=N, S=S)
energy1 = ift.library.NonlinearWienerFilterEnergy( energy1 = ift.library.NonlinearWienerFilterEnergy(
position=xi1, d=d, Instrument=R, nonlinearity=f, FFT=fft, power=A, N=N, S=S) position=xi1, d=d, Instrument=R, nonlinearity=f, ht=ht, power=A, N=N, S=S)
a = (energy1.value - energy0.value) / eps a = (energy1.value - energy0.value) / eps
b = energy0.gradient.vdot(direction) b = energy0.gradient.vdot(direction)
tol = 1e-2 tol = 1e-4
assert_allclose(a, b, rtol=tol, atol=tol) assert_allclose(a, b, rtol=tol, atol=tol)
...@@ -30,12 +30,14 @@ from numpy.testing import assert_allclose ...@@ -30,12 +30,14 @@ from numpy.testing import assert_allclose
class Noise_Energy_Tests(unittest.TestCase): class Noise_Energy_Tests(unittest.TestCase):
@expand(product([ift.RGSpace(64, distances=.789), @expand(product([ift.RGSpace(64, distances=.789),
ift.RGSpace([32, 32], distances=.789)], ift.RGSpace([32, 32], distances=.789)],
[ift.library.Exponential, ift.library.Linear])) [ift.library.Exponential, ift.library.Linear],
def testNoise(self, space, nonlinearity): [23, 131, 32]))
def testNoise(self, space, nonlinearity, seed):
np.random.seed(seed)
f = nonlinearity() f = nonlinearity()
dim = len(space.shape) dim = len(space.shape)
fft = ift.FFTOperator(space) hspace = space.get_default_codomain()
hspace = fft.target[0] ht = ift.HarmonicTransformOperator(hspace, target=space)
binbounds = ift.PowerSpace.useful_binbounds(hspace, logarithmic=False) binbounds = ift.PowerSpace.useful_binbounds(hspace, logarithmic=False)
pspace = ift.PowerSpace(hspace, binbounds=binbounds) pspace = ift.PowerSpace(hspace, binbounds=binbounds)
P = ift.PowerProjectionOperator(domain=hspace, power_space=pspace) P = ift.PowerProjectionOperator(domain=hspace, power_space=pspace)
...@@ -44,13 +46,15 @@ class Noise_Energy_Tests(unittest.TestCase): ...@@ -44,13 +46,15 @@ class Noise_Energy_Tests(unittest.TestCase):
def pspec(k): return 1 / (1 + k**2)**dim def pspec(k): return 1 / (1 + k**2)**dim
tau = ift.PS_field(pspace, pspec) tau = ift.PS_field(pspace, pspec)
A = P.adjoint_times(ift.sqrt(tau)) A = P.adjoint_times(ift.sqrt(tau))
n = ift.Field.from_random(domain=space, random_type='normal') var = 1.
s = fft.inverse_times(xi * A) n = ift.Field.from_random(domain=space, random_type='normal', std=np.sqrt(var))
var = ift.Field(n.domain, val=var)
N = ift.DiagonalOperator(var)
eta0 = ift.log(var)
s = ht(xi * A)
diag = ift.Field.ones(space) * 10 diag = ift.Field.ones(space) * 10
R = ift.DiagonalOperator(diag) R = ift.DiagonalOperator(diag)
diag = ift.Field.ones(space) diag = ift.Field.ones(space)
eta0 = ift.log(diag)
N = ift.DiagonalOperator(diag)
d = R(f(s)) + n d = R(f(s)) + n
alpha = ift.Field(d.domain, val=2.) alpha = ift.Field(d.domain, val=2.)
...@@ -58,7 +62,7 @@ class Noise_Energy_Tests(unittest.TestCase): ...@@ -58,7 +62,7 @@ class Noise_Energy_Tests(unittest.TestCase):
direction = ift.Field.from_random('normal', d.domain) direction = ift.Field.from_random('normal', d.domain)
direction /= np.sqrt(direction.var()) direction /= np.sqrt(direction.var())
eps = 1e-10 eps = 1e-8
eta1 = eta0 + eps * direction eta1 = eta0 + eps * direction
IC = ift.GradientNormController( IC = ift.GradientNormController(
...@@ -74,22 +78,24 @@ class Noise_Energy_Tests(unittest.TestCase): ...@@ -74,22 +78,24 @@ class Noise_Energy_Tests(unittest.TestCase):
d=d, d=d,
Instrument=R, Instrument=R,
nonlinearity=f, nonlinearity=f,
FFT=fft, ht=ht,
power=A, power=A,
N=N, N=N,
S=S, S=S,
inverter=inverter).curvature inverter=inverter).curvature
Nsamples = 10
sample_list = [D.generate_posterior_sample() + xi for i in range(Nsamples)]
energy0 = ift.library.NoiseEnergy( energy0 = ift.library.NoiseEnergy(
position=eta0, d=d, m=xi, D=D, t=tau, Instrument=R, position=eta0, d=d, m=xi, D=D, t=tau, Instrument=R,
alpha=alpha, q=q, Projection=P, nonlinearity=f, alpha=alpha, q=q, Projection=P, nonlinearity=f,
FFT=fft, samples=3) ht=ht, sample_list=sample_list)
energy1 = ift.library.NoiseEnergy( energy1 = ift.library.NoiseEnergy(
position=eta1, d=d, m=xi, D=D, t=tau, Instrument=R, position=eta1, d=d, m=xi, D=D, t=tau, Instrument=R,
alpha=alpha, q=q, Projection=P, nonlinearity=f, alpha=alpha, q=q, Projection=P, nonlinearity=f,
FFT=fft, samples=3) ht=ht, sample_list=sample_list)
a = (energy1.value - energy0.value) / eps a = (energy1.value - energy0.value) / eps
b = energy0.gradient.vdot(direction) b = energy0.gradient.vdot(direction)
tol = 1e-2 tol = 1e-5
assert_allclose(a, b, rtol=tol, atol=tol) assert_allclose(a, b, rtol=tol, atol=tol)
...@@ -29,8 +29,10 @@ from numpy.testing import assert_allclose ...@@ -29,8 +29,10 @@ from numpy.testing import assert_allclose
class Power_Energy_Tests(unittest.TestCase): class Power_Energy_Tests(unittest.TestCase):
@expand(product([ift.RGSpace(64, distances=.789), @expand(product([ift.RGSpace(64, distances=.789),
ift.RGSpace([32, 32], distances=.789)])) ift.RGSpace([32, 32], distances=.789)],
def testLinearPower(self, space): [