Hessian by DL toolbox

4 views (last 30 days)
MAHSA YOUSEFI
MAHSA YOUSEFI on 27 Sep 2021
Answered: Anurag Ojha on 6 May 2024
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 Comments
MAHSA YOUSEFI
MAHSA YOUSEFI on 27 Sep 2021
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 on 27 Sep 2021
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.

Sign in to comment.

Answers (1)

Anurag Ojha
Anurag Ojha on 6 May 2024
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:

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!