Commit b5f2473f authored by Martin Reinecke's avatar Martin Reinecke

temporary

parent d27bca16
......@@ -68,7 +68,7 @@ class CriticalPowerEnergy(Energy):
self.rho = self.position.domain[0].rho
self._w = w if w is not None else None
def at(self, position):
def at(self, position): #MR what about logarithmic?
return self.__class__(position, self.m, D=self.D, alpha=self.alpha,
q=self.q, smoothness_prior=self.smoothness_prior,
w=self.w, samples=self.samples)
......
......@@ -63,7 +63,7 @@ class LineSearchStrongWolfe(LineSearch):
def __init__(self, c1=1e-4, c2=0.9,
max_step_size=1000000000, max_iterations=100,
max_zoom_iterations=100):
max_zoom_iterations=30):
super(LineSearchStrongWolfe, self).__init__()
......@@ -141,6 +141,7 @@ class LineSearchStrongWolfe(LineSearch):
if (phi_alpha1 > phi_0 + self.c1*alpha1*phiprime_0) or \
((phi_alpha1 >= phi_alpha0) and (i > 0)):
print "zoom1:",i
(alpha_star, phi_star, le_star) = self._zoom(
alpha0, alpha1,
phi_0, phiprime_0,
......@@ -157,6 +158,7 @@ class LineSearchStrongWolfe(LineSearch):
break
if phiprime_alpha1 >= 0:
print "zoom2:",i
(alpha_star, phi_star, le_star) = self._zoom(
alpha1, alpha0,
phi_0, phiprime_0,
......@@ -233,34 +235,19 @@ class LineSearchStrongWolfe(LineSearch):
# define the cubic and quadratic interpolant checks
cubic_delta = 0.2 # cubic
quad_delta = 0.1 # quadratic
phiprime_alphaj = 0.
# initialize the most recent versions (j-1) of phi and alpha
alpha_recent = None
phi_recent = None
#alpha_recent = None
#phi_recent = None
assert phi_lo <= phi_0 + self.c1*alpha_lo*phiprime_0
assert phiprime_lo*(alpha_hi-alpha_lo)<0.
print "enter:"
for i in xrange(max_iterations):
#assert phi_lo <= phi_0 + self.c1*alpha_lo*phiprime_0
#assert phiprime_lo*(alpha_hi-alpha_lo)<0.
# print alpha_lo, alpha_hi
delta_alpha = alpha_hi - alpha_lo
if delta_alpha < 0:
a, b = alpha_hi, alpha_lo
else:
a, b = alpha_lo, alpha_hi
# Try cubic interpolation
if i > 0:
cubic_check = cubic_delta * delta_alpha
alpha_j = self._cubicmin(alpha_lo, phi_lo, phiprime_lo,
alpha_hi, phi_hi,
alpha_recent, phi_recent)
# If cubic was not successful or not available, try quadratic
if (i == 0) or (alpha_j is None) or (alpha_j > b - cubic_check) or\
(alpha_j < a + cubic_check):
quad_check = quad_delta * delta_alpha
alpha_j = self._quadmin(alpha_lo, phi_lo, phiprime_lo,
alpha_hi, phi_hi)
# If quadratic was not successful, try bisection
if (alpha_j is None) or (alpha_j > b - quad_check) or \
(alpha_j < a + quad_check):
alpha_j = alpha_lo + 0.5*delta_alpha
alpha_j = alpha_lo + 0.5*delta_alpha
# Check if the current value of alpha_j is already sufficient
le_alphaj = self.line_energy.at(alpha_j)
......@@ -268,11 +255,17 @@ class LineSearchStrongWolfe(LineSearch):
# If the first Wolfe condition is not met replace alpha_hi
# by alpha_j
# print "W1:", phi_alphaj, phi_0 + self.c1*alpha_j*phiprime_0
print alpha_lo, phi_lo
print alpha_hi, phi_hi
# print phi_lo, phi_hi, phi_alphaj
# print phiprime_lo, phiprime_alphaj
if (phi_alphaj > phi_0 + self.c1*alpha_j*phiprime_0) or\
(phi_alphaj >= phi_lo):
alpha_recent, phi_recent = alpha_hi, phi_hi
# print "beep"
alpha_hi, phi_hi = alpha_j, phi_alphaj
else:
# print "boop"
phiprime_alphaj = le_alphaj.dd
# If the second Wolfe condition is met, return the result
if abs(phiprime_alphaj) <= -self.c2*phiprime_0:
......@@ -282,10 +275,7 @@ class LineSearchStrongWolfe(LineSearch):
break
# If not, check the sign of the slope
if phiprime_alphaj*delta_alpha >= 0:
alpha_recent, phi_recent = alpha_hi, phi_hi
alpha_hi, phi_hi = alpha_lo, phi_lo
else:
alpha_recent, phi_recent = alpha_lo, phi_lo
# Replace alpha_lo by alpha_j
(alpha_lo, phi_lo, phiprime_lo) = (alpha_j, phi_alphaj,
phiprime_alphaj)
......
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