1 ## Copyright (C) 2005 Michel D. Schmid <michaelschmid@users.sourceforge.net>
4 ## This program is free software; you can redistribute it and/or modify it
5 ## under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 2, or (at your option)
9 ## This program is distributed in the hope that it will be useful, but
10 ## WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ## General Public License for more details.
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program; see the file COPYING. If not, see
16 ## <http://www.gnu.org/licenses/>.
19 ## @deftypefn {Function File} {}{@var{net}} = __newnetwork(@var{numInputs},@var{numLayers},@var{numOutputs},@var{networkType})
20 ## @code{__newnetwork} create a custom 'zero'-network
24 ## net = __newnetwork(numInputs,numLayers,numOutputs,networkType)
26 ## numInputs : number of input vectors, actually only 1 allowed
27 ## numLayers : number of layers
28 ## numOutputs: number of output vectors, actually only 1 allowed
29 ## networkType: e.g. feed-forward-network "newff"
33 ## net = __newnetwork(1,2,1,"newff")
34 ## 1 input layer, two hidden layers, one output layer
35 ## and the network type
41 ## Author: Michel D. Schmid
43 function net = __newnetwork(numInputs,numLayers,numOutputs,networkType)
45 ## check range of input arguments
46 error(nargchk(4,4,nargin))
49 if ( !isposint(numInputs) )
50 error("network: at least 1 input must be defined! ")
51 # this can't happen actually, only one is allowed and this
53 elseif ( !isposint(numLayers) )
54 error("network: at least 1 hidden- and one output layer must be defined! ")
56 ## second check for numLayers... must be at least "2" for the
57 ## newff, this means at least 1 hidden and 1 output layer
58 if (strcmp(networkType,"newff") && (numLayers<2))
59 error("network: not enough layers are defined! ")
62 ## define network type
63 net.networkType = networkType;
68 net.numInputDelays = 0;
69 net.numLayerDelays = 0;
70 # the next five parameters aren't used till now, they are used
71 # only for matlab nnet type compatibility ==> saveMLPStruct
72 net.biasConnect = []; # not used parameter till now
73 net.inputConnect = []; # not used parameter till now
74 net.layerConnect = []; # not used parameter till now
75 net.outputConnect = []; # not used parameter till now
76 net.targetConnect = []; # not used parameter till now
79 net.inputs = cell(0,1);
80 net.layers = cell(0,1);
81 net.biases = cell(0,1);
82 net.inputWeights = cell(0,0);
83 net.layerWeights = cell(0,0);
84 net.outputs = cell(1,0);
85 net.targets = cell(1,0);
87 net.performParam = [];
93 net.userdata.note = "Put your custom network information here.";
98 ## define everything with "inputs"
99 net.numInputs = numInputs;
100 ## actually, it's only possible to have "one" input vector
101 net.inputs{1,1}.range = [0 0];
102 net.inputs{1,1}.size = 0;
103 net.inputs{1,1}.userdata = "Put your custom informations here!";
105 ## define everything with "layers"
106 net.numLayers = numLayers;
107 net = newLayers(net,numLayers);
109 ## define unused variables, must be defined for saveMLPStruct
110 net.biasConnect = [0; 0];
111 net.inputConnect = [0; 0];
112 net.layerConnect = [0 0; 0 0];
113 net.outputConnect = [0 0];
114 net.targetConnect = [0 0];
115 net.numInputDelays = 0;
116 net.numLayerDelays = 0;
118 ## define everything with "outputs"
119 net.numOutputs = numOutputs;
120 net.outputs = cell(1,numLayers);
123 net.outputs{i}.size = 1; # nothing else allowed till now
124 net.outputs{i}.userdata = "Put your custom informations here!";
130 ## define everything with "biases"
131 net = newBiases(net,numLayers);
135 #=====================================================
137 # Additional ARCHITECTURE Functions
139 #=====================================================
140 function net = newLayers(net,numLayers)
142 ## check range of input arguments
143 error(nargchk(2,2,nargin))
145 ## check type of arguments
146 if ( !isscalar(numLayers) || !isposint(numLayers) )
147 error("second argument must be a positive integer scalar value!")
149 if ( !__checknetstruct(net) )
150 error("first argument must be a network structure!")
153 for iRuns=1:numLayers
154 net.layers{iRuns,1}.dimension = 0;
155 net.layers{iRuns,1}.netInputFcn = "";
156 net.layers{iRuns,1}.size = 0;
157 ### TODO: test with newff net.layers{iRuns,1}.transferFcn = "tansig";
158 net.layers{iRuns,1}.transferFcn = "";
159 net.layers{iRuns,1}.userdata = "Put your custom informations here!";
164 #-----------------------------------------------------
166 function net = newBiases(net,numLayers)
168 ## check range of input arguments
169 error(nargchk(2,2,nargin))
171 ## check type of arguments
172 if ( !isscalar(numLayers) || !isposint(numLayers) )
173 error("second argument must be a positive integer scalar value!")
175 if ( !isstruct(net) )
176 error("first argument must be a network structure!")
179 for iRuns=1:numLayers
180 net.biases{iRuns,1}.learn = 1;
181 net.biases{iRuns,1}.learnFcn = "";
182 net.biases{iRuns,1}.learnParam = "undefined...";
183 net.biases{iRuns,1}.size = 0;
184 net.biases{iRuns,1}.userdata = "Put your custom informations here!";
189 # ================================================================
191 # END Additional ARCHITECTURE Functions
193 # ================================================================