]> Creatis software - CreaPhase.git/blob - octave_packages/nnet-0.1.13/trastd.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nnet-0.1.13 / trastd.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{pn} = trastd (@var{p},@var{meanp},@var{stdp})
20 ## @code{trastd} preprocess additional data for neural network simulation.
21 ##
22 ## @example
23 ##   @code{p}    : test input data
24 ##   @code{meanp}: vector with standardization parameters of prestd(...)
25 ##   @code{stdp} : vector with standardization parameters of prestd(...)
26 ##
27 ##   meanp = [2.5; 6.5];
28 ##   stdp = [1.2910; 1.2910];
29 ##   p = [1 4; 2 5];
30 ##
31 ##   pn = trastd(p,meanp,stdp);
32 ## @end example
33 ## @noindent
34 ## @end deftypefn
35
36 ## @seealso{prestd, poststd}
37
38 ## Author: Michel D. Schmid
39
40 function [Pn] = trastd(Pp,meanp,stdp)
41
42   ## check number of inputs
43   error(nargchk(3,3,nargin));
44
45   
46   [nRows,nColumns]=size(Pp);
47   rowOnes = ones(1,nColumns);
48   
49   ## now set all standard deviations which are zero to 1
50   [nRowsII, nColumnsII] = size(stdp);
51   rowZeros = zeros(nRowsII,1);
52   findZeros = find(stdp==0);
53   rowZeros(findZeros)=1;
54   equal = rowZeros;
55   nequal = !equal;
56   if ( sum(equal) != 0 )
57     warning("Some standard deviations are zero. Those inputs won't be transformed.");
58     meanp = meanp.*nequal;
59     stdp = stdp.*nequal + 1*equal;
60   end
61
62   Pn = (Pp-meanp*rowOnes)./(stdp*rowOnes);
63
64 endfunction
65
66 ##
67 ## >> mInput = [1 2 3 4; 5 6 7 8]
68 ##
69 ## mInput =
70 ##
71 ##      1     2     3     4
72 ##      5     6     7     8
73 ##
74 ## >> [pn,meanp,stdp] = prestd(mInput)
75 ##
76 ## pn =
77 ##
78 ##    -1.1619   -0.3873    0.3873    1.1619
79 ##    -1.1619   -0.3873    0.3873    1.1619
80 ##
81 ##
82 ## meanp =
83 ##
84 ##     2.5000
85 ##     6.5000
86 ##
87 ##
88 ## stdp =
89 ##
90 ##     1.2910
91 ##     1.2910