📄 sgctrain.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 sgcTrain</title> <meta name="keywords" content="sgcTrain"> <meta name="description" content="sgcTrain: Training for single Gaussian classifier training"> <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> > sgcTrain.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>sgcTrain</h1><h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="box"><strong>sgcTrain: Training for single Gaussian classifier training</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 [classParam, recogRate, hitIndex]=sgcTrain(DS, prior, plotOpt) </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"> sgcTrain: Training for single Gaussian classifier training
Usage: [classParam, recogRate, hitIndex]=sgcTrain(DS, prior, plotOpt)
DS: data set for classification
prior: a vector of class prior probability
(Equal prior probability will assume if an empty matrix is given.)
plotOpt: 1 for plotting
classParam: classParam(i) is the parameters for class i, etc.
recogRate: recognition rate
hitIndex: index of the correctly classified data points
For example:
DS=prData('iris');
DS.input=DS.input(3:4, :);
plotOpt=1;
classParam=sgcTrain(DS, [], plotOpt);</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)"><li><a href="dcprDataPlot.html" class="code" title="function dcprDataPlot(DS, plotTitle, displayAnnotation)">dcprDataPlot</a> dcprDataPlot: Plot of 2D data for data clustering or pattern recognition</li><li><a href="gaussianMle.html" class="code" title="function gaussianParam = gaussianMle(feature, plotOpt)">gaussianMle</a> mleGaussian: Maximum likelihood estimator for Gaussian distribution</li><li><a href="prData.html" class="code" title="function [DS, TS]=prData(dataName)">prData</a> prData: Various data set for PR</li><li><a href="sgcEval.html" class="code" title="function [computedClass, recogRate, hitIndex]=sgcEval(DS, classParam, plotOpt)">sgcEval</a> sgcTrain: Evaluation for single Gaussian classifier</li></ul>This function is called by:<ul style="list-style-image:url(../matlabicon.gif)"><li><a href="decisionBoundaryPlot.html" class="code" title="function out=decisionBoundaryPlot(surfObj)">decisionBoundaryPlot</a> decisionBoundaryPlot: Plot of the decision boundary of a classification problem</li><li><a href="sgcEval.html" class="code" title="function [computedClass, recogRate, hitIndex]=sgcEval(DS, classParam, plotOpt)">sgcEval</a> sgcTrain: Evaluation for single Gaussian classifier</li><li><a href="sgcSurface.html" class="code" title="function surfObj=sgcSurface(DS, pointNum, classParam)">sgcSurface</a> </li></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 [classParam, recogRate, hitIndex]=sgcTrain(DS, prior, plotOpt)</a>0002 <span class="comment">% sgcTrain: Training for single Gaussian classifier training</span>0003 <span class="comment">% Usage: [classParam, recogRate, hitIndex]=sgcTrain(DS, prior, plotOpt)</span>0004 <span class="comment">% DS: data set for classification</span>0005 <span class="comment">% prior: a vector of class prior probability</span>0006 <span class="comment">% (Equal prior probability will assume if an empty matrix is given.)</span>0007 <span class="comment">% plotOpt: 1 for plotting</span>0008 <span class="comment">% classParam: classParam(i) is the parameters for class i, etc.</span>0009 <span class="comment">% recogRate: recognition rate</span>0010 <span class="comment">% hitIndex: index of the correctly classified data points</span>0011 <span class="comment">%</span>0012 <span class="comment">% For example:</span>0013 <span class="comment">% DS=prData('iris');</span>0014 <span class="comment">% DS.input=DS.input(3:4, :);</span>0015 <span class="comment">% plotOpt=1;</span>0016 <span class="comment">% classParam=sgcTrain(DS, [], plotOpt);</span>0017 0018 <span class="comment">% Roger Jang, 20041123, 20080924</span>0019 0020 <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>0021 0022 [dim, dataNum]=size(DS.input);0023 uniqOutput=unique(DS.output);0024 classNum=length(uniqOutput);0025 0026 <span class="keyword">if</span> nargin<2, prior=ones(classNum, 1); <span class="keyword">end</span>0027 <span class="keyword">if</span> nargin<3, plotOpt=0; <span class="keyword">end</span>0028 0029 <span class="keyword">if</span> isempty(prior), prior=ones(classNum, 1); <span class="keyword">end</span>0030 0031 <span class="comment">% Identify parameters for each class</span>0032 classParam=struct([]);0033 <span class="keyword">for</span> i=1:length(uniqOutput)0034 index=find(DS.output==uniqOutput(i));0035 dataCount=length(index);0036 temp=<a href="gaussianMle.html" class="code" title="function gaussianParam = gaussianMle(feature, plotOpt)">gaussianMle</a>(DS.input(:, index)); classParam(i).mu=temp.mu; classParam(i).sigma=temp.sigma; <span class="comment">% How can we combine this into a single statement?</span>0037 classParam(i).invSigma=inv(classParam(i).sigma);0038 classParam(i).gconst=-0.5*(dim*log(2*pi)+log(det(classParam(i).sigma)));0039 classParam(i).weight=prior(i);0040 classParam(i).name=uniqOutput(i);0041 <span class="keyword">end</span>0042 [computedClass, recogRate, hitIndex]=<a href="sgcEval.html" class="code" title="function [computedClass, recogRate, hitIndex]=sgcEval(DS, classParam, plotOpt)">sgcEval</a>(DS, classParam, plotOpt);0043 0044 <span class="keyword">if</span> plotOpt & dim==20045 <a href="dcprDataPlot.html" class="code" title="function dcprDataPlot(DS, plotTitle, displayAnnotation)">dcprDataPlot</a>(DS);0046 axis image; box on0047 missIndex=1:dataNum;0048 missIndex(hitIndex)=[];0049 <span class="comment">% display these points</span>0050 <span class="keyword">for</span> i=1:length(missIndex),0051 line(DS.input(1,missIndex(i)), DS.input(2,missIndex(i)), <span class="string">'marker'</span>, <span class="string">'x'</span>, <span class="string">'color'</span>, <span class="string">'k'</span>);0052 <span class="keyword">end</span>0053 titleString = sprintf(<span class="string">'%d error points denoted by "x".'</span>, length(missIndex));0054 title(titleString);0055 <span class="keyword">end</span>0056 0057 <span class="comment">% ====== Self demo</span>0058 <a name="_sub1" href="#_subfunctions" class="code">function selfdemo</a>0059 DS=<a href="prData.html" class="code" title="function [DS, TS]=prData(dataName)">prData</a>(<span class="string">'iris'</span>);0060 DS.input=DS.input(3:4, :);0061 plotOpt=1;0062 classParam=feval(mfilename, DS, [], 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 + -