⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lda.html

📁 一个关于数据聚类和模式识别的程序,在生物化学,化学中因该都可以用到.希望对大家有用,谢谢支持
💻 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 lda</title>  <meta name="keywords" content="lda">  <meta name="description" content="lda: Linear discriminant analysis">  <meta http-equiv="Content-Type" content="text/html; charset=big5">  <meta name="generator" content="m2html &copy; 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> &gt;  <a href="index.html">dcpr</a> &gt; lda.m</div><!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td><td align="right"><a href="index.html">Index for dcpr&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>--><h1>lda</h1><h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="box"><strong>lda: Linear discriminant analysis</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 [DS2, discrimVec, eigValues] = lda(DS, discrimVecNum) </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">lda: Linear discriminant analysis
    Usage:
    [DS2, discrimVec, eigValues] = lda(DS, discrimVecNum)
        DS: input data set.
            Please try &quot;DS=prData('iris')&quot; to get an example of DS.
        discrimVecNum: No. of discriminant vectors
        DS2: output data set, with new feature vectors

    Reference:
    J. Duchene and S. Leclercq, &quot;An Optimal Transformation for
    Discriminant Principal Component Analysis,&quot; IEEE Trans. on
    Pattern Analysis and Machine Intelligence,
    Vol. 10, No 6, November 1988

    Type &quot;lda&quot; for a self-demo.</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="classSize.html" class="code" title="function [class, count] = classSize(DS, plotOpt)">classSize</a>	classSize: Class sizes for a sample data set</li><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="knnrLoo.html" class="code" title="function [recogRate, computed, nearestIndex] = knnrLoo(DS, k, plotOpt)">knnrLoo</a>	knnrLoo: Leave-one-out recognition rate of KNNR</li><li><a href="prData.html" class="code" title="function [DS, TS]=prData(dataName)">prData</a>	prData: Various data set for PR</li></ul>This function is called by:<ul style="list-style-image:url(../matlabicon.gif)"><li><a href="ldaKnnrLoo.html" class="code" title="function recogRate=ldaKnnrLoo(DS, maxDim, plotOpt)">ldaKnnrLoo</a>	ldaKnnrLoo: LDA analysis using KNNR and LOO</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 [DS2, discrimVec, eigValues] = lda(DS, discrimVecNum)</a>0002 <span class="comment">%lda: Linear discriminant analysis</span>0003 <span class="comment">%    Usage:</span>0004 <span class="comment">%    [DS2, discrimVec, eigValues] = lda(DS, discrimVecNum)</span>0005 <span class="comment">%        DS: input data set.</span>0006 <span class="comment">%            Please try &quot;DS=prData('iris')&quot; to get an example of DS.</span>0007 <span class="comment">%        discrimVecNum: No. of discriminant vectors</span>0008 <span class="comment">%        DS2: output data set, with new feature vectors</span>0009 <span class="comment">%</span>0010 <span class="comment">%    Reference:</span>0011 <span class="comment">%    J. Duchene and S. Leclercq, &quot;An Optimal Transformation for</span>0012 <span class="comment">%    Discriminant Principal Component Analysis,&quot; IEEE Trans. on</span>0013 <span class="comment">%    Pattern Analysis and Machine Intelligence,</span>0014 <span class="comment">%    Vol. 10, No 6, November 1988</span>0015 <span class="comment">%</span>0016 <span class="comment">%    Type &quot;lda&quot; for a self-demo.</span>0017 0018 <span class="comment">%    Roger Jang, 19990829, 20030607</span>0019 0020 <span class="keyword">if</span> nargin&lt;1, <a href="#_sub1" class="code" title="subfunction selfdemo">selfdemo</a>; <span class="keyword">return</span>; <span class="keyword">end</span>0021 <span class="keyword">if</span> ~isstruct(DS)0022     fprintf(<span class="string">'Please try &quot;DS=prData(''iris'')&quot; to get an example of DS.\n'</span>);0023     error(<span class="string">'The input DS should be a structure variable!'</span>);0024 <span class="keyword">end</span>0025 <span class="keyword">if</span> nargin&lt;2, discrimVecNum=size(DS.input,1); <span class="keyword">end</span>0026 0027 <span class="comment">% ====== Initialization</span>0028 m = size(DS.input,1);    <span class="comment">% Dimension of data point</span>0029 n = size(DS.input,2);    <span class="comment">% No. of data point</span>0030 A = DS.input;0031 <span class="keyword">if</span> size(DS.output, 1)==1    <span class="comment">% Crisp output</span>0032     classLabel = DS.output;0033     [diffClassLabel, <a href="classSize.html" class="code" title="function [class, count] = classSize(DS, plotOpt)">classSize</a>] = elementCount(classLabel);0034     classNum = length(diffClassLabel);0035     mu = mean(A, 2);0036 0037     <span class="comment">% ====== Compute B and W</span>0038     <span class="comment">% ====== B: between-class scatter matrix</span>0039     <span class="comment">% ====== W:  within-class scatter matrix</span>0040     <span class="comment">% M = \sum_k m_k*mu_k*mu_k^T</span>0041     M = zeros(m, m);0042     <span class="keyword">for</span> i = 1:classNum,0043         index = find(classLabel==diffClassLabel(i));0044         classMean = mean(A(:, index), 2);0045         M = M + length(index)*classMean*classMean';0046     <span class="keyword">end</span>0047     W = A*A'-M;0048     B = M-n*mu*mu';0049 <span class="keyword">else</span>                <span class="comment">% Potential fuzzy output</span>0050 <span class="keyword">end</span>0051 0052 <span class="comment">% ====== Find the best discriminant vectors</span>0053 invW = inv(W);0054 Q = invW*B;0055 0056 D = [];0057 <span class="keyword">for</span> i = 1:discrimVecNum0058     [eigVec, eigVal] = eig(Q);0059     [eigValues(i), index] = max(diag(eigVal));  0060     D = [D, eigVec(:, index)];        <span class="comment">% Each col of D is a eigenvector</span>0061     Q = (eye(m)-invW*D*inv(D'*invW*D)*D')*invW*B;0062 <span class="keyword">end</span>0063 DS2=DS;0064 DS2.input = D(:,1:discrimVecNum)'*A; 0065 discrimVec = D;0066 0067 <span class="comment">% ====== Self demo</span>0068 <a name="_sub1" href="#_subfunctions" class="code">function selfdemo</a>0069 <span class="comment">% ====== Self demo using IRIS dataset</span>0070 DS=<a href="prData.html" class="code" title="function [DS, TS]=prData(dataName)">prData</a>(<span class="string">'iris'</span>);0071 DS2=feval(mfilename, DS);0072 figure; <a href="dcprDataPlot.html" class="code" title="function dcprDataPlot(DS, plotTitle, displayAnnotation)">dcprDataPlot</a>(DS2); xlabel(<span class="string">'Input 1'</span>); ylabel(<span class="string">'Input 2'</span>);0073 DS2.input=DS2.input(3:4, :);0074 figure; <a href="dcprDataPlot.html" class="code" title="function dcprDataPlot(DS, plotTitle, displayAnnotation)">dcprDataPlot</a>(DS2); xlabel(<span class="string">'Input 3'</span>); ylabel(<span class="string">'Input 4'</span>);0075 <span class="comment">% ====== Leave-one-out errors after using LDA for dimension reduction</span>0076 DS=<a href="prData.html" class="code" title="function [DS, TS]=prData(dataName)">prData</a>(<span class="string">'iris'</span>);0077 recogRate = <a href="knnrLoo.html" class="code" title="function [recogRate, computed, nearestIndex] = knnrLoo(DS, k, plotOpt)">knnrLoo</a>(DS); 0078 fprintf(<span class="string">'Full data ===&gt; LOO recog. rate = %g%%\n'</span>, 100*recogRate);0079 DS2 = feval(mfilename, DS);0080 <span class="keyword">for</span> i = 1:40081     DS3=DS2; DS3.input=DS3.input(1:i, :);0082     [recogRate(i), hitIndex] = <a href="knnrLoo.html" class="code" title="function [recogRate, computed, nearestIndex] = knnrLoo(DS, k, plotOpt)">knnrLoo</a>(DS3);0083     fprintf(<span class="string">'LDA dim = %d ===&gt; LOO recog. rate = %g%%\n'</span>, i, 100*recogRate(i));0084 <span class="keyword">end</span></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> &copy; 2003</address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -