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{pn},@var{meanp},@var{stdp},@var{tn},@var{meant},@var{stdt}] =prestd(@var{p},@var{t})
20 ## @code{prestd} preprocesses the data so that the mean is 0 and the standard deviation is 1.
25 ## Author: Michel D. Schmid
27 function [pn,meanp,stdp,tn,meant,stdt] = prestd(Pp,Tt)
31 ## * p are the general descriptions for the inputs of
33 ## * t is written for "targets" and these are the outputs
34 ## of a neural network
36 ## some more detailed description:
37 ## for more informations about this
38 ## formula programmed in this file, see:
39 ## 1. http://en.wikipedia.org/wiki/Standard_score
40 ## 2. http://www.statsoft.com/textbook/stathome.html
41 ## choose "statistical glossary", choose "standardization"
43 ## check range of input arguments
44 error(nargchk(1,2,nargin))
49 [nRows,nColumns]=size(Pp);
50 rowOnes = ones(1,nColumns);
52 ## now set all standard deviations which are zero to 1
53 [nRowsII, nColumnsII] = size(stdp);
54 rowZeros = zeros(nRowsII,1); # returning a row containing only zeros
55 findZeros = find(stdp==0); # returning a vector containing index where zeros are
56 rowZeros(findZeros)=1; #
58 if (sum(rowZeros) != 0)
59 warning("Some standard deviations are zero. Those inputs won't be transformed.");
60 meanpZero = meanp.*nequal;
61 stdpZero = stdp.*nequal + 1*rowZeros;
67 ## calculate the standardized inputs
68 pn = (Pp-meanpZero*rowOnes)./(stdpZero*rowOnes);
75 ## now set all standard deviations which are zero to 1
76 [nRowsIII, nColumnsIII] = size(stdt);
77 rowZeros = zeros(nRowsIII,1);
78 findZeros = find(stdt==0);
79 rowZeros(findZeros)=1;
81 if (sum(rowZeros) != 0)
82 warning("Some standard deviations are zero. Those targets won't be transformed.");
83 meantZero = meant.*nequal;
84 stdtZero = stdt.*nequal + 1*rowZeros;
90 ## calculate the standardized targets
91 tn = (Tt-meantZero*rowOnes)./(stdtZero*rowOnes);
97 %! Pp = [1 2 3 4; -1 3 2 -1];
99 %! [pn,meanp,stdp] = prestd(Pp);
100 %!assert(pn,[-1.16190 -0.38730 0.38730 1.16190; -0.84887 1.09141 0.60634 -0.84887],0.00001);