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} = __init (@var{net})
20 ## @code{__init} initializes a neural network. This will be done
21 ## with the function @code{rand} from octave.
27 ## This function takes the octave function "rand" to init the
28 ## neural network weights.
34 ## Author: Michel D. Schmid
36 function net=__init(net)
38 ## check number of inputs
39 error(nargchk(1,1,nargin));
42 if ( !__checknetstruct(net) )
43 error("__init: wrong argument type, must be a structure!");
47 if (strcmp(net.networkType,"newff"))
49 ## init with random numbers between +-1
51 mRand = rand(net.layers{1}.size,net.inputs{1}.size);
52 net.IW{1} = mRand*2-1;
55 nLayers = net.numLayers;
57 mRand = rand(net.layers{i}.size,net.layers{i-1}.size);
58 net.LW{i,i-1} = mRand*2-1;
61 mRand = rand(net.biases{i}.size,1);
64 elseif (strcmp(net.networkType,"newp"))
67 inputRows = size(net.inputs{1,1}.range,1);
68 net.IW{1} = zeros(inputRows,1);
69 net.b{1} = zeros(1,1);
72 ## warn user of constant inputs
74 prange = net.inputs{i}.range;
75 if (any(prange(:,1) == prange(:,2)))
77 fprintf("** Warning in INIT\n")
78 fprintf("** Network net.inputs{%g}.range has a row with equal min and max values.\n",i)
79 fprintf("** Constant inputs do not provide useful information.\n")