The weights for the first network, 'net1', are not getting initialized properly. Specifically, 'net1' has two sets of weights, stored in variables 'IW' [input weights] and 'LW' [layer weights]. When you call the 'configure' function as follows:
net1 = configure(net1, 'output', t);
the layer weights in 'LW' get initialized because the network has enough information to know the size of these weights. However, the input weights in 'IW' do not get initialized because MATLAB doesn't know the input size yet. This is expected behavior.
Subsequently, when you set the size of the inputs, as follows:
net1.inputs{1}.size = 240;
MATLAB now has enough information to initialize the input weights 'IW'. However, the network does not have any input data available, so 'IW' is initialized to 'zeros' by default.
Initializing the weight matrix of the neural network to zeros is the root cause behind the poor accuracy of the network in the first script.
The are two ways to fix this issue:
1) You can re-configure the network using the inputs before training, as follows:
net1 = configure(net1, x, t);
This will initialize the input weights correctly.
2) Alternatively, you can delete the following line:
net1.inputs{1}.size = 240;
This will leave the input weights 'IW' un-initialized and calling the 'train' function will initialize 'IW' to appropriate values.
Now, 'net1' and 'net2' should perform similarly as both of them have been assigned similar initial weights.
Best Answer