data and nn input sizes do not match..

5 views (last 30 days)
SShamtej Singh Rana
SShamtej Singh Rana on 25 Jul 2019
Edited: TED MOSBY on 8 Jul 2025
my neural network is supposed to take an coloumn vector input [7x1] and output a value 1-3 that refers to a certain condition.
the way i have these set up is below, as well as a copy of the network code.
when i try to run this, i get an error "the numbers of input signals and networks inputs do not match"
this happens when i try to use net=configure(net, input), using my dataset.
im new to matlab so let me know if the mistake is just somewhere simple, ill have trouble finding it...
data= {temp;humid;SLP;precip;SWR;wind;dir};
%make a variable that treats all our coloumns as a matrix. i put this here
%and used it below to try and make the code work but it is making a 7 x 1
%cell instead of a 7x38000 matrix of all my input sets.
predictionNet=network;
predictionNet.name='PredictNet';
predictionNet.numInputs= 7;
predictionNet.numLayers= 5;
%first three lines are just initialization of the predictionNetwork.
predictionNet.biasConnect=[1;1;1;1;1];
%select which layers we want biases for
predictionNet.inputConnect=[1 1 1 1 1 1 0
0 0 0 0 0 0 1
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0];
%boolean matrix of T/F connections between inputs and weights
predictionNet.outputConnect=[0 0 0 0 1];
%select which layers will connect to the final output
predictionNet.layerConnect=[0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0];
%outlines which layer you want to feed into a current layer out of all
%layers
predictionNet.layers{1}.size=10;
predictionNet.layers{2}.size=20;
predictionNet.layers{3}.size=20;
predictionNet.layers{4}.size=15;
predictionNet.layers{5}.size=1;
%set number of neurons in each layer. the last layer has to be size 1 to
%get an indication of warning/fire/safe
predictionNet.layers{1}.transferFcn='tansig';
predictionNet.layers{1}.initFcn='initnw';
predictionNet.layers{2}.transferFcn = 'logsig';
predictionNet.layers{2}.initFcn = 'initnw';
predictionNet.layers{3}.transferFcn = 'logsig';
predictionNet.layers{3}.initFcn = 'initnw';
predictionNet.layers{4}.transferFcn = 'logsig';
predictionNet.layers{4}.initFcn = 'initnw';
predictionNet.layers{5}.transferFcn = 'logsig';
predictionNet.layers{5}.initFcn = 'initnw';
%set the transfer function and the initial functions.
%i chose tansig for the first so everything is centered around a mean, and
%then I chose logsig so everything is more probabalistic.
predictionNet.initFcn= 'initlay';
predictionNet.trainFcn='trainlm';
predictionNet.divideFcn='dividerand';
%divides training data randomly
predictionNet.plotFcns={'plotperform','plottrainstate'};
%choosing which plots i want when the data is read.
predictionNet= train(predictionNet, data, output);
view(predictionNet);

Answers (1)

TED MOSBY
TED MOSBY on 8 Jul 2025
Edited: TED MOSBY on 8 Jul 2025
Hi,
The error occured because you created a network with 7 separate input ports (predictionNet.numInputs = 7;). With seven input ports MATLAB expects 7 × Q cells (Q samples). A single column looked like “one time-step” rather than “Q samples”. So instead of this you can collapse it to one input port and tell the net that it has one input of size 7.
Additonally instead of the manual work, you can use the straightforward pattern-recognition net that handles all the bookkeeping automatically.
patternnet internally creates correct inputConnect, layerConnect, biases, transfer functions, and data splits. patternnet trains a soft-max output and needs targets sized nClasses × Q.
Below is an example to implement it:
temp = 20 + 10*rand(1,Q);
humid = 40 + 20*rand(1,Q);
SLP = 1005 + 10*rand(1,Q);
precip = max(0, randn(1,Q));
SWR = 200 + 50*randn(1,Q);
wind = 3 + 2*randn(1,Q);
dir = 360*rand(1,Q);
labels = randi(3,1,Q);
X = [temp; humid; SLP; precip; SWR; wind; dir];
T = ind2vec(labels(:)');
hiddenSizes = [10 20 20 15];
net = patternnet(hiddenSizes,'trainlm');
net = configure(net, X, T);
[net,tr] = train(net, X, T);
Y = net(X);
predCls = vec2ind(Y);
accTrain = mean(predCls == labels)*100;
Here is more information on "patternnet":
Hope this helps!

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!