From: Aitor Azcarate on 3 May 2010 08:51 I am a new to neural nets. I have some data and targets with which I have learned some neural nets, like this: stage1Net = create_pr_net(s1,tar1); outputs1 = sim(stage1Net,s1); function create_pr_net(inputs,targets) numHiddenNeurons = 20; % Adjust as desired net = newpr(inputs,targets,numHiddenNeurons); net.divideParam.trainRatio = 60/100; % Adjust as desired net.divideParam.valRatio = 20/100; % Adjust as desired net.divideParam.testRatio = 20/100; % Adjust as desired % Train and Apply Network [net,tr] = train(net,inputs,targets); When the outputs are well enough for me I have written the weight and biases to a file: fprintf(fid,'%f ',stage1Net.IW{1}); fprintf(fid,'\n'); fprintf(fid,'%f ',stage1Net.IW{2}); fprintf(fid,'\n'); fprintf(fid,'%f ',stage1Net.LW{1}); fprintf(fid,'\n'); fprintf(fid,'%f ',stage1Net.LW{2}); fprintf(fid,'\n'); fprintf(fid,'%f ',stage1Net.LW{3}); fprintf(fid,'\n'); fprintf(fid,'%f ',stage1Net.LW{4}); fprintf(fid,'\n'); fprintf(fid,'%f ',stage1Net.b{1}); fprintf(fid,'\n'); fprintf(fid,'%f ',stage1Net.b{2}); fprintf(fid,'\n'); Now I want to use this neural net (for which I have written the weights and biases to file) again to classify some new data. Can I get the neural net by doing this?: numHiddenNeurons = 20; % Adjust as desired stage1NN = newpr(s1,tar1,numHiddenNeurons); stage1NN.divideParam.trainRatio = 60/100; % Adjust as desired stage1NN.divideParam.valRatio = 20/100; % Adjust as desired stage1NN.divideParam.testRatio = 20/100; stage1NN = init(stage1NN); a = [-1.027574 1.299970 -0.155901 -0.361756 -0.194674 0.129434 -0.978455 1.244117 1.022117 0.446432 -1.249563 -0.120601 -1.387035 -0.118050 1.120289 -0.134009 -1.254433 -1.053414 1.220733 -0.945070 -1.030993 -0.959083 0.786927 -0.826084 1.161268 -0.739598 1.205290 1.526128 -1.093754 -1.414622 -1.103992 1.401535 -0.333518 0.990345 0.612091 -0.940715 -0.727251 1.478113 1.189388 0.337921 -0.364311 0.276533 -0.079478 0.280825 -0.978948 -1.319882 -1.337934 0.233793 0.140455 1.049921 -0.577287 1.808920 -0.667076 -0.128279 -1.105200 1.629127 0.291449 0.169764 -0.650200 0.608210 -0.169891 1.598755 -0.564480 -1.264748 1.308707 -0.458410 -0.571623 -0.839012 -1.066973 0.290596 -1.003593 -0.178867 1.417486 1.531266 -1.019029 -0.878843 0.957516 0.934152 -0.485380 -1.266497 -1.105566 -0.075205 -2.077308 0.467661 -0.254943 -1.416405 -0.883727 -0.405509 -0.298345 0.211971 -0.875966 -0.103508 0.717743 -1.166459 -0.643309 -0.148595 1.338379 0.657805 -1.090044 0.761788 1.348162 0.268987 0.191144 1.615493 1.094426 -0.893346 -0.111200 0.721337 1.353539 1.374078 0.657478 0.162828 -0.561913 0.776970 -1.008375 0.984305 0.651710 0.831619 -0.754239 1.326143]; stage1NN.IW{1} = reshape(a,20,6); a = [0.148719 0.441608 -0.020489 -0.397135 0.046821 -0.052416 0.123279 -0.565742 0.236745 -0.286982 -0.516495 0.215501 -0.600813 0.165845 0.145545 0.486871 0.416301 0.525577 0.155127 0.368187 -0.554779 0.488346 -0.232253 -0.396462 0.490558 -0.347078 0.373806 -0.574523 0.398095 -0.007985 -0.423943 0.503573 -0.377779 0.072202 -0.098969 -0.417778 -0.634351 -0.056821 0.201195 0.484960 -0.422641 0.488628 0.445360 -0.279992 0.576967 -0.705216 -0.550070 -0.585503 0.576996 0.502500 -0.207105 -0.450744 0.337802 0.123367 -0.368625 0.059287 -0.368247 0.269553 -0.219582 0.418023 -0.602221 0.184102 -0.311837 0.049497 -0.221010 0.007665 -0.510147 -0.106787 0.426972 0.104632 0.102174 -0.502476 -0.355411 0.245520 0.199564 0.445231 -0.179313 0.312466 0.378452 -0.144276 0.332482 -0.432228 0.043458 -0.274456 -0.116035 -0.491948 -0.453086 0.499090 -0.325626 -0.257771 0.152589 -0.179846 0.204703 0.427190 -0.339011 0.006862 0.122504 0.331211 -0.397029 0.139939 0.305149 0.445464 -0.206180 0.193496 0.020103 0.402666 -0.126419 -0.489736 -0.223871 0.431888 0.252712 -0.364021 0.366342 -0.143054 0.142306 -0.286945 -0.435387 0.484643 -0.229062 0.125160 -0.115654 0.272286 0.045413 -0.086129 -0.538473 -0.371947 0.414374 0.084278 0.291219 -0.406593 0.449753 0.406068 0.105281 0.087225 -0.400952 -0.025432 0.505265 -0.129978 -0.351926 -0.392711 -0.054844 0.450486 0.515457 0.439596 -0.123690 0.480848 -0.140099 0.291361 0.021588 0.499421 -0.516295 0.404636 -0.483605 -0.381392 0.163510 0.205742 0.249904 0.402077 -0.566712 -0.279718 -0.187016 -0.298743 -0.389370 -0.027522 -0.055849 0.536609 -0.239003 0.340510 0.567870 -0.006923 0.036879 -0.366187 0.303765 -0.481021 -0.236027 -0.298377 -0.631308 -0.562297 0.457835 0.534939 -0.326643 -0.442802 -0.455825 -0.126440 0.464025 -0.269258 -0.242933 0.125424 -0.342750 -0.418667 0.125905 -0.101165 0.087244 -0.189791 -0.530146 -0.448756 0.236989 -0.062929 0.238973 -0.249132 -0.285056 0.197661 0.395109 0.522933 0.399574 -0.200793 0.167044 -0.088734 -0.435359 -0.644283 -0.261479 -0.264166 -0.214630 -0.481273 -0.252829 0.328741 0.564598 -0.125145 0.417006 -0.263310 ]; stage1NN.LW{2} = reshape(a,11,20); stage1NN.b{1} = [2.306569 -2.063772 1.820975 1.578178 1.335382 -1.092585 0.849788 -0.606992 -0.364195 -0.121398 -0.121398 -0.364195 -0.606992 -0.849788 1.092585 -1.335382 -1.578178 -1.820975 2.063772 -2.306569]'; stage1NN.b{2} = [-1.578329 -1.262664 0.946998 0.631332 -0.315666 0.000000 0.315666 -0.631332 0.946998 -1.262664 -1.578329]'; These numbers are the weights and biases that are written to file. So basically my question is: How to get a neural net that was previously trained and 'saved' to classify new data?
From: Steven Lord on 3 May 2010 09:19 "Aitor Azcarate" <fclisse8(a)yahoo.com> wrote in message news:hrmgrt$30f$1(a)fred.mathworks.com... >I am a new to neural nets. I have some data and targets with which I have >learned some neural nets, like this: > stage1Net = create_pr_net(s1,tar1); > outputs1 = sim(stage1Net,s1); > > function create_pr_net(inputs,targets) > numHiddenNeurons = 20; % Adjust as desired > net = newpr(inputs,targets,numHiddenNeurons); > net.divideParam.trainRatio = 60/100; % Adjust as desired > net.divideParam.valRatio = 20/100; % Adjust as desired > net.divideParam.testRatio = 20/100; % Adjust as desired > % Train and Apply Network > [net,tr] = train(net,inputs,targets); > > When the outputs are well enough for me I have written the weight and > biases to a file: > fprintf(fid,'%f ',stage1Net.IW{1}); Note that this will not write the exact value of state1.Net.IW{1} to the file: >> format long g >> x = pi x = 3.14159265358979 >> fprintf('%f\n', x) 3.141593 *snip* > These numbers are the weights and biases that are written to file. > So basically my question is: How to get a neural net that was previously > trained and 'saved' to classify new data? SAVE it to a MAT-file, then LOAD it from the file and use SIM to process new data using the loaded network. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Aitor Azcarate on 3 May 2010 09:29 Thanks for the quick response Steve!! You are right with the respect to the precision. Didn't even think about it!!! I will try to save to and load from a mat file.
|
Pages: 1 Prev: Case sensitivity Next: help for the peak sidelobe ratio (PSLR) in the radar system |