Why DerivativeCheck would be allowed to be on while there is no GradObj?
4 ビュー (過去 30 日間)
When GradObj is off, and DerivativeCheck is on, fmincon starts to run without any error or warning. Why would this be the case? That is, if there is no gradient supplied, there cannot be derivattive check. So why would MATLAB allow the DerivativeCheck to be on if there is no gradient available?
options = optimset(...
Here's a reason why you might want to allow DerivativeCheck to be on even when the analytical gradient computations are all off. Suppose the user has coded 6 different implementations of the gradient calculation and wants to compare them all for speed. Suppose also that she wants to run the optimization with finite difference gradient computations as a baseline for the comparison.
In this situation, you would want to have DerivativeCheck='on' for 6 different runs. To run the finite differencing baseline, however, your proposal would force the user to set both SpecifyObjectiveGradient=false and DerivativeCheck='off'. Some people would prefer just to set SpecifyObjectiveGradient=false and not to have to fuss with additional settings for just that one case.
その他の回答 (3 件)
John D'Errico 2023 年 1 月 27 日
Moved: Walter Roberson 2023 年 1 月 27 日
You can set other options that will be ignored if they are not applicable. Would you rather have the code fail for no reason on a problem that has a solution?
編集済み: Matt J 2023 年 1 月 28 日
I would say that no warning is strictly necessary because one of two cases are possible:
(1) DerivativeCheck='on' was intentional, but GradObj='off' was unintentional. If so, you will be warned that something is wrong by the fact that no derivative check output appears.
(2) GradObj='off' was intentional, but DerivativeCheck='on' was unintentional. If so, it would be your wish that the optimization proceed without a derivative check and, indeed, that is what happens.
That said, I do agree that an explicit warning message in case (1) would be more aesthetic.
編集済み: Matt J 2023 年 1 月 29 日
The user sees that things still run fine with nonsense settings.
It might be overstating things slightly to say that the settings are "nonsense". The main purpose of DerivativeCheck is to prevent the optimization from using analytical gradient calculations that are faulty. However, if SpecifyObjectiveGradient is turned off, the user is not supplying the gradient, and so there is no danger this will occur. So, arguably, the purpose of DerivativeCheck has been fulfilled and the optimization should just proceed care-free.
As I mention in my other answer, it would be nice if Matlab could warn you when you shut off analytical gradient calculations accidentally, or forget to turn them back on. But that is simply not always something Matlab can detect, and in any case is not something DerivativeCheck was primarily designed to protect against.
編集済み: Matt J 2023 年 1 月 28 日
So why would MATLAB allow the DerivativeCheck to be on if there is no gradient available?
Because maybe SpecifyConstraintGradient=true, even if SpecyObjectiveGradient=false. In your example, this is not the case. In general however, there are 4 possible combinations of settings for SpecifyObjectiveGradient and SpecifyConstraintGradient and only one of these combinations is suspicious when DerivativeCheck='on'. Therefore, there is very limited protection a warning message could provide against users accidentally turning off analytical gradient computation.
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!