Do dlgradient and dlfeval have to be used together?

3 ビュー (過去 30 日間)
cui,xingxing
cui,xingxing 2020 年 1 月 6 日
コメント済み: hang Jiang 2021 年 9 月 29 日
Do dlgradient and dlfeval have to be used together?
function [y,dydx] = rosenbrock(x)
y = 100*(x(2) - x(1).^2).^2 + (1 - x(1)).^2;
dydx = dlgradient(y,x);
end
[y,dydx] = rosenbrock([1,2]),
get error??? Value to differentiate must be a traced dlarray scalar.
Can't it be as convenient as pytorch?”a traced dlarray scalar.“ not clear!!!

回答 (2 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 1 月 6 日
編集済み: KALYAN ACHARJYA 2020 年 1 月 6 日
x=[1,2];
[y,dydx]=rosenbrock(x);
  1 件のコメント
cui,xingxing
cui,xingxing 2020 年 1 月 7 日
Undefined function 'dlgradient' for input arguments of type 'double'.
should type "dlarray"

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


cui,xingxing
cui,xingxing 2020 年 1 月 7 日
編集済み: cui,xingxing 2020 年 1 月 7 日
but i input like this in command window , is OK ,why???
[fval,gradval] = dlfeval(@rosenbrock,dlarray([1,2]))
fval =
1×1 dlarray
100
gradval =
1×2 dlarray
-400 200
  1 件のコメント
hang Jiang
hang Jiang 2021 年 9 月 29 日
try:
x=dlarray(x);
dlarray(y)=100*(x(2)-x(1).^2).^2+(1-x(1)).^2;

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

カテゴリ

Help Center および File ExchangeCustom Training Loops についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by