📄 demo_mmgauss.m
字号:
set(h.ellipse.handler,'XData',x,'YData',y,'Visible','on'); end % comment set(h.txsteps,'String',text); % store data set(hfigure,'UserData',h); % flush it on desktop drawnow; end % disable button set([h.edeps,h.editer,h.btstep,h.btclose,h.btplay,... h.btreset,h.btinfo,h.btload,h.btcreat,h.txeps,h.txiter],... 'Enable','on'); % enable stop button set(h.btstop,'Enable','off');case 'step' % == One step learning ============================================== h=get(hfigure,'UserData'); % get data set sets=get(h.aset,'UserData'); % are data sets loaded ? if isempty(sets)==1, return; end % get # of iter and epsilon iter=str2num(get(h.editer,'String')); epsilon=str2num(get(h.edeps,'String')); % start point for plot if h.ellipse.t==0 & iter > 1,%% [mi,sigma,solution,minp,topp]=mmln(sets.X,epsilon,1,0); options.eps = epsilon; options.tmax = 1; model=mmgauss(sets.X,options); mi = model.Mean; sigma = model.Cov; minp = model.lower_bound(end); topp = model.upper_bound(end); solution = model.exitflag; h.plot1.time=[1]; h.plot2.minps=[minp]; h.plot1.topps=[topp]; end % perform one learning step%% [mi,sigma,solution,minp,topp,h.ellipse.N,h.ellipse.t]=...%% mmln(sets.X,epsilon,iter,h.ellipse.t,h.ellipse.N); options.tmax = iter+h.ellipse.t; options.eps = epsilon; if h.ellipse.t == 0, model=mmgauss(sets.X,options); else init_model.t = h.ellipse.t; init_model.Alpha = h.ellipse.N; model=mmgauss(sets.X,options,init_model); end mi= model.Mean; sigma = model.Cov; solution = model.exitflag; minp = model.lower_bound(end); topp = model.upper_bound(end); h.ellipse.N = model.Alpha; h.ellipse.t = model.t; text=sprintf('iteration t=%d ',h.ellipse.t); if solution==1, text=strcat(text,',solution was found.'); else % add new value to plot h.plot1.time=[h.plot1.time,h.ellipse.t]; h.plot2.minps=[h.plot2.minps,minp]; h.plot1.topps=[h.plot1.topps,topp]; % is axis to be changed ? if h.ellipse.t > h.plot1.axist, h.plot1.axist=h.ellipse.t+iter*AXIST_ADD; set(h.aprob,'XLim',[1 h.plot1.axist]); end set(h.plot2.handler,'XData',h.plot1.time,'YData',h.plot2.minps,'Visible','on'); set(h.plot1.handler,'XData',h.plot1.time,'YData',h.plot1.topps,'Visible','on'); % erase old ellipse, compute and plot new one set(h.ellipse.center,'XData',mi(1),'YData',mi(2),'Visible','on'); r=sqrt(max(mahalan(sets.X,mi,sigma)));%%% [x,y]=ellipse(inv(sigma),50,r,mi); [x,y]=ellips(mi,inv(sigma),r,40); set(h.ellipse.handler,'XData',x,'YData',y,'Visible','on'); end % comment set(h.txsteps,'String',text); % flush it on desktop drawnow; set(hfigure,'UserData',h);case 'redraw' % == Redraw contents of axes ==================================== h=get(hfigure,'UserData'); % uicontrol handlers % get sets with points sets=get(h.aset,'UserData'); if isempty(sets)==1, return; end % clears axes axes(h.aset); set(get(h.aset,'Children'),'EraseMode','normal'); %%% cla; clrchild(h.aset); h.ellipse.handler=plot([0],[0],... 'Parent',h.aset,'LineWidth',LINE_WIDTH,... 'EraseMode','xor','Color','r','Visible','off'); h.ellipse.center=line(0,0,'Marker','+',... 'EraseMode','xor','Color','r','MarkerSize',CENTERSIZE,'Visible','off'); win=cmpwin(min(sets.X'),max(sets.X'),BORDER,BORDER);%%% axis(win); setaxis(h.aset,win); axes(h.aset); % plot mixture%% pplot(sets.X,sets.I);%% ppoints(sets.X,sets.I); ppatterns(sets.X); set(hfigure,'UserData',h);case 'getfile' % == Invoke standard open file dialog ==================================== % Opens file and checks if contains appropriate data, if yes than loads data. h=get(hfigure,'UserData'); % change path to directory%% wres=what('minimax');%% cd(wres.path); [name,path]=uigetfile('*.mat','Open file'); if name~=0, file.pathname=strcat(path,name); file.path=path; file.name=name;% if checkdat(file.pathname,DATA_IDENT,2,[0])==1, if check2ddata(file.pathname), set(h.btload,'UserData',file); demo_mmgauss('loadsets',hfigure); else errordlg('This file does not contain required data.','Bad file','modal'); end endcase 'loadsets' % == Load sets ================================================================== % Get file name from the pop up menu according to menu pointer. h=get(hfigure,'UserData'); % Get file name with sets file=get(h.btload,'UserData'); % Load sets sets=load(file.pathname); sets.I = sets.y; sets.K = size(sets.X,2); sets.N = 2; % store loaded sets set(h.aset,'UserData',sets); % call reset demo_mmgauss('reset',hfigure); % call redraw demo_mmgauss('redraw',hfigure); drawnow;case 'reset' % == Reset adaptation process, set up t=0 ================ h=get(hfigure,'UserData'); % get handlers % get file file=get(h.btload,'UserData'); % get data set sets=get(h.aset,'UserData'); % zeroes parameters of the separation line h.ellipse.mi=[]; h.ellipse.sigma=[]; h.ellipse.t=0; h.ellipse.N=[]; h.plot1.topps=[]; h.plot2.minps=[]; h.plot1.time=[]; h.plot1.axist=0; % comment text=sprintf('iteration t=0 '); set(h.txsteps,'String',text); % hide ellipse if h.ellipse.handler==-1, h.ellipse.handler=plot([0],[0],... 'Parent',h.aset,'LineWidth',LINE_WIDTH,... 'EraseMode','xor','Color','k','Visible','off'); h.ellipse.center=line(0,0,'Marker','x',... 'EraseMode','xor','Color','k','MarkerSize',CENTERSIZE,'Visible','off'); else set(h.ellipse.handler,'Visible','off'); set(h.ellipse.center,'Visible','off'); end % if h.ellipse.handler~=-1 % clear axes prob. axes(h.aprob); cla; axis auto; h.plot1.handler=plot([0],[0],'b','Parent',h.aprob,... 'EraseMode','background','Visible','off'); h.plot2.handler=plot([0],[0],'r','Parent',h.aprob,... 'EraseMode','background','Visible','off'); % set up handlers and flush queue with graph. objects set(hfigure,'UserData',h); % creat comment axes(h.aset); if isempty(sets)==0, set(h.title1,'String',sprintf('Data file: %s, %d vectors',... file.name,sum(sets.K))); else set(h.title1,'String','No data loaded'); pos=get(h.aset,'Position'); fsize=min(pos(3),pos(4))/8; axis([-1 1 -1 1]); builtin('text',0,0,'Press ''Load data'' button.',... 'HorizontalAlignment','center',... 'FontUnits','normalized',... 'Clipping','on',... 'FontSize',fsize); builtin('text',0,-fsize*2,... 'Load sample data from ../toolboxroot/data/mm\_samples/ ',... 'HorizontalAlignment','center',... 'FontUnits','normalized',... 'Clipping','on',... 'FontSize',fsize*0.65); end drawnow;case 'creatdata' % == Invoke data set creator ============================================%% creatset('finite',1,'demo_mmgauss','created',hfigure); createdata('finite',1,'demo_mmgauss','created',hfigure);case 'created' % == Load new created data set =========================================== % get handler and make this figure active figure(hfigure); h=get(hfigure,'UserData'); % get file name path=varargin{1}; name=varargin{2}; pathname=strcat(path,name);%% if checkdat(pathname,DATA_IDENT,2,[0])==1, if check2ddata(pathname), file.pathname=pathname; file.path=path; file.name=name; set(h.btload,'UserData',file); demo_mmgauss('loadsets',hfigure); else errordlg('This file does not contain required data.','Bad file','modal'); endcase 'info' % == Call standard Matlab`s info box ========================================= helpwin(mfilename);end % switch%%%%%%%%%%%%%%%%%%%%function []=clrchild(handle)% function []=clraxis(handle)%% CLRCHILD clears children of an object with the given handle.%% See also DELETE.%% Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac% (c) Czech Technical University Prague, http://cmp.felk.cvut.cz% Written Vojtech Franc (diploma thesis) 02.01.2000% Modifications% 24. 6.00 V. Hlavac, comments polished.delete(get(handle,'Children'));return;function [win]=cmpwin(mins,maxs,xborder,yborder)%% [win]=cmpwin(mins,maxs,xborder,yborder)%% CMPWIN computes appropriate size of the axes.%% Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac% (c) Czech Technical University Prague, http://cmp.felk.cvut.cz% Written Vojtech Franc (diploma thesis) 02.01.2000% Modifications% 24. 6.00 V. Hlavac, comments polished.dx=max( (maxs(1)-mins(1)), 1 )*xborder;dy=max( (maxs(2)-mins(2)), 1 )*yborder;%x1=floor(mins(1)-dx);%x2=ceil(maxs(1)+dx);%y1=floor(mins(2)-dy);%y2=ceil(maxs(2)+dx);x1=(mins(1)-dx);x2=(maxs(1)+dx);y1=(mins(2)-dy);y2=(maxs(2)+dx);win=[x1 x2 y1 y2];return;function []=setaxis(handle,rect)% function []=setaxis(handle,rect)%% SETAXIS sets scaling for the x- and y-axes% on the plot with a given handle.%% See also AXIS.%% Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac% (c) Czech Technical University Prague, http://cmp.felk.cvut.cz% Written Vojtech Franc (diploma thesis) 02.01.2000% Modificationsset(handle,'XLim',rect(1:2));set(handle,'YLim',rect(3:4));if size(rect,2)>=6, set(handle,'ZLim',rect(5:6));endreturn;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -