MATLAB: Net reusing

Deep Learning Toolboxneural network

Hi, I'm creating a set of nets using a code more or less like this:
net = patternnet(10);
% net initialization
% ...
for ii=1:10
net = train(net,in,tar);
netSet{ii} = net;
end
What I see is the first training takes relatively a lot of time, while the others usually are far faster. So a question comes to my mind: could be each new training starts from the previous net? If so, is there a function to re-randomize the initial weights (without the need to allocate a new net)?

Best Answer

Inside your loop, the input to train() is definitely the value of "net" that just calculated in the previous. I am guessing you want to do something like this instead:
net0 = patternnet(10);
% net0 initialization
% ...
for ii=1:10
net = train(net0,in,tar);
netSet{ii} = net;
end
This way, you are starting from the initialized value "net0" each time. I don't know enough about neural nets to know if train() has some randomness in it that will make each value of netSet(ii) different.
Also, note that you do not really need the intermediate value "net" inside your loop. You could just do
for ii=1:10
netSet{ii} = train(net0,in,tar);
end