Where is the problem in my neural network script? I cannot update the weights and biases after training.

I am trying to design a custom neural network model to solve a problem. Here is the script:
net= network;
net.numInputs = 1;
net.inputs{1}.size = 1;
net.numLayers = 2;
net.layers{1}.size = 5;
net.layers{2}.size = 1;
net.inputConnect(1,1) = 1;
net.inputConnect(2,1) = 0;
net.biasConnect(1) = 1;
net.biasConnect(2) = 0;
net.layerConnect(2,1) = 1;
net.layers{1}.transferFcn = 'logsig';
net.layers{2}.transferFcn = 'purelin';
net.inputWeights{1,1}.initFcn = 'initzero';
net.inputWeights{1,1}.learn = 1;
net.inputWeights{1,1}.learnFcn = 'learngd';
net.layerWeights{2,1}.initFcn = 'initzero';
net.layerWeights{2,1}.learn = 1;
net.layerWeights{2,1}.learnFcn = 'learngd';
net.biases{1}.initFcn = 'initzero';
net.biases{1}.learn = 1;
net.biases{1}.learnFcn = 'learngd';
net.outputConnect = [0 1];
net.initFcn = 'initlay';
net.trainFcn = 'traingd';
net.performFcn = 'sse';
And here is the the diagram for the neural network:
Before I trained the network, I typed
net.IW{1}; net.b{1}; net.LW{2,1}
in the command window and checked that the values were all initially zero. However, when I trained the network, say
train(net, 0.1, 1)
Even though there was a pop-up window showing the process,
it seemed that the weights and biases did not update as I typed net.IW{1}, net.b{1} and net.LW{2,1}. Also, the output was always zero, no matter what value I input using
sim()
Could anyone help me to indicate the problem in the script or the procedure in training? Thank you.

 Accepted Answer

train(net, 0.1, 1)
You cannot train with a single point. You need input and target row vectors or matrices.

3 Comments

Hi Greg,
Thanks for your answer and suggestion. So I have two additional questions. First, when I use simplefit_dataset as inputs and targets in the MATLAB examples and making up the same structure, the weights can be updated. But this is not the case while using my script.
And also, I am also curious why single points cannot be used in training in my case. I have tried that using a single point would work if I omit the second linear layer.
Could you explain why those things happen? Thank you.
For designing an I-H-O net with Ntrn input/target pairs
you have
Nw = (I+1)*H+(H+1)*O unknown weights and biases to
be estimated with
Ntrneq = Ntrn*O training equations
A necessary condition for a STABLE minimum MSE solution is that the number of unknowns do not exceed the number of equations
Ntrn >= 1 + (I+O+1)*H/O
PS: Replace logsig with tansig and center your inputs. I like standardization with zero-mean/unit-variance inputs. Then you can check for outliers before training. However, the MATLAB default just transforms INPUTS AND TARGETS to [ -1 1 ]
Hope this helps.
Greg

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!