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 CenterFile Exchange에서 Custom Training Loops에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by