Hessian by DL toolbox

4 ビュー (過去 30 日間)
MAHSA YOUSEFI
MAHSA YOUSEFI 2021 年 9 月 27 日
回答済み: Anurag Ojha 2024 年 5 月 6 日
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 Center および File ExchangeCustom Training Loops についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by