Skip to content

Commit ead7372

Browse files
committed
restore (much) better dh estimate
1 parent cfad68c commit ead7372

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/madl_match.mad

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -560,13 +560,18 @@ local function compute_fgrd (env)
560560
-- backup states
561561
backup(var, bak)
562562

563-
-- last step norm
563+
-- estimate dh from last step or current point
564564
local hn = h:norm()
565+
local dh = 1e-4*hn
566+
if dh == 0 then dh = 1e-8*x:norm() end
567+
if dh == 0 then dh = 1e-10 end
568+
569+
if trc then printf("nlopt: computing derivatives with dh=%-.5e\n", dh) end
565570

566571
-- Broyden's Jacobian update
567572
local bro, Bc = env.objective.broyden and prv.c ~= nil and hn ~= 0
568573
if bro then
569-
if trc then printf("nlopt: Broyden's update with |hn|=%-.8e\n", hn) end
574+
if trc then printf("nlopt: Broyden's update with |hn|=%-.5e\n", hn) end
570575
Bc = cjac + (c - prv.c - cjac*h)*h:t()/hn^2
571576
end
572577

@@ -575,12 +580,13 @@ local function compute_fgrd (env)
575580
if bro and h[iv] >= 0.8*hn then -- Broyden's rank one update
576581
cjac:setcol(iv, Bc:getcol(iv))
577582
if trc then
578-
printf("nlopt: Broyden's update for variable %d (%-.8e)\n", iv, h[iv])
583+
printf("nlopt: Broyden's update for variable %d (%-.5e)\n", iv, h[iv])
579584
end
580585
else -- finite difference required
581-
local ih = x[iv] ~= 0 and x[iv]*xstp[iv] or 1e-12
586+
local ih = x[iv]*xstp[iv]
587+
if ih == 0 then ih = dh end
582588
x[iv] = x[iv]+ih ; var.fval = fval
583-
if x[iv] < xmin[iv] or x[iv] > xmax[iv] then
589+
if x[iv] < xmin[iv] or x[iv] > xmax[iv] or ih*xslp[iv] < 0 then
584590
x[iv], ih = x[iv]-2*ih, -ih -- take -ih if bbox are violated
585591
end
586592

@@ -814,7 +820,7 @@ local function exec (self)
814820
local v = variables[i] or {}
815821
if v.get then var.x0[i] = v.get(env) end
816822
var.x [i] = var.x0[i]
817-
var.xstp[i] = v.rstp or variables.rstp or 1e-8
823+
var.xstp[i] = v.rstp or variables.rstp or 0
818824
var.xslp[i] = v.slope or variables.slope or 0
819825
var.xtol[i] = v.tol or variables.tol or 0
820826
var.xmin[i] = v.min or variables.min or -inf

0 commit comments

Comments
 (0)