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} = __setx (@var{net},@var{X2})
20 ## @code{__setx} sets the new weights to the neural network structure
25 ## Author: Michel D. Schmid
27 function net = __setx(net,xx)
29 ## check number of inputs
30 error(nargchk(2,2,nargin));
33 ## check "net", must be a net structure
34 if !__checknetstruct(net)
35 error("Structure doesn't seem to be a neural network")
39 [nRows, nColumns] = size(net.IW{1,1});
40 nElementsIW = nRows*nColumns;
41 net.IW{1,1}(:) = xx(1:nElementsIW);
43 [nRows, nColumns] = size(net.b{1,1});
44 nElementsB1 = nRows*nColumns;
45 net.b{1,1}(:) = xx(1+nElementsIW:nElementsIW+nElementsB1);
46 start = nElementsIW + nElementsB1;
49 nLayers = net.numLayers;
51 [nRows, nColumns] = size(net.LW{i,i-1});
52 nElementsLW = nRows*nColumns;
53 net.LW{i,i-1}(:) = xx(1+start:start+nElementsLW);
55 [nRows, nColumns] = size(net.b{i,1});
56 nElementsBx = nRows*nColumns;
57 net.b{i,1}(:) = xx(1+start+nElementsLW:start+nElementsLW+nElementsBx);
58 start = start + nElementsLW + nElementsBx;