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

1 view (last 30 days)
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

Greg Heath
Greg Heath on 3 Feb 2016
train(net, 0.1, 1)
You cannot train with a single point. You need input and target row vectors or matrices.
  3 Comments
Greg Heath
Greg Heath on 5 Feb 2016
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!