]> Creatis software - CreaPhase.git/blob - octave_packages/nnet-0.1.13/__setx.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nnet-0.1.13 / __setx.m
1 ## Copyright (C) 2005 Michel D. Schmid  <michaelschmid@users.sourceforge.net>
2 ##
3 ##
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)
7 ## any later version.
8 ##
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.
13 ##
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/>.
17
18 ## -*- texinfo -*-
19 ## @deftypefn {Function File} {} @var{net} = __setx (@var{net},@var{X2})
20 ## @code{__setx} sets the new weights to the neural network structure
21 ## @end deftypefn
22
23 ## @seealso{getx}
24
25 ## Author: Michel D. Schmid
26
27 function net = __setx(net,xx)
28
29   ## check number of inputs
30   error(nargchk(2,2,nargin));
31
32   ## check input args
33   ## check "net", must be a net structure
34   if !__checknetstruct(net)
35     error("Structure doesn't seem to be a neural network")
36   endif
37
38   ## inputs
39   [nRows, nColumns] = size(net.IW{1,1});
40   nElementsIW = nRows*nColumns;
41   net.IW{1,1}(:) = xx(1:nElementsIW);
42
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;
47
48   ## layers
49   nLayers = net.numLayers;
50   for i = 2:nLayers
51     [nRows, nColumns] = size(net.LW{i,i-1});
52     nElementsLW = nRows*nColumns;
53     net.LW{i,i-1}(:) = xx(1+start:start+nElementsLW);
54
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;
59   endfor
60
61 endfunction