In neural network toolbox, do train() and traingdx() call each other?

2 views (last 30 days)
I am using the R2018a Neural Network Toolbox, and I was reading the function descriptions. I am trying to understand how the training works for a specific reason in my research.
As I was reading the train() function description, (located in C:\Program Files\MATLAB\R2018a\toolbox\nnet\nnet\@network\train.m), I saw this line of code:
function [net,tr,out3,out4,out5,out6]=train(net,varargin)
[net,tr] = feval(trainFcn,'apply',net,data,calcLib,calcNet,tr);
As far as I understand, this line calls the function that is specified as trainFcn, which, in my case, is 'traingdx'. When I opened the script for traingdx (located in C:\Program Files\MATLAB\R2018a\toolbox\nnet\nnet\nntrain\traingdx.m), I encountered the following line of code:
function [out1,out2] = traingdx(varargin)
[out1,out2] = train(net,varargin{2:end});
From this, it seems to me that both functions call each other, which did not make any sense to me.
Could anybody explain to me this situation?
(For those who may wonder, my actual purpose is to be able to have an 'independent' layer at the end of the network, the weights of which I plan to update according to a specified function. I know that this may be contrary to the general intuition behind deep learning, and therefore the network might not converge to a desired value, but I was wondering if there is any way I can update the weights of a specific layer after each iteration of training.)
Thanks very much in advance.

Answers (1)

Sai Bhargav Avula
Sai Bhargav Avula on 23 Mar 2020
I would like to recommed you to use break points with an example to understand the flow after this explaination as it can clear many things.
Use the any example in the given link:
First for example lets consider the feedforward function for creating the network. The traingdx and trainlm are the back propogation function methods. These are called while creating the network if trainFcn is not passed as the argument. These intern call the train function only in the case it needs to train(calculation mode). The train function calls the feval in the case when it needs info or other or to initilize the params and trainFcn.
Hope this didn't confuse you !


Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!