How can I use Neural Networks to create several networks instead of creating one by one manually?

2 views (last 30 days)
I would like to create several neural networks models and estimations using for each one of them 2 variables as inputs and 1 variable as output. For a single stock I would use the NNtool to first construct the model and then do the estimation. What I would like to know is how could I do this for all the stocks (30 stocks and for each one of them I would like to create a nn estimation) in an automatic way without having to run the wizard for each one of them.
Thanks you for your support,
Best regards,

Accepted Answer

Greg Heath
Greg Heath on 28 Apr 2014
You can do it with nested for loops. Indexed nets should be stored in cells. However, it is not clear what the difference in inputs is for the 30 stocks. Also, what are the outputs? I assume this is regression and not classification. Therefore you should use the FITNET version of feedforwardnet (NEWFIT version of newff if you are using the obsolete version).
A single hidden layer is sufficient. Accept all defaults except the number of hidden nodes, H=10; Try to use the smallest value of H that yields acceptable results.
Also, you have to take into account that some designs will be bad because of an unfortunate assignment of random initial weights. Therefore, for each case, multiple random initial weight designs will have to be made to obtain an acceptable one.
I typically look at Ntrials = 10 random initialization designs for each of ~10 candidate values for H. Search using
greg fitnet Ntrials
Hope this helps.
Thank you for formally accepting my answer

Sign in to comment.

More Answers (1)

Apdullah YAYIK
Apdullah YAYIK on 27 Apr 2014
Of course you can create several neural networks and control their variables (transfer functions, hidden layers, neuron numbers of training algorithms)for your estimation or classification problems. For example ---First ANN--- nn=10;mm=10;pp=10; %%Neuron Numbers net1=newfit(minmax(target{1,1}),[nn,mm,pp,1],{'radbas','purelin','radbas','purelin','radbas'},'trainbr'); net1.trainparam.min_grad=0; net1.trainparam.mu_max=1.e+10; net1.trainParam.epochs=20; net1=train(net1,target{1,1},acik_bin_reshaped{1,1}); ---Second ANN--- net2=newfit(minmax(target{1,2}),[nn,mm,pp,1],{'radbas','purelin','radbas','purelin','radbas'},'traingda'); net2.trainparam.min_grad=0; net2.trainparam.mu_max=1.e+10; net2.trainParam.epochs=20; net2=train(net2,target{1,2},acik_bin_reshaped{1,2}); ---Third ANN--- %%%%%%%%%%%%%%%%%%%%%3.Boyut NN%%%%%%%%%%%%%%%%%%%%% net3=newfit(minmax(target{1,3}),[nn,mm,pp,1],{'radbas','purelin','radbas','purelin','radbas'},'traingda'); net3.trainparam.min_grad=0; net3.trainparam.mu_max=1.e+10; net3.trainParam.epochs=20; net3=train(net3,target{1,3},acik_bin_reshaped{1,3});
Then, you can simulate each of them independently.
output1=sim(net1,target{1,1}); output2=sim(net2,target{1,2}); output3=sim(net3,target{1,3});
  1 Comment
Sarah on 27 Apr 2014
Hey Apdullah,
Thank you for your quick response. However I did not totally understand how could I do it.
What does nn mm and pp mean? what is it like the target{1,1}, is it an array with the target values? What does the acik_bin_reshaped{1,2} mean? Can you better explain to me these variables?
Lets say that we have 30 stocks and we want to do a model for each one of them with two input variables and one output variable. Do I have do do write that code 30 times and refer to the different inputs and outputs or can I do it with a for or other cycle?
Thank you again for your time!

Sign in to comment.


Find more on Deep Learning with Time Series and Sequence Data in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by