Hessian by DL toolbox

6 次查看(过去 30 天)
MAHSA YOUSEFI
MAHSA YOUSEFI 2021-9-27
Hi there.
In my Matlab code, I am using customize training loop for my algorithm, so I am using forward and dlgradient to create my loss and gradient models, and then taking them by dlfeval.
I am going to ask you, is there any way to calculate the Hessian model of the objective function (in my case softmax cross entropy) in the training loop? Something similar dlgradent, lets say.
Thank you...
  3 个评论
MAHSA YOUSEFI
MAHSA YOUSEFI 2021-9-27
3.500,000 parameters totally and a dataset with 50,000 samples. For sure, yes! It would be a large matrix.
In my Algorithm, I have a subsampled Hessian (10,000 samples) multiply by a vectore.
MAHSA YOUSEFI
MAHSA YOUSEFI 2021-9-27
Actually, if I find the way of computing Hessian, I can take some strategies to solve this problem, storing issue. I am going to do computations layer by layer. In this case, the size of Hessian matrix, depends on only to the number of that specific layter. So it would noy be too large if it is considered per layer.

请先登录,再进行评论。

回答(1 个)

Anurag Ojha
Anurag Ojha 2024-5-6
Hello Mahsa
You can use hessian function to find hessian matrix.
hessian(f,v) finds the Hessian matrix of the symbolic scalar function f with respect to vector v in Cartesian coordinates.
If we do not specify v, then hessian(f) finds the Hessian matrix of the scalar function f with respect to a vector constructed from all symbolic variables found in f.
Adding a example below
syms x y z
f = x*y + 2*z*x;
hessian(f,[x,y,z])
ans = 
Adding the MATLAB documentation link so that you can dive deeper:

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by