Commit 2dfde4c2 authored by Martin Reinecke's avatar Martin Reinecke

more energy test improvements

parent 597286b4
......@@ -52,7 +52,6 @@ def check_value_gradient_consistency(E, tol=1e-6, ntries=100):
dir = E2.position - E.position
Enext = E2
dirnorm = dir.norm()
dirder = E.gradient.vdot(dir)/dirnorm
for i in range(50):
Emid = E.at(E.position + 0.5*dir)
dirder = Emid.gradient.vdot(dir)/dirnorm
......@@ -69,19 +68,20 @@ def check_value_gradient_consistency(E, tol=1e-6, ntries=100):
def check_value_gradient_curvature_consistency(E, tol=1e-6, ntries=100):
for _ in range(ntries):
E2 = _get_acceptable_energy(E)
val = E.value
dir = E2.position - E.position
Enext = E2
dirnorm = dir.norm()
dirder = E.gradient.vdot(dir)/dirnorm
dgrad = E.curvature(dir)/dirnorm
for i in range(50):
gdiff = E2.gradient - E.gradient
if abs((E2.value-E.value)/dirnorm-dirder) < tol and \
Emid = E.at(E.position + 0.5*dir)
dirder = Emid.gradient.vdot(dir)/dirnorm
dgrad = Emid.curvature(dir)/dirnorm
if abs((E2.value-val)/dirnorm-dirder) < tol and \
(abs((E2.gradient-E.gradient)/dirnorm-dgrad) < tol).all():
break
dir *= 0.5
dirnorm *= 0.5
E2 = E2.at(E.position+dir)
E2 = Emid
else:
raise ValueError("gradient, value and curvature seem inconsistent")
# E = Enext
......@@ -70,6 +70,7 @@ def get_signal_variance(spec, space):
k_field = dist(field)
return k_field.weight(2).sum()
def _single_power_analyze(field, idx, binbounds):
power_domain = PowerSpace(field.domain[idx], binbounds)
pd = PowerDistributor(field.domain, power_domain, idx)
......
......@@ -25,6 +25,7 @@ from test.common import expand
dom = ift.makeDomain({"d1": ift.RGSpace(10)})
class Test_Functionality(unittest.TestCase):
def test_vdot(self):
f1 = ift.from_random("normal", domain=dom, dtype=np.complex128)
......@@ -53,7 +54,8 @@ class Test_Functionality(unittest.TestCase):
assert_equal(val.local_data, f2[key].local_data)
def test_blockdiagonal(self):
op = ift.BlockDiagonalOperator({"d1": ift.ScalingOperator(20., dom["d1"])})
op = ift.BlockDiagonalOperator({"d1":
ift.ScalingOperator(20., dom["d1"])})
op2 = op*op
ift.extra.consistency_check(op2)
assert_equal(type(op2), ift.BlockDiagonalOperator)
......
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