You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# error("Failed to achieve finite test value; alphatest = ", alphatest)
234
-
end
235
-
236
-
alphatest = psi3 * alphatest
237
-
phitest =ϕ(alphatest)
238
-
iterfinite +=1
239
-
end
240
-
a = ((phitest-phi_0)/alphatest - dphi_0)/alphatest # quadratic fit
241
-
242
-
if verbose ==true
243
-
println("quadfit: alphatest = ", alphatest,
244
-
", phi_0 = ", phi_0,
245
-
", dphi_0 = ", dphi_0,
246
-
", phitest = ", phitest,
247
-
", quadcoef = ", a)
248
-
end
249
-
mayterminate[] =false
250
-
ifisfinite(a) && a >0&& phitest <= phi_0
251
-
alpha =-dphi_0 /2/ a # if convex, choose minimum of quadratic
252
-
if alpha ==0
253
-
error("alpha is zero. dphi_0 = ", dphi_0, ", phi_0 = ", phi_0, ", phitest = ", phitest, ", alphatest = ", alphatest, ", a = ", a)
254
-
end
255
-
if alpha <= alphamax
256
-
mayterminate[] =true
257
-
else
258
-
alpha = alphamax
259
-
mayterminate[] =false
260
-
end
232
+
mayterminate[] = quadstep_success =false
233
+
if quadstep
234
+
a = ((phitest - phi_0) / alphatest - dphi_0) / alphatest # quadratic fit
261
235
if verbose ==true
262
-
println("alpha guess (quadratic): ", alpha,
263
-
",(mayterminate = ", mayterminate, ")")
236
+
println("quadfit: alphatest = ", alphatest,
237
+
", phi_0 = ", phi_0,
238
+
", dphi_0 = ", dphi_0,
239
+
", phitest = ", phitest,
240
+
", quadcoef = ", a)
264
241
end
265
-
else
266
-
if phitest > phi_0
267
-
alpha = alphatest
268
-
else
269
-
alpha *= psi2 # if not convex, expand the interval
242
+
ifisfinite(a) && a >0&& phitest <= phi_0
243
+
alphatest2 =-dphi_0 /2/ a # if convex, choose minimum of quadratic
244
+
alphatest2 =min(alphatest2, alphamax)
245
+
phitest2 =ϕ(alphatest2)
246
+
ifisfinite(phitest2)
247
+
mayterminate[] = quadstep_success =true
248
+
alphatest = alphatest2
249
+
phitest = phitest2
250
+
if verbose ==true
251
+
println("alpha guess (quadratic): ", alphatest,
252
+
",(mayterminate = ", mayterminate[], ")")
253
+
end
254
+
end
270
255
end
271
256
end
272
-
alpha =min(alphamax, alpha)
273
-
if verbose ==true
274
-
println("alpha guess (expand): ", alpha)
257
+
if (!quadstep ||!quadstep_success) && phitest <= phi_0
258
+
# If no quadstep or it fails, expand the interval.
259
+
# While the phitest <= phi_0 condition was not in the paper, it gives a significant boost to the speed. The rationale behind it is that since the slope at alpha = 0 is negative, if phitest > phi_0 then a local minimum must be between alpha = 0 and alpha = alphatest, so alpha_test is good enough to return.
0 commit comments