Commit d27bca16 authored by Martin Reinecke's avatar Martin Reinecke

new stopping criterion

parent 4ee9b94a
Pipeline #14905 passed with stage
in 6 minutes and 15 seconds
...@@ -76,8 +76,8 @@ if __name__ == "__main__": ...@@ -76,8 +76,8 @@ if __name__ == "__main__":
# Choosing the measurement instrument # Choosing the measurement instrument
Instrument = SmoothingOperator(s_space, sigma=0.01) # Instrument = SmoothingOperator(s_space, sigma=0.01)
# Instrument = DiagonalOperator(s_space, diagonal=1.) Instrument = DiagonalOperator(s_space, diagonal=1.)
# Instrument._diagonal.val[200:400, 200:400] = 0 # Instrument._diagonal.val[200:400, 200:400] = 0
#Instrument._diagonal.val[64:512-64, 64:512-64] = 0 #Instrument._diagonal.val[64:512-64, 64:512-64] = 0
...@@ -100,8 +100,8 @@ if __name__ == "__main__": ...@@ -100,8 +100,8 @@ if __name__ == "__main__":
realized_power = log(sh.power_analyze(binbounds=p_space.binbounds)) realized_power = log(sh.power_analyze(binbounds=p_space.binbounds))
data_power = log(fft(d).power_analyze(binbounds=p_space.binbounds)) data_power = log(fft(d).power_analyze(binbounds=p_space.binbounds))
d_data = d.val.get_full_data().real d_data = d.val.get_full_data().real
#if rank == 0: if rank == 0:
# pl.plot([go.Heatmap(z=d_data)], filename='data.html') pl.plot([go.Heatmap(z=d_data)], filename='data.html')
# minimization strategy # minimization strategy
...@@ -110,17 +110,18 @@ if __name__ == "__main__": ...@@ -110,17 +110,18 @@ if __name__ == "__main__":
print (x, iteration) print (x, iteration)
minimizer1 = RelaxedNewton(convergence_tolerance=1e-2, minimizer1 = RelaxedNewton(convergence_tolerance=1e-8,
convergence_level=2, convergence_level=1,
iteration_limit=5, iteration_limit=5,
callback=convergence_measure) callback=convergence_measure)
minimizer2 = VL_BFGS(convergence_tolerance=1e-3, minimizer2 = VL_BFGS(convergence_tolerance=1e-8,
iteration_limit=20, convergence_level=1,
iteration_limit=1000,
callback=convergence_measure, callback=convergence_measure,
max_history_length=10) max_history_length=20)
minimizer3 = SteepestDescent(convergence_tolerance=1e-3, minimizer3 = SteepestDescent(convergence_tolerance=1e-8,
iteration_limit=70, iteration_limit=500,
callback=convergence_measure) callback=convergence_measure)
# Setting starting position # Setting starting position
...@@ -143,7 +144,7 @@ if __name__ == "__main__": ...@@ -143,7 +144,7 @@ if __name__ == "__main__":
# Initializing the power energy with updated parameters # Initializing the power energy with updated parameters
power_energy = CriticalPowerEnergy(position=t0, m=m0, D=D0, smoothness_prior=10., samples=3) power_energy = CriticalPowerEnergy(position=t0, m=m0, D=D0, smoothness_prior=10., samples=3)
(power_energy, convergence) = minimizer3(power_energy) (power_energy, convergence) = minimizer2(power_energy)
# Setting new power spectrum # Setting new power spectrum
...@@ -151,7 +152,7 @@ if __name__ == "__main__": ...@@ -151,7 +152,7 @@ if __name__ == "__main__":
# Plotting current estimate # Plotting current estimate
print i print i
#if i%50 == 0: if i%50 == 0:
# plot_parameters(m0,t0,log(sp), data_power) plot_parameters(m0,t0,log(sp), data_power)
...@@ -108,6 +108,7 @@ class LineEnergy: ...@@ -108,6 +108,7 @@ class LineEnergy:
@property @property
def dd(self): def dd(self):
res = self.energy.gradient.vdot(self.linedir) res = self.energy.gradient.vdot(self.linedir)
assert abs(res-res.real)<1e-12, \ if abs(res.imag)/max(abs(res.real),1.)>1e-12:
"directional derivative has non-negligible imaginary part" print "directional derivative has non-negligible " \
"imaginary part:", res
return res.real return res.real
...@@ -154,6 +154,10 @@ class DescentMinimizer(Loggable, object): ...@@ -154,6 +154,10 @@ class DescentMinimizer(Loggable, object):
energy=energy, energy=energy,
pk=descent_direction, pk=descent_direction,
f_k_minus_1=f_k_minus_1) f_k_minus_1=f_k_minus_1)
if f_k_minus_1 is None:
delta=1e30
else:
delta = abs(f_k -f_k_minus_1)/max(abs(f_k),abs(f_k_minus_1),1.)
f_k_minus_1 = energy.value f_k_minus_1 = energy.value
tx1=energy.position-new_energy.position tx1=energy.position-new_energy.position
# check if new energy value is bigger than old energy value # check if new energy value is bigger than old energy value
...@@ -165,7 +169,6 @@ class DescentMinimizer(Loggable, object): ...@@ -165,7 +169,6 @@ class DescentMinimizer(Loggable, object):
energy = new_energy energy = new_energy
# check convergence # check convergence
delta = abs(gradient).max() * step_length / gradient_norm
self.logger.debug("Iteration:%08u step_length=%3.1E " self.logger.debug("Iteration:%08u step_length=%3.1E "
"delta=%3.1E energy=%3.1E" % "delta=%3.1E energy=%3.1E" %
(iteration_number, step_length, delta, (iteration_number, step_length, delta,
......
...@@ -43,7 +43,8 @@ class Test_DescentMinimizers(unittest.TestCase): ...@@ -43,7 +43,8 @@ class Test_DescentMinimizers(unittest.TestCase):
covariance = DiagonalOperator(space, diagonal=covariance_diagonal) covariance = DiagonalOperator(space, diagonal=covariance_diagonal)
energy = QuadraticPotential(position=starting_point, energy = QuadraticPotential(position=starting_point,
eigenvalues=covariance) eigenvalues=covariance)
minimizer = minimizer_class(iteration_limit=30) minimizer = minimizer_class(iteration_limit=30,
convergence_tolerance=1e-10)
(energy, convergence) = minimizer(energy) (energy, convergence) = minimizer(energy)
......
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