Old-style difference is not a good choice because sometimes you have values to compare like 1.24*105 (user-supplied) and 1.23*105 (finite-difference), while sometimes 1.24*10-5 (user-supplied) and 1.23*10-5 (finite-difference).
The new way is based on comparing
1 - derivative_user/derivative_finite_diff
to maxViolation value
The parameter maxViolation can be used as prob field or via for example p.checkdc(maxViolation=0.05)
Note that x remains to be 1st argument for checkdc, checkdf, checkdh (default p.x0), and can be used as kwarg as well: p.checkdh(maxViolation=0.05, x = 0.5*(p.lb+p.ub)), that is same to p.checkdh(0.5*(p.lb+p.ub), maxViolation=0.05).
So new text output is like this one below (this one is produced by updated examples/checkDerivatives.py file).
Note that RD (relative difference) is defined as
int(ceil(log10(abs(Diff) / maxViolation + 1e-150)))
where
Diff = 1 - (info_user+1e-150)/(info_numerical + 1e-150)
(those small numbers are used to suppress zeros)
################################
OpenOpt checks user-supplied gradient df (shape: (30,) )
according to prob.diffInt = [9.9999999999999995e-08]
lines with 1 - info_user/info_numerical greater than maxViolation = 0.01 will be shown
df num user-supplied numerical RD
0 +7.000e+00 -8.000e+00 3
8 -2.291e+00 -1.029e+01 2
max(abs(df_user - df_numerical)) = 14.9999995251
(is registered in df number 0)
========================
OpenOpt checks user-supplied gradient dc (shape: (2, 30) )
according to prob.diffInt = [9.9999999999999995e-08]
lines with 1 - info_user/info_numerical greater than maxViolation = 0.01 will be shown
dc num i,j:dc[i]/dx[j] user-supplied numerical RD
32 1 / 2 +1.417e+01 -8.323e-01 4
max(abs(dc_user - dc_numerical)) = 14.9999999032
(is registered in dc number 32)
========================
OpenOpt checks user-supplied gradient dh (shape: (2, 30) )
according to prob.diffInt = [9.9999999999999995e-08]
lines with 1 - info_user/info_numerical greater than maxViolation = 0.01 will be shown
dh num i,j:dh[i]/dx[j] user-supplied numerical RD
58 1 / 28 -4.474e+01 -5.974e+01 2
max(abs(dh_user - dh_numerical)) = 14.9999962441
(is registered in dh number 58)
========================
No comments:
Post a Comment