how does check gradient compare supplied gradients with finite difference gradients?

5 ビュー (過去 30 日間)
omid Heydarnia
omid Heydarnia 2023 年 5 月 10 日
コメント済み: Torsten 2023 年 5 月 11 日
Dears,
I supplied objective function gradients for the fmincon that faced an error with a massive difference between supplied and finite difference! Since I checked the way I provide gradients multiple times and implemented it for other systems, I thought a singularity might cause this big difference!
I have 415 optimization parameters, and the error occurs for 380. Interestingly, my optimization problem is a direct multiple shooting for a system which means the error occurs on one of the control parameters that objective gradient respect to it was correct in the past shooting nodes!!
I'll be grateful if you know how the check gradient option works. And give some insight into this problem.

回答 (1 件)

Alan Weiss
Alan Weiss 2023 年 5 月 11 日
The CheckGradients option causes solvers to compare a finite-difference gradient estimate to the supplied gradient value, and if the relative difference is more than 1e-6 apart, CheckGradients throws an error.
Sorry, the option has no provision for changing the 1e-6 tolerance. The option does respond appropriately to the FiniteDifferenceType and FiniteDifferenceStepSize options, so you can play around with those options to see if you can get the CheckGradients option to work more effectively for you.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 件のコメント
omid Heydarnia
omid Heydarnia 2023 年 5 月 11 日
Thank Alen for your answer.
Would you please tell me how I can interpret the error log? For example, when the log demonstrates the error between supplied and finite-difference gradient for derivative element (368,1) is high, can I interpret that the supplied gradient elements between 1 to 367 are less than 1e-6?
Torsten
Torsten 2023 年 5 月 11 日
It's easy to check by inserting an obvious error in one of the elements from 1 to 367 :-)
Then you can be certain that these elements have been checked before.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by