怎么可视化dlgradient?

3 ビュー (過去 30 日間)
浩然 吴
浩然 吴 2022 年 6 月 11 日
回答済み: Ninad 2023 年 9 月 13 日
dy = dlgradient(sum(y,"all"),dlX,EnableHigherDerivatives=true);
怎么可视化上述代码

回答 (1 件)

Ninad
Ninad 2023 年 9 月 13 日
Hello,
As per my understanding, the line of code mentioned above will calculate the gradient of the sum of elements in the array `y` with respect to the input `dlX`.
Thus, the variable `dy` will have the same dimension as the input `dlX`.
You may use the `quiver` function to plot the gradients calculated using the `dlgradient` function.
The `quiver (X, Y, U, V) ` function in MATLAB plots arrows with directional components U and V at the Cartesian coordinates specified by X and Y. Each arrow represents a vector starting from the corresponding point (X, Y) and extending horizontally by U and vertically by V. By default, the function scales the arrow lengths to prevent overlapping.
Rosenbrock’s function is a standard test function for optimization. You may use it for demonstration purpose and enabled the higher derivative option. Then, compute the gradient using automatic differentiation, before plotting it using the `quiver` function.
You may find the code in the attached live script file (.mlx file), for your reference.
References:
Hope this helps.

カテゴリ

Help Center および File Exchange向量场 についてさらに検索

Community Treasure Hunt

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

Start Hunting!