Assume that I create two neural networks, each having the same structure (for example, one, 10 neuron hidden layer) and a dataset 'data.mat', which has the variables 'x' and 't' corresponding to 'features' and 'targets' respectively.
The only difference between the two networks is that the first network has explicitly specified number and size of inputs while the second network has not.
For a concrete example, consider the following MATLAB script:
% load data
load('data.mat');trainFcn = 'traincgf';n=10;% create and configure net1
net1 = fitnet(n,trainFcn);net1 = configure(net1,'output', t);% specify inputs and connections manually
net1.numInputs = 1;net1.inputs{1}.size = 20;net1.biasConnect =[ 1;1 ];net1.inputConnect = [1;0];net1.layerConnect = [0 0;1 0];net1.outputConnect = [0 1];% specify data split
net1.divideFcn = 'divideind';[trainInd,valInd,testInd] = divideint(50, 0.7, 0.15, 0.15);net1.divideParam.trainInd = trainInd;net1.divideParam.valInd = valInd;net1.divideParam.testInd = testInd;% train net1
[net1,tr1]= train(net1,x,t);%,'CheckpointFile','ProteomicYield1000.mat');
y1=net1(x);% create and configure net2
net2 = fitnet(n, trainFcn);net2 = configure(net2,'output',t);% Don't specify inputs or connections manually
% use the same data split as net1
net2.divideFcn = 'divideind';net2.divideParam.trainInd = trainInd;net2.divideParam.valInd = valInd;net2.divideParam.testInd = testInd;% train net2
[net2,tr2]= train(net2,x,t);y2=net2(x);
Here 'net1' and 'net2' are two identical shallow neural networks. In 'net1', I explicitly specify the number and size of inputs after configuring the network.
In 'net2', I do not specify the number and size of inputs and directly configure and train the network.
I am running the above code on the same data, ensuring that the training, validation and test sets are exactly the same for both of the networks.
Why do I get very different results for 'net1' and 'net2', and 'net2' always seems to be more accurate than 'net1'?
Best Answer