1 ## Copyright (C) 2006 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{netoutput} =} sim (@var{net}, @var{mInput})
20 ## @code{sim} is usuable to simulate a before defined neural network.
21 ## @code{net} is created with newff(@dots{}) and @var{mInput} should be the
22 ## corresponding input data set!
25 ## Author: Michel D. Schmid
28 ## Comments: see in "A neural network toolbox for Octave User's Guide" [4]
29 ## for variable naming... there have inputs or targets only one letter,
30 ## e.g. for inputs is written P. To write a program, this is stupid, you can't
31 ## search for 1 letter variable... that's why it is written here like Pp, or Tt
32 ## instead only P or T.
34 function [netoutput] = sim(net,mInput)
36 ## check range of input arguments
37 error(nargchk(2,2,nargin))
40 ## check "net", must be a net structure
41 if !__checknetstruct(net)
42 error("Structure doesn't seem to be a neural network")
44 ## check "mInput", must have defined size
45 [nRows, nColumns] = size(mInput);
46 if (nRows != net.inputs{1}.size)
47 error(["Simulation input data must have: " num2str(net.inputs{1}.size) " rows."])
50 ## first get weights...
53 b1 = repmat(b1,1,size(mInput,2));
54 nLoops = net.numLayers;
57 trf = net.layers{i}.transferFcn;
58 ## calculate the outputs for each layer from input to output
61 Nn{i,1} = IW*mInput + b1;
65 bx = repmat(bx,1,size(Aa{i-1,1},2));
66 Nn{i,1} = LWx*Aa{i-1,1} + bx;
71 Aa{i,1} = tansig(Nn{i,1});
73 Aa{i,1} = purelin(Nn{i,1});
75 Aa{i,1} = logsig(Nn{i,1});
77 error(["sim:Unknown transfer fucntion: " trf "!"]);