MATLAB NN toolbox does not give the expected weights and bias amount after trained the network

1 view (last 30 days)
I had 192 inputs with 48 outputs to train my network. To give a clear idea about the problem I have given the code with only four inputs and two outputs for an example.
When I try to train the network with only one element for each input and output, and three hidden neurons, network does not train. Even when I try to read the weight and bias (getwb(net)) of the trained network, it gives 3 zeros (3 is vary with the number of neurons, when it has 10 hidden neurons, getwb(net) gives 10 zeros) even though it should be equal to 23 weights and bias ((I+1)*H+(H+1)*O).
Most importantly, when I test the trained network, it gives my training target as the output with any testing input. But it shows the correct amount of weights and bias when I have more than one element for each input and target. But testing output is almost same with the last target set.
How can this happen? why it shows me only 3 weight, bias values (those are also zeros), at least where is my initial weights and bias? why it is equal to last target set when I have several elements for training inputs and targets. One thing I noticed "view(net)" shows I have 0 output layers (network diagram has been attached with this)
i = [1,2,3,4]; % 4 inputs with one element each
t = [1,2]; % 2 targets with one element each
net = feedforwardnet([3], 'trainlm'); %feedforward network with 3 hidden neurons net.layers{1}.transferFcn = 'tansig';
net.performFcn = 'mse'; net.trainParam.epochs = 100;
net.divideFcn = '';
[net, tr] = train(net, i', t'); %train the network
ut = sim(net, [[1,3,3,4]]') %testing the output
  1 Comment
Javier  Conte
Javier Conte on 29 Nov 2018
Hello,
try to use the "tonndata" function to transform your matrix data in to a cell format.
%% Example
... omitted steps ( Network definition and train)
... after training use the net to estimate/predict the output with new data
xx = tonndata(input_matrix_data,true,false); % help tonndata
output = net(xx);
%% end example
I hope I can help you
best regards
J. Conte

Sign in to comment.

Answers (1)

Greg Heath
Greg Heath on 29 Nov 2018
Edited: Greg Heath on 29 Nov 2018
  1. Use the special cases of feedforwardnet
a. fitnet for curvefitting and regression
b. patternnet for classification and pattern recognition
2. The smartest approach is to begin by modifying the help and doc examples:
help fitnet
doc fitnet
3. [x,t] = simplefit_dataset;
net = fitnet(10);
net = train(net,x,t);
view(net)
y = net(x);
%perf = perform(net,t,y) ... UGH!!!
NMSE = mse(t-y) / var(t,1) % Normalized MSE
RSQUARE = 1- NMSE % See Encyclopedia or Elementary Statistics references
Hope this helps
Thank you for formally accepting my answer
Greg
  1 Comment
Greg Heath
Greg Heath on 29 Nov 2018
Note: The above expression for the reference mean-square-error, MSEref, is obtained from the simplest guess at an answer:
referenceoutput = mean(t)
MSEref = mean( ( t- mean(t) ).^2 )
= var(t,1)
Hope this is helpful
Greg

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!