📄 inputnormalize.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><head> <title>Description of inputNormalize</title> <meta name="keywords" content="inputNormalize"> <meta name="description" content="inputNormalize: Input (feature) normalization to have zero mean and unity variance for each feature"> <meta http-equiv="Content-Type" content="text/html; charset=big5"> <meta name="generator" content="m2html © 2003 Guillaume Flandin"> <meta name="robots" content="index, follow"> <link type="text/css" rel="stylesheet" href="../m2html.css"></head><body><a name="_top"></a><div><a href="../index.html">Home</a> > <a href="index.html">dcpr</a> > inputNormalize.m</div><!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td><td align="right"><a href="index.html">Index for dcpr <img alt=">" border="0" src="../right.png"></a></td></tr></table>--><h1>inputNormalize</h1><h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="box"><strong>inputNormalize: Input (feature) normalization to have zero mean and unity variance for each feature</strong></div><h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="box"><strong>function [data2, mu1, sigma1] = inputNormalize(data, plotOpt, mu, sigma) </strong></div><h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="fragment"><pre class="comment"> inputNormalize: Input (feature) normalization to have zero mean and unity variance for each feature
Usage:
[data2, MU1, SIGMA1] = inputNormalize(data, plotOpt, MU, SIGMA)
data: Input feature matrix, where each column is a data point
and each column being the values for a specific feature.
data2: Output feature matrix with zero mean and unity variance for each feature.
If the function has three inputs, then the normalization is performed
using the supplied MU and SIGMA. If the function has only one inputs,
MU1 and SIGMA1 are calculated (and returned) based on data.</pre></div><!-- crossreference --><h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>This function calls:<ul style="list-style-image:url(../matlabicon.gif)"></ul>This function is called by:<ul style="list-style-image:url(../matlabicon.gif)"></ul><!-- crossreference --><h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><ul style="list-style-image:url(../matlabicon.gif)"><li><a href="#_sub1" class="code">function selfdemo</a></li></ul><h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [data2, mu1, sigma1] = inputNormalize(data, plotOpt, mu, sigma)</a>0002 <span class="comment">% inputNormalize: Input (feature) normalization to have zero mean and unity variance for each feature</span>0003 <span class="comment">% Usage:</span>0004 <span class="comment">% [data2, MU1, SIGMA1] = inputNormalize(data, plotOpt, MU, SIGMA)</span>0005 <span class="comment">% data: Input feature matrix, where each column is a data point</span>0006 <span class="comment">% and each column being the values for a specific feature.</span>0007 <span class="comment">% data2: Output feature matrix with zero mean and unity variance for each feature.</span>0008 <span class="comment">%</span>0009 <span class="comment">% If the function has three inputs, then the normalization is performed</span>0010 <span class="comment">% using the supplied MU and SIGMA. If the function has only one inputs,</span>0011 <span class="comment">% MU1 and SIGMA1 are calculated (and returned) based on data.</span>0012 0013 <span class="comment">% Roger Jang, 20040925</span>0014 0015 <span class="keyword">if</span> nargin<1, <a href="#_sub1" class="code" title="subfunction selfdemo">selfdemo</a>; <span class="keyword">return</span>; <span class="keyword">end</span>0016 <span class="keyword">if</span> nargin<2, plotOpt=0; <span class="keyword">end</span>0017 0018 dim = size(data, 1);0019 dataNum = size(data, 2);0020 0021 <span class="keyword">if</span> nargin<=20022 mu1 = mean(data, 2);0023 sigma1 = sqrt(diag(cov(data')));0024 data2 = data-mu1*ones(1,dataNum,1);0025 data2 = diag(1./sigma1)*data2;0026 <span class="keyword">else</span>0027 data2 = data-mu(:)*ones(1,dataNum,1);0028 data2 = diag(1./sigma)*data2;0029 <span class="keyword">end</span>0030 0031 <span class="keyword">if</span> plotOpt0032 subplot(1,2,1);0033 plot(data(1,:), data(2,:), <span class="string">'.'</span>); axis image0034 title(<span class="string">'Original data'</span>);0035 subplot(1,2,2);0036 plot(data2(1,:), data2(2,:), <span class="string">'.'</span>); axis image0037 title(<span class="string">'Normalized data'</span>);0038 <span class="keyword">end</span>0039 0040 <span class="comment">% ====== Self demo</span>0041 <a name="_sub1" href="#_subfunctions" class="code">function selfdemo</a>0042 dataNum=100;0043 x=8*randn(1, dataNum);0044 y=randn(1, dataNum)+100;0045 data=[x; y];0046 plotOpt=1;0047 feval(mfilename, data, plotOpt);</pre></div><hr><address>Generated on Thu 30-Oct-2008 12:53:56 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -