Do dlgradient and dlfeval have to be used together?

1 visualización (últimos 30 días)
cui,xingxing
cui,xingxing el 6 de En. de 2020
Comentada: hang Jiang el 29 de Sept. de 2021
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!!!

Respuestas (2)

KALYAN ACHARJYA
KALYAN ACHARJYA el 6 de En. de 2020
Editada: KALYAN ACHARJYA el 6 de En. de 2020
x=[1,2];
[y,dydx]=rosenbrock(x);
  1 comentario
cui,xingxing
cui,xingxing el 7 de En. de 2020
Undefined function 'dlgradient' for input arguments of type 'double'.
should type "dlarray"

Iniciar sesión para comentar.


cui,xingxing
cui,xingxing el 7 de En. de 2020
Editada: cui,xingxing el 7 de En. de 2020
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 comentario
hang Jiang
hang Jiang el 29 de Sept. de 2021
try:
x=dlarray(x);
dlarray(y)=100*(x(2)-x(1).^2).^2+(1-x(1)).^2;

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by