Using If statement to train Neural Network
Show older comments
Good day, Is it possible to use if statement to train a neural network ? I have specific set of inputs that correspond with specific set of outputs with different sizes. For example, the 3 set of inputs are a 24x2 matrix each corresponding with 3 sets of output 5x2,7x2 and 9x2 respectively.
After training, the simulation only gives me back for 5 outputs with very bad results. But I need it give me back for 5, 7 and 9.
I don't know if it's my input argument (eg. ' if network2.layers{2}.size == 7 & network2.inputs{1}.exampleInput==i2') that's the issue or I'm going about it the wrong way. Please I need help.
Thank you for any input response.
Below is the code written. CODE network2=network(1,2,[1;1],[1;0],[0 0;1 0],[0 1]); network2.inputs{1}.size=24; network2.inputs{1}.processFcns = {'removeconstantrows','mapminmax'}; network2.layers{1}.size = 30; network2.layers{1}.transferFcn='tansig'; network2.layers{1}.initFcn = 'initnw'; network2.layers{2}.size = 5; network2.layers{2}.transferFcn='purelin'; network2.layers{2}.initFcn = 'initnw'; network2.inputs{1}.exampleInput=i1; network2.initFcn = 'initlay'; network2.performFcn = 'mse'; network2.trainFcn = 'trainlm'; network2.divideFcn = 'dividerand'; network2.plotFcns = {'plotperform','plottrainstate','plotregression'}; network2.trainParam.epochs=10000; network2.trainParam.goal=0; network2.trainParam.min_grad=1e-7; if network2.layers{2}.size == 5 & network2.inputs{1}.exampleInput==i1 train(network2,i1,o1); else if network2.layers{2}.size == 7 & network2.inputs{1}.exampleInput==i2 train(network2,i2,o2); else train(network2,i3,o3); end end DATASET i1=[281.907400000000,1198.04650000000;284.647200000000,1201.21840000000;236.376200000000,1191.29540000000;183.152000000000,1174.05820000000;135.078500000000,1144.08000000000;95.9512000000000,1086.29350000000;72.3133000000000,983.455900000000;61.6324000000000,793.240500000000;62.4501000000000,562.124400000000;69.2182000000000,352.981300000000;85.8570000000000,172.069000000000;109.075800000000,110.127400000000;140.669700000000,103.392200000000;178.568700000000,118.533800000000;224.686200000000,140.450000000000;289.353400000000,166.471100000000;361.089100000000,191.471700000000;436.180400000000,213.347100000000;540.414000000000,237.769600000000;639.630600000000,255.883300000000;740.965800000000,270.163300000000;833.914200000000,280.210200000000;918.818500000000,287.279300000000;1002.77820000000,292.616800000000] i2=[20.0326000000000,59.6496000000000;19.9899000000000,60.0313000000000;20.1479000000000,58.4751000000000;20.4259000000000,55.9220000000000;20.9007000000000,51.9693000000000;21.7638000000000,45.7339000000000;23.1983000000000,37.2975000000000;25.5834000000000,26.7863000000000;28.2221000000000,19.1738000000000;30.5521000000000,15.5267000000000;33.2405000000000,14.9470000000000;36.3009000000000,17.0807000000000;41.6112000000000,20.9500000000000;50.3339000000000,26.1645000000000;63.3688000000000,33.1481000000000;84.3511000000000,43.9976000000000;110.013400000000,57.3753000000000;139.548200000000,72.8986000000000;185.873800000000,97.4243000000000;237.205600000000,124.815400000000;299.394400000000,158.303300000000;368.616500000000,195.977800000000;446.956500000000,239.142900000000;547.245400000000,295.276400000000] i3=[10.2122000000000,89.8217000000000;10.1287000000000,90.6532000000000;10.9130000000000,106.931400000000;12.1459000000000,130.142200000000;13.8731000000000,158.514900000000;16.3103000000000,193.140200000000;19.4212000000000,232.965300000000;23.6388000000000,281.420900000000;28.0371000000000,325.456600000000;32.3947000000000,360.688000000000;38.2749000000000,393.106300000000;43.9239000000000,410.107900000000;49.8511000000000,420.214700000000;55.3723000000000,432.560300000000;60.4935000000000,461.510300000000;66.5390000000000,532.130800000000;74.1069000000000,643.727300000000;84.8775000000000,781.726000000000;104.945700000000,992.866000000000;128.719100000000,1209.10510000000;156.821300000000,1446.89610000000;186.298700000000,1683.43430000000;217.292600000000,1919.24040000000;253.457200000000,2177.39820000000] o1=[300,1200;50,50;1200,300;1.30000000000000,5;10,12] o2=[20,60;60,10;22,40;1200,700;4.10000000000000,3;3.60000000000000,10.8000000000000;12.5000000000000,19.5000000000000] o3=[10,84;50,730;100,400;20,280;400,3000;2,1.40000000000000;11,4;20,15;15,20]
2 Comments
Muhammad Abdurrehman
on 12 Mar 2017
You should edit your question. Select code and press {}code to enhance readability.
Greg Heath
on 12 Mar 2017
5 + 7 + 9 ~= 24 ???
[ I N ] = size(input) = [ ? ? ]
[ O N ] = size(target) = [ ? ? ]
Greg
Answers (0)
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!