Commit c754769f authored by Martin Reinecke's avatar Martin Reinecke

intermediate stage

parent 67950f71
...@@ -115,10 +115,13 @@ if __name__ == "__main__": ...@@ -115,10 +115,13 @@ if __name__ == "__main__":
iteration_limit=3, iteration_limit=3,
callback=convergence_measure) callback=convergence_measure)
minimizer2 = VL_BFGS(convergence_tolerance=0, minimizer2 = VL_BFGS(convergence_tolerance=1e-3,
iteration_limit=7, iteration_limit=70,
callback=convergence_measure, callback=convergence_measure,
max_history_length=3) max_history_length=10)
minimizer3 = SteepestDescent(convergence_tolerance=1e-3,
iteration_limit=70,
callback=convergence_measure)
# Setting starting position # Setting starting position
flat_power = Field(p_space,val=1e-8) flat_power = Field(p_space,val=1e-8)
...@@ -140,7 +143,7 @@ if __name__ == "__main__": ...@@ -140,7 +143,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) = minimizer1(power_energy) (power_energy, convergence) = minimizer2(power_energy)
# Setting new power spectrum # Setting new power spectrum
......
...@@ -121,18 +121,18 @@ class DescentMinimizer(Loggable, object): ...@@ -121,18 +121,18 @@ class DescentMinimizer(Loggable, object):
""" """
print "into line search:" #print "into line search:"
print " pos: ",energy.position.val[0] #print " pos: ",energy.position.val[0]
print " ene: ",energy.value #print " ene: ",energy.value
convergence = 0 convergence = 0
f_k_minus_1 = None f_k_minus_1 = None
step_length = 0 step_length = 0
iteration_number = 1 iteration_number = 1
while True: while True:
print "line search next iteration:" #print "line search next iteration:"
print " pos: ",energy.position.val[0] #print " pos: ",energy.position.val[0]
print " ene: ",energy.value #print " ene: ",energy.value
if self.callback is not None: if self.callback is not None:
try: try:
self.callback(energy, iteration_number) self.callback(energy, iteration_number)
...@@ -153,7 +153,7 @@ class DescentMinimizer(Loggable, object): ...@@ -153,7 +153,7 @@ class DescentMinimizer(Loggable, object):
# current position is encoded in energy object # current position is encoded in energy object
descent_direction = self.get_descent_direction(energy) descent_direction = self.get_descent_direction(energy)
print "descent direction:",descent_direction.val[0] #print "descent direction:",descent_direction.val[0]
# compute the step length, which minimizes energy.value along the # compute the step length, which minimizes energy.value along the
# search direction # search direction
step_length, f_k, new_energy = \ step_length, f_k, new_energy = \
...@@ -161,17 +161,17 @@ class DescentMinimizer(Loggable, object): ...@@ -161,17 +161,17 @@ 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)
print "out of wolfe:" #print "out of wolfe:"
print " old pos: ",energy.position.val[0] #print " old pos: ",energy.position.val[0]
print " old ene: ",energy.value #print " old ene: ",energy.value
print " new pos: ",new_energy.position.val[0] #print " new pos: ",new_energy.position.val[0]
print " new ene: ",new_energy.value #print " new ene: ",new_energy.value
print " f_k: ",f_k #print " f_k: ",f_k
f_k_minus_1 = energy.value f_k_minus_1 = energy.value
print " step length: ", step_length #print " step length: ", step_length
tx1=energy.position-new_energy.position tx1=energy.position-new_energy.position
print " step length 2: ", (energy.position-new_energy.position).norm() #print " step length 2: ", (energy.position-new_energy.position).norm()
print " step length 3: ", new_energy.position.val[0]-energy.position.val[0] #print " step length 3: ", new_energy.position.val[0]-energy.position.val[0]
# check if new energy value is bigger than old energy value # check if new energy value is bigger than old energy value
if (new_energy.value - energy.value) > 0: if (new_energy.value - energy.value) > 0:
print "Line search algorithm returned a new energy that was larger than the old one. Stopping." print "Line search algorithm returned a new energy that was larger than the old one. Stopping."
......
...@@ -61,6 +61,9 @@ class LineSearchStrongWolfe(LineSearch): ...@@ -61,6 +61,9 @@ class LineSearchStrongWolfe(LineSearch):
""" """
# def __init__(self, c1=1e-4, c2=0.9,
# max_step_size=1000000000, max_iterations=100,
# max_zoom_iterations=100):
def __init__(self, c1=1e-4, c2=0.9, def __init__(self, c1=1e-4, c2=0.9,
max_step_size=50, max_iterations=10, max_step_size=50, max_iterations=10,
max_zoom_iterations=10): max_zoom_iterations=10):
...@@ -111,6 +114,7 @@ class LineSearchStrongWolfe(LineSearch): ...@@ -111,6 +114,7 @@ class LineSearchStrongWolfe(LineSearch):
le_0 = self.line_energy.at(0) le_0 = self.line_energy.at(0)
phi_0 = le_0.value phi_0 = le_0.value
phiprime_0 = le_0.dd phiprime_0 = le_0.dd
assert phiprime_0<0, "input direction must be a descent direction"
if phiprime_0 == 0: if phiprime_0 == 0:
self.logger.warn("Flat gradient in search direction.") self.logger.warn("Flat gradient in search direction.")
...@@ -133,12 +137,12 @@ class LineSearchStrongWolfe(LineSearch): ...@@ -133,12 +137,12 @@ class LineSearchStrongWolfe(LineSearch):
# start the minimization loop # start the minimization loop
for i in xrange(max_iterations): for i in xrange(max_iterations):
print "a0a1:",alpha0, alpha1 #print "a0a1:",alpha0, alpha1
print "line search outer iteration", i #print "line search outer iteration", i
le_alpha1 = self.line_energy.at(alpha1) le_alpha1 = self.line_energy.at(alpha1)
print "position:", le_alpha1.energy.position.val[0] #print "position:", le_alpha1.energy.position.val[0]
phi_alpha1 = le_alpha1.value phi_alpha1 = le_alpha1.value
print "energy:", le_alpha1.value #print "energy:", le_alpha1.value
if alpha1 == 0: if alpha1 == 0:
self.logger.warn("Increment size became 0.") self.logger.warn("Increment size became 0.")
alpha_star = 0. alpha_star = 0.
...@@ -175,6 +179,7 @@ class LineSearchStrongWolfe(LineSearch): ...@@ -175,6 +179,7 @@ class LineSearchStrongWolfe(LineSearch):
# update alphas # update alphas
alpha0, alpha1 = alpha1, min(2*alpha1, max_step_size) alpha0, alpha1 = alpha1, min(2*alpha1, max_step_size)
if alpha1 == max_step_size: if alpha1 == max_step_size:
print "bailout"
alpha_star = alpha1 alpha_star = alpha1
phi_star = phi_alpha1 phi_star = phi_alpha1
le_star = le_alpha1 le_star = le_alpha1
...@@ -235,10 +240,10 @@ class LineSearchStrongWolfe(LineSearch): ...@@ -235,10 +240,10 @@ class LineSearchStrongWolfe(LineSearch):
The new Energy object on the new position. The new Energy object on the new position.
""" """
print "entering zoom" #print "entering zoom"
print alpha_lo, alpha_hi #print alpha_lo, alpha_hi
print "pos1:",self.line_energy.at(alpha_lo).energy.position.val[0] #print "pos1:",self.line_energy.at(alpha_lo).energy.position.val[0]
print "pos2:",self.line_energy.at(alpha_hi).energy.position.val[0] #print "pos2:",self.line_energy.at(alpha_hi).energy.position.val[0]
max_iterations = self.max_zoom_iterations max_iterations = self.max_zoom_iterations
# define the cubic and quadratic interpolant checks # define the cubic and quadratic interpolant checks
cubic_delta = 0.2 # cubic cubic_delta = 0.2 # cubic
......
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