📄 demo_emgmm.html
字号:
<html><head> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1"> <title>demo_emgmm.m</title><link rel="stylesheet" type="text/css" href="../../m-syntax.css"></head><body><code><span class=defun_kw>function</span> <span class=defun_name>demo_emgmm</span>(<span class=defun_in>action,hfigure,varargin</span>)<br><span class=h1>% DEMO_EMGMM Demo on Expectation-Maximization (EM) algorithm.</span><br><span class=help>%</span><br><span class=help>% <span class=help_field>Synopsis:</span></span><br><span class=help>% demo_emgmm</span><br><span class=help>%</span><br><span class=help>% <span class=help_field>Description:</span></span><br><span class=help>% This demo shows the Expectation-Maximization (EM) algorithm</span><br><span class=help>% [Schles68][DLR77] for Gaussians mixture model (GMM). The EM </span><br><span class=help>% fits the GMM to i.i.d. sample data (in this case only 2D) </span><br><span class=help>% such that the likelihood is maximized. </span><br><span class=help>%</span><br><span class=help>% The found model is described by ellipsoids (shape of </span><br><span class=help>% covariances) and a crosses (mean value vectors). The value</span><br><span class=help>% of the optimized log-likelihood function for the current estimate </span><br><span class=help>% is displayed in the bottom part.</span><br><span class=help>%</span><br><span class=help>% <span class=help_field>Control:</span></span><br><span class=help>% Covariance - Determines type of the covariance matrix:</span><br><span class=help>% Diagonal (independent features),</span><br><span class=help>% Full (correlated features).</span><br><span class=help>% Components - Number of components (Gaussians) in the mixture.</span><br><span class=help>% </span><br><span class=help>% Iterations - Number of iterations in one step.</span><br><span class=help>% Random init - the initial model is randomly generated and/or </span><br><span class=help>% first n training samples are taken as the</span><br><span class=help>% mean vectors.</span><br><span class=help>%</span><br><span class=help>% FIG2EPS - Export screen to the PostScript file.</span><br><span class=help>% Save model - Save current model to file.</span><br><span class=help>% Load data - Load input point sets from file.</span><br><span class=help>% Create data - Invoke program for creating point sets.</span><br><span class=help>% Reset - Set the tested algorithm to the initial state.</span><br><span class=help>% Play - Run the tested algorithm.</span><br><span class=help>% Stop - Stop the running algorithm.</span><br><span class=help>% Step - Perform only one step.</span><br><span class=help>% Info - Info box.</span><br><span class=help>% Close - Close the program.</span><br><span class=help>%</span><br><span class=help>% See also EMGMM.</span><br><span class=help>%</span><br><hr><span class=help1>% <span class=help1_field>About:</span> Statistical Pattern Recognition Toolbox</span><br><span class=help1>% (C) 1999-2003, Written by Vojtech Franc and Vaclav Hlavac</span><br><span class=help1>% <a href="http://www.cvut.cz">Czech Technical University Prague</a></span><br><span class=help1>% <a href="http://www.feld.cvut.cz">Faculty of Electrical Engineering</a></span><br><span class=help1>% <a href="http://cmp.felk.cvut.cz">Center for Machine Perception</a></span><br><br><span class=help1>% <span class=help1_field>Modifications:</span></span><br><span class=help1>% 19-sep-2003, VF</span><br><span class=help1>% 11-june-2001, V.Franc, comments added.</span><br><span class=help1>% 27.02.00 V. Franc</span><br><span class=help1>% 5. 4.00 V. Franc</span><br><span class=help1>% 23.06.00 V. Hlavac Comments polished. Message when no data loaded.</span><br><span class=help1>% Export of the solution to global variables.</span><br><span class=help1>% 27-mar-2001, V.Franc, Graph og log-likelihood function added</span><br><br><br><hr><span class=comment>% Used functions: PPOINTS, PNMIX</span><br><br><span class=comment>% == Global variables, used to export results from demo_emgmm ========</span><br><br><span class=type>global</span> UNSU_MI <span class=comment>% K vectors with mean values</span><br><span class=type>global</span> UNSU_SIGMA <span class=comment>% K covariance matrices</span><br><span class=type>global</span> UNSU_PK <span class=comment>% K apriori probabilities for each distributions.</span><br><span class=comment>%global UNSU_eI % Used only by the next iteration, not globalised</span><br><span class=type>global</span> UNSU_solution <span class=comment>% 1 if alg. finished in stationary point, 0 otherwise</span><br><span class=type>global</span> UNSU_t <span class=comment>% Number of iterations the algorithm performed</span><br><br><span class=comment>% == Constants =====================================================</span><br><br>AXIST_ADD=10;<br>AXISY_ADD=5;<br><br>BORDER=0.25; <span class=comment>% space betwean window outer and the points
</span><br>CENTERSIZE=10; <span class=comment>% size of center point
</span><br>LINE_WIDTH=1;
<br>AXIST_ADD=10;
<br>DATA_IDENT=<span class=quotes>'Finite sets, enumeration'</span>; <span class=comment>% file identifier
</span><br>randinit=1;
<br>
<br><span class=keyword>if</span> <span class=stack>nargin</span> < 1,
<br> action = <span class=quotes>'initialize'</span>;
<br><span class=keyword>end</span>
<br>
<br><span class=comment>% What action is required ?
</span><br><span class=keyword>switch</span> lower(action)
<br>
<br><span class=label>case</span> <span class=quotes>'initialize'</span>
<br> <span class=comment>% == Initialize user interface control and figure window ================
</span><br>
<br> <span class=comment>% == Figure</span><br> <span class=comment>% =============================================================
</span><br> left=0.2;<br> width=0.6;<br> bottom=0.1;<br> height=0.8;<br> hfigure=<span class=graph>figure</span>(<span class=quotes>'Name'</span>,<span class=quotes>'EM algorithm'</span>, ...<br> <span class=quotes>'Visible'</span>,<span class=quotes>'off'</span>,...<br> <span class=quotes>'NumberTitle'</span>,<span class=quotes>'off'</span>, ...<br> <span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>, ...<br> <span class=quotes>'Position'</span>,[left bottom width height],...<br> <span class=quotes>'tag'</span>,<span class=quotes>'demo_emgmm'</span>,...<br> <span class=quotes>'doublebuffer'</span>,<span class=quotes>'on'</span>,...<br> <span class=quotes>'backingstore'</span>,<span class=quotes>'off'</span>);<br><br> <br> <span class=comment>% == Axes ===============================================================</span><br> left=0.1;<br> width=0.65;<br> bottom=0.45;<br> height=0.5;<br> haxes1=<span class=graph>axes</span>(...<br> <span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>, ...<br> <span class=quotes>'NextPlot'</span>,<span class=quotes>'add'</span>,...<br> <span class=quotes>'UserData'</span>,[],...<br> <span class=quotes>'Position'</span>,[left bottom width height]);<br> xlabel(<span class=quotes>'feature x\_1'</span>);<br> ylabel(<span class=quotes>'feature x\_2'</span>);<br><br> htitle1=title(<span class=quotes>'No data loaded'</span>,...
<br> <span class=quotes>'VerticalAlignment'</span>,<span class=quotes>'bottom'</span>,...
<br> <span class=quotes>'Parent'</span>,haxes1,...<br> <span class=quotes>'HorizontalAlignment'</span>,<span class=quotes>'left'</span>,...
<br> <span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>,...
<br> <span class=quotes>'Position'</span>,[0 1 0]);
<br><br> <span class=comment>% axes log-Likelihood graph</span><br> left=0.1;<br> width=0.65;<br> bottom=0.1;<br> height=0.25;<br> haxes2=<span class=graph>axes</span>(...<br> <span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>, ...<br> <span class=quotes>'NextPlot'</span>,<span class=quotes>'add'</span>,...<br> <span class=quotes>'Position'</span>,[left bottom width height]);<br> ylabel(<span class=quotes>'logL(t)'</span>);<br> <br> htitle2=title(<span class=quotes>'Log-likelihood function'</span>,...<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -