📄 demo_mmgauss.html
字号:
<span class=quotes>'Enable'</span>,<span class=quotes>'off'</span>);<br> <span class=comment>% enable stop button</span><br> <span class=graph>set</span>(h.btstop,<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br><br> <span class=comment>% get # of iter and epsilon</span><br> iter=str2num(<span class=graph>get</span>(h.editer,<span class=quotes>'String'</span>));<br> epsilon=str2num(<span class=graph>get</span>(h.edeps,<span class=quotes>'String'</span>));<br><br> <span class=comment>% set stop button</span><br> <span class=graph>set</span>(h.btstop,<span class=quotes>'UserData'</span>,0);<br><br> <span class=comment>% start point for plot</span><br> <span class=keyword>if</span> h.ellipse.t==0 & iter > 1,<br><span class=comment>%% [mi,sigma,solution,minp,topp]=mmln(sets.X,epsilon,1,0);</span><br> options.eps = epsilon;<br> options.tmax = 1;<br> model=mmgauss(sets.X,options);<br> mi = model.Mean;<br> sigma = model.Cov;<br> minp = model.lower_bound(<span class=keyword>end</span>);<br> topp = model.upper_bound(<span class=keyword>end</span>);<br> solution = model.exitflag;<br><br> h.plot1.time=[1];<br> h.plot2.minps=[minp];<br> h.plot1.topps=[topp];<br> <span class=keyword>end</span><br><br><br> <span class=comment>% Play - adaptation process</span><br> play=1;<br> <span class=keyword>while</span> play==1 & <span class=graph>get</span>(h.btstop,<span class=quotes>'UserData'</span>)==0,<br><br> <span class=comment>% perform one learning step</span><br><span class=comment>% [mi,sigma,solution,minp,topp,h.ellipse.N,h.ellipse.t]=...</span><br><span class=comment>% mmln(sets.X,epsilon,iter,h.ellipse.t,h.ellipse.N);</span><br><br> options.tmax = iter+h.ellipse.t;<br> options.eps = epsilon;<br> <span class=keyword>if</span> h.ellipse.t == 0,<br> model=mmgauss(sets.X,options);<br> <span class=keyword>else</span><br> init_model.t = h.ellipse.t;<br> init_model.Alpha = h.ellipse.N;<br> model=mmgauss(sets.X,options,init_model);<br> <span class=keyword>end</span><br><br> mi= model.Mean;<br> sigma = model.Cov;<br> solution = model.exitflag;<br> minp = model.lower_bound(<span class=keyword>end</span>);<br> topp = model.upper_bound(<span class=keyword>end</span>);<br> h.ellipse.N = model.Alpha;<br> h.ellipse.t = model.t;<br> <br> <br> text=<span class=io>sprintf</span>(<span class=quotes>'iteration t=%d '</span>,h.ellipse.t);<br> <span class=keyword>if</span> solution==1,<br> text=strcat(text,<span class=quotes>', algorithm has converged.'</span>);<br> play=0;<br> <span class=keyword>else</span><br> <span class=comment>% add new value to plot</span><br> h.plot1.time=[h.plot1.time,h.ellipse.t];<br> h.plot2.minps=[h.plot2.minps,minp];<br> h.plot1.topps=[h.plot1.topps,topp];<br><br> <span class=comment>% is axis to be changed ?</span><br> <span class=keyword>if</span> h.ellipse.t > h.plot1.axist,<br> h.plot1.axist=h.ellipse.t+iter*AXIST_ADD;<br> <span class=graph>set</span>(h.aprob,<span class=quotes>'XLim'</span>,[1 h.plot1.axist]);<br> <span class=keyword>end</span><br> <span class=graph>set</span>(h.plot2.handler,<span class=quotes>'XData'</span>,h.plot1.time,<span class=quotes>'YData'</span>,h.plot2.minps,<span class=quotes>'Visible'</span>,<span class=quotes>'on'</span>);<br> <span class=graph>set</span>(h.plot1.handler,<span class=quotes>'XData'</span>,h.plot1.time,<span class=quotes>'YData'</span>,h.plot1.topps,<span class=quotes>'Visible'</span>,<span class=quotes>'on'</span>);<br><br> <span class=comment>% erase old ellipse, compute and plot new one</span><br> <span class=graph>set</span>(h.ellipse.center,<span class=quotes>'XData'</span>,mi(1),<span class=quotes>'YData'</span>,mi(2),<span class=quotes>'Visible'</span>,<span class=quotes>'on'</span>);<br> r=sqrt(max(mahalan(sets.X,mi,sigma)));<br><span class=comment>%%% [x,y]=ellipse(inv(sigma),50,r,mi);</span><br> [x,y]=ellips(mi,inv(sigma),r,40);<br> <span class=graph>set</span>(h.ellipse.handler,<span class=quotes>'XData'</span>,x,<span class=quotes>'YData'</span>,y,<span class=quotes>'Visible'</span>,<span class=quotes>'on'</span>);<br> <span class=keyword>end</span><br><br> <span class=comment>% comment</span><br> <span class=graph>set</span>(h.txsteps,<span class=quotes>'String'</span>,text);<br><br> <span class=comment>% store data</span><br> <span class=graph>set</span>(hfigure,<span class=quotes>'UserData'</span>,h);<br><br> <span class=comment>% flush it on desktop</span><br> drawnow;<br> <span class=keyword>end</span><br><br> <span class=comment>% disable button</span><br> <span class=graph>set</span>([h.edeps,h.editer,h.btstep,h.btclose,h.btplay,...<br> h.btreset,h.btinfo,h.btload,h.btcreat,h.txeps,h.txiter],...<br> <span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br> <span class=comment>% enable stop button</span><br> <span class=graph>set</span>(h.btstop,<span class=quotes>'Enable'</span>,<span class=quotes>'off'</span>);<br><br><br><span class=label>case</span> <span class=quotes>'step'</span><br> <span class=comment>% == One step learning ==============================================</span><br> h=<span class=graph>get</span>(hfigure,<span class=quotes>'UserData'</span>);<br><br> <span class=comment>% get data set</span><br> sets=<span class=graph>get</span>(h.aset,<span class=quotes>'UserData'</span>);<br><br> <span class=comment>% are data sets loaded ?</span><br> <span class=keyword>if</span> isempty(sets)==1,<br> <span class=jump>return</span>;<br> <span class=keyword>end</span><br><br> <span class=comment>% get # of iter and epsilon</span><br> iter=str2num(<span class=graph>get</span>(h.editer,<span class=quotes>'String'</span>));<br> epsilon=str2num(<span class=graph>get</span>(h.edeps,<span class=quotes>'String'</span>));<br><br> <span class=comment>% start point for plot</span><br> <span class=keyword>if</span> h.ellipse.t==0 & iter > 1,<br><span class=comment>%% [mi,sigma,solution,minp,topp]=mmln(sets.X,epsilon,1,0);</span><br> options.eps = epsilon;<br> options.tmax = 1;<br> model=mmgauss(sets.X,options);<br> mi = model.Mean;<br> sigma = model.Cov;<br> minp = model.lower_bound(<span class=keyword>end</span>);<br> topp = model.upper_bound(<span class=keyword>end</span>);<br> solution = model.exitflag;<br> <br> <br> h.plot1.time=[1];<br> h.plot2.minps=[minp];<br> h.plot1.topps=[topp];<br> <span class=keyword>end</span><br><br> <span class=comment>% perform one learning step</span><br><br><span class=comment>%% [mi,sigma,solution,minp,topp,h.ellipse.N,h.ellipse.t]=...</span><br><span class=comment>%% mmln(sets.X,epsilon,iter,h.ellipse.t,h.ellipse.N);</span><br><br> options.tmax = iter+h.ellipse.t;<br> options.eps = epsilon;<br> <span class=keyword>if</span> h.ellipse.t == 0,<br> model=mmgauss(sets.X,options);<br> <span class=keyword>else</span><br> init_model.t = h.ellipse.t;<br> init_model.Alpha = h.ellipse.N;<br> model=mmgauss(sets.X,options,init_model);<br> <span class=keyword>end</span><br> mi= model.Mean;<br> sigma = model.Cov;<br> solution = model.exitflag;<br> minp = model.lower_bound(<span class=keyword>end</span>);<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -