Error Messages/Gradient descrepancy
Warning Message
In NlpDefine, the gradient expression has computed a value that differs by 93.453% from the value estimated using finite differencing on the first variable at the point X = [0.74, -0.38, -7.51e-002, 0.34, -0.10, -0.40, -5.85e-003] This indicates that you likely have an error in your expression for the gradient. To turn this warning permanently off, remove the "Derivatives" = 4 setting.
Cause
This warning is used when you are debugging an analytic gradient expression, and occurs when your analytic expression appears to be computing the wrong gradient values.
When using NlpDefine, you can speed up the optimization search by supplying an analytically-computed gradient expression. Without such an expression, gradient-based solver engines like "GRG Nonlinear" must estimate the derivates using finite-differencing, resulting in far more model evaluations. When a correct gradient expression is provided, the search proceeds faster, but if the gradient expression is in error, it can throw off and mislead the search process.
Debugging a gradient expression can be difficult, so a facility is provided to test your expression against finite differencing to see if it agrees. This facility is turned on by setting the Derivatives setting to 4, like this:
NlpDefine(..., settingsName: "Derivative", settingsValue: 4)
When this is on, NlpDefine evaluates your gradient expression to obtain the gradient, but then also computes it using finite differencing and compares the two. If a difference exists, this warning appears. This should be used while debugging since, obviously, leaving this switch on slows down evaluation and defeats the purpose of supplying an analytic gradient.
Enable comment auto-refresher