possible to reduce the relative difference for CheckGradients in optimization (fmincon)?
4 次查看(过去 30 天)
显示 更早的评论
When double-checking my Jacobian using CheckGradients, I have a relative maximum difference of, crudely, 4e-6,
and my entries of the Jacobian are in the ballpark 1e-1.
I do not expect that Finite Difference can calculate the first six digits after the decimal correctly as my problem has large second derivatives.
That said, can I reduce the relative difference in CheckGradients from 1e-6 to a different value?
0 个评论
采纳的回答
Matt J
2022-10-26
编辑:Matt J
2022-10-27
This FEX download allows you to obtain the results of the finite differencing, as well as to decide where (at what x) you want it computed,
Occasionally also, I find it to be more accurate and reliable as a checking tool than CheckGradient.
In any case, because it gives you the computed FD gradient, you can use this tool to compare both the finite difference and analytical gradients according to whatever error criterion that you wish.
更多回答(1 个)
Torsten
2022-10-26
编辑:Torsten
2022-10-26
Why not just turning off the CheckGradient feature if you are sure your derivatives are correct within a certain error tolerance (which might be larger than 1e-6) ?
5 个评论
Torsten
2022-10-27
To me, the fixed value of 1e-6 does not make sense at all. Say, the entries were in the ballpark 1e-6 -- gradient check would work even if the first relevant digit is wrong. On the other hand, if the entries were 1e-1, gradient check fails although the first 4 or 5 digits are correct.
I don't think that 1e-6 is an absolute, but a relative error in the calculation. Thus
|| gradient_MATLAB - gradient_USER || <= eps * ||gradient_MATLAB||
or something similar is checked for
||gradient_MATLAB|| > 1
and
|| gradient_MATLAB - gradient_USER|| <= eps
only for
||gradient_MATLAB|| <= 1
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!