iCub-main
saveNetwork.m
Go to the documentation of this file.
1 function saveNetwork(net)
2 % Save the file 'network.ini' containing the network 'net'
3 % in the proper format required by the ctrlLib framework.
4 %
5 % Copyright: (C) 2010 RobotCub Consortium
6 % Author: Ugo Pattacini
7 % CopyPolicy: Released under the terms of the GNU GPL v2.0.
8 
9 fid=fopen('network.ini','w');
10 
11 szIW=size(net.IW{1});
12 szLW=size(net.LW{2,1});
13 
14 fprintf(fid,'\n');
15 fprintf(fid,'numInputNodes\t\t%d\n',uint8(szIW(2)));
16 fprintf(fid,'numHiddenNodes\t\t%d\n',uint8(szIW(1)));
17 fprintf(fid,'numOutputNodes\t\t%d\n',uint8(szLW(1)));
18 fprintf(fid,'\n');
19 
20 fprintf(fid,'// hidden layer neurons\n');
21 for i=1:szIW(1)
22  fprintf(fid,'IW_%d\t\t( ',uint8(i-1));
23  for j=1:szIW(2)
24  fprintf(fid,'%.15f ',net.IW{1}(i,j));
25  end
26  fprintf(fid,')\n');
27 end
28 fprintf(fid,'\n');
29 
30 fprintf(fid,'// output layer neurons\n');
31 for i=1:szLW(1)
32  fprintf(fid,'LW_%d\t\t( ',uint8(i-1));
33  for j=1:szLW(2)
34  fprintf(fid,'%.15f ',net.LW{2,1}(i,j));
35  end
36  fprintf(fid,')\n');
37 end
38 fprintf(fid,'\n');
39 
40 fprintf(fid,'// bias hidden layer neurons\n');
41 fprintf(fid,'b1\t\t( ');
42 for i=1:length(net.b{1})
43  fprintf(fid,'%.15f ',net.b{1}(i));
44 end
45 fprintf(fid,')\n\n');
46 
47 fprintf(fid,'// bias output layer neurons\n');
48 fprintf(fid,'b2\t\t( ');
49 for i=1:length(net.b{2})
50  fprintf(fid,'%.15f ',net.b{2}(i));
51 end
52 fprintf(fid,')\n\n');
53 
54 fprintf(fid,'// input preprocessing\n');
55 params=net.inputs{1}.processSettings{end};
56 for i=1:szIW(2)
57  fprintf(fid,'inMinMaxX_%d\t\t( %.15f %.15f )\n',uint8(i-1),params.xmin(i),params.xmax(i));
58 end
59 for i=1:szIW(2)
60  fprintf(fid,'inMinMaxY_%d\t\t( %.15f %.15f )\n',uint8(i-1),params.ymin,params.ymax);
61 end
62 fprintf(fid,'\n');
63 
64 fprintf(fid,'// output postprocessing\n');
65 params=net.outputs{2}.processSettings{end};
66 for i=1:szLW(1)
67  fprintf(fid,'outMinMaxY_%d\t\t( %.15f %.15f )\n',uint8(i-1),params.ymin,params.ymax);
68 end
69 for i=1:szLW(1)
70  fprintf(fid,'outMinMaxX_%d\t\t( %.15f %.15f )\n',uint8(i-1),params.xmin(i),params.xmax(i));
71 end
72 fprintf(fid,'\n');
73 
74 fclose(fid);
75 
76 
77 
int n
FILE * file
Definition: main.cpp:81
fprintf(fid,'\n')
szLW
Definition: saveNetwork.m:12
function saveNetwork(net) % Save the file 'network.ini' containing the network 'net' % in the proper format required by the ctrlLib framework. % % Copyright szIW
Definition: saveNetwork.m:11
fclose(fileID)