How to get Gradient from Network Created by Neural Network Toolbox?

조회 수: 8 (최근 30일)
Ahmed
Ahmed 2013년 6월 3일
댓글: Zheng Chai 2017년 12월 20일
How can the gradient of the performance function with respect to the weights and biases of a neural network created by the Neural Network Toolbox be obtained? I am looking for a function analogous to "getwb".
[x,t] = simplefit_dataset;
net = feedforwardnet(10);
net = train(net,x,t);
wb = getwb(net);
gwb = ????; % something analogous to getwb(net)
% resulting in a 31x1 vector
Thanks, Ahmed

채택된 답변

Ahmed
Ahmed 2013년 6월 6일
Actully, the function 'staticderivative' can do this for a static network. In general, however, it is likely that defaultderiv is the better choice.
help defaultderiv
help staticderiv

추가 답변 (1개)

Greg Heath
Greg Heath 2013년 6월 3일
[x,t] = simplefit_dataset;
net = fitnet; % No need for feedforwardnet
rng(0) % Convenient for duplicating the run
[ net tr ] = train(net,x,t);
wb = getwb(net);
tr = tr % No semicolon...Look at all of the goodies!
stopcrit = tr.stop
bestepoch = tr.best_epoch
gradient = tr.gradient; %complete history
Hope this helps
Thank you for formally accepting my answer
Greg ;
  댓글 수: 7
Greg Heath
Greg Heath 2017년 12월 19일
편집: Greg Heath 2017년 12월 19일
Sorry, Each year it seems that MATLAB modifies code, presumably to make it better in some esoteric way.
However an annoying result is that the code has become more and more difficult for the average user to understand.
Greg
PS Try contacting MATLAB directly.
Zheng Chai
Zheng Chai 2017년 12월 20일
Thank you so much Greg. Indeed Matlab modified its code. I could not find a proper helper function in my R2013b, but after updating it to R2017b, I found it. Thank you again for your kind help.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by