📄 demo_anderson.m
字号:
function result = demo_anderson(action,hfigure,varargin)% DEMO_ANDERSON Demo on Generalized Anderson's task.%% Synopsis:% demo_anderson%% Description:% This demo demonstrates the algorithms which solve % the Generalized Anderson`s Task (GAT) [SH10]. The GAT is an % instance of the non-Bayesian task of decision under % non-random intervention. % % The goal of is to find a binary linear classification% rule (g(x)=sgn(W'*x+b) (line in 2D) with minimal probability of% misclassification. The conditional probabilities are known to% be Gaussians their paramaters belong to a given set of % parameters. The true parameters are not known. The linear rule % which guarantes the minimimal classification error for the worst% possible case (the worst configuration of Gaussains) is% sought for.% % The found solution (hyperplane, line in 2D) is vizualized % as well as the input Gaussians which describe input classes.%% Following algorithms can be tested:% % Eps-solution - Finds epsilon-solution of the GAT in finite number% of iterations if such solution exist. The epsilon means% desired classification error.% Original - Original Anderson-Bahadur's algorithm defined for % two Gaussians only (each class one Gaussian).% Optimal - Implementation of general algorithm propsed by Schlesinger.% It finds the optimal solution.% Gradient - Fast and simple implementation which uses the generalized% gradient descent optimization.%% Control:% Algorithm - select algorithm for testing.% Parameter - parameters for the selected algorithm.% Iterations - number of iterations in one step.% Animation - enable/dissable animation.%% FIG2EPS - export screen to the PostScript file.% Load data - load input point sets from file.% Create data - call interactive program for creating sets of Gaussians.% Reset - set the tested algorithm to the initial state.% Play - run the tested algorithm.% Stop - stop the running algorithm.% Step - perform only one step.% Info - display the info box.% Close - close the program.%% See also % EANDERS, ANDRORIG, GGRADANDR, GANDERS.%% About: Statistical Pattern Recognition Toolbox% (C) 1999-2003, Written by Vojtech Franc and Vaclav Hlavac% <a href="http://www.cvut.cz">Czech Technical University Prague</a>% <a href="http://www.feld.cvut.cz">Faculty of Electrical Engineering</a>% <a href="http://cmp.felk.cvut.cz">Center for Machine Perception</a>% Modifications:% 17-sep-2003, VF% 11-June-2001, V.Franc, comments added.% 24. 6.00 V. Hlavac, comments polished.% constantsALGONAMES=['Eps-solution ';... 'Original ';... 'Gradient ';... 'Optimal '];PREC_TITLE=['Max error (0-50) [%]';... % e-Optimal solution 'd(lambda,ni) (0,inf)';... % Original Anderson`s solution 'd( min r ) (0,inf) ';... % Gradient method 'd( min r ) (0,inf) ']; % General solution DEF_PRECISION=[10,1e-3,1e-3,1e-3]; % default values of the precision of algo. 1,2,...BORDER=0.5;DATA_IDENT='Infinite sets, Normal distributions'; % M-file identifierPLOT_FCE='pandr2d'; % outlined ellipsoids%PLOT_FCE='pandr2df'; % outlined ellipsoids% if number of arguments is less then 1, that means first call of this function. Every% other calls set up at least argument actionif nargin < 1, action = 'initialize';end% what action is required ?switch lower(action)case 'initialize' % == Initialize user interface control and figure window ================ % == Figure ============================================================= left=0.1; width=0.8; bottom=0.1; height=0.8; hfigure=figure('Name','Anderson`s task', ... 'Visible','off',... 'Units','normalized', ... 'NumberTitle','off', ... 'Position',[left bottom width height],... 'tag','Demo_Anderson',... 'Units','normalized', ... 'RendererMode','manual'); % == Axes =============================================================== left=0.1; width=0.65; % axes for showing sets bottom=0.35; height=0.60; haxes1=axes(... 'Units','normalized', ... 'Box','on', ... 'DrawMode','fast',... 'NextPlot','add',... 'Layer','top',... 'UserData',[],... 'Position',[left bottom width height]); xlabel('feature x'); ylabel('feature y'); % == Comment window ===================================================== % Comment Window frame bottom=0.05; height=0.2; uicontrol( ... 'Style','frame', ... 'Units','normalized', ... 'Position',[left bottom width height], ... 'BackgroundColor',[0.5 0.5 0.5]); % Text label uicontrol( ... 'Style','text', ... 'Units','normalized', ... 'Position',[left height-0.01 width 0.05], ... 'BackgroundColor',[0.5 0.5 0.5], ... 'ForegroundColor',[1 1 1], ... 'String','Comment Window'); % Edit window border=0.01; hconsole=uicontrol( ... 'Style','edit', ... 'HorizontalAlignment','left', ... 'Units','normalized', ... 'Max',10, ... 'BackgroundColor',[1 1 1], ... 'Position',[left+border bottom width-2*border height-0.05], ... 'Enable','inactive',... 'String',''); % == Buttons =========================================================== % -- Export to EPS --------- width=0.1; left=0.75-width; bottom=0.95; height=0.04; hbtclose = uicontrol(... 'Units','Normalized', ... 'Callback','fig2eps(gcf)',... 'ListboxTop',0, ... 'Position',[left bottom width height], ... 'String','FIG2EPS'); %---------------------------------- % Close button left=0.8; bottom=0.05; height=0.05; width=0.15; hbtclose = uicontrol(... 'Units','Normalized', ... 'Callback','close(gcf)',... 'ListboxTop',0, ... 'Position',[left bottom width height], ... 'String','Close'); % Info button: call stanard info box bottom=bottom+1.5*height; hbtinfo = uicontrol(... 'Units','Normalized', ... 'Callback','demo_anderson(''info'',gcf)',... 'ListboxTop',0, ... 'Position',[left bottom width height], ... 'String','Info'); % Step button: perform one adaptation step bottom=bottom+1.5*height; hbtstep = uicontrol(... 'Units','Normalized', ... 'ListboxTop',0, ... 'Position',[left bottom width height], ... 'String','Step', ... 'Interruptible','off',... 'Callback','demo_anderson(''step'',gcf)'); % Stop button: stop process of adaptation bottom=bottom+height; hbtstop = uicontrol(... 'Units','Normalized', ... 'ListboxTop',0, ... 'Position',[left bottom width height], ... 'String','Stop', ... 'Callback','set(gcbo,''UserData'',1)',... 'Enable','off'); % Play button: start up adaptation bottom=bottom+height; hbtplay = uicontrol(... 'Units','Normalized', ... 'ListboxTop',0, ... 'Position',[left bottom width height], ... 'String','Play', ... 'Callback','demo_anderson(''play'',gcf)'); % Reset button: set up t = 0 bottom=bottom+height; hbtreset = uicontrol(... 'Units','Normalized', ... 'ListboxTop',0, ... 'Position',[left bottom width height], ... 'String','Reset', ... 'Callback','demo_anderson(''reset'',gcf)'); % Create data bottom=bottom+1.5*height; hbtcreat = uicontrol(... 'Units','Normalized', ... 'ListboxTop',0, ... 'Position',[left bottom width height], ... 'String','Create data', ... 'Callback','demo_anderson(''creatdata'',gcf)'); % Load data bottom=bottom+1*height; hbtload = uicontrol(... 'Units','Normalized', ... 'ListboxTop',0, ... 'Position',[left bottom width height], ... 'String','Load data', ... 'Callback','demo_anderson(''getfile'',gcf)'); % == Check boxes =============================================================== % Make chack box to determine if a line will be drawn in one step or smoothly. bottom=bottom+height*1.2; hxbanim = uicontrol(... 'Style','checkbox', ... 'Units','normalized', ... 'ListboxTop',0, ... 'Position',[left bottom width height], ... 'String','Animation'); % == Popup menus ========================================================== % Pop up menu for the selection between algorithms % title bottom=0.95-height; htxalgo=uicontrol( ... 'Style','text', ... 'Units','normalized', ... 'Position',[left bottom width 0.9*height], ... 'String','Algorithm'); % popup menu bottom=bottom-0.9*height; hpualgo=uicontrol( ... 'Style','popup', ... 'Units','normalized', ... 'CallBack','demo_anderson(''algohandler'',gcf)',... 'Position',[left bottom width height], ... 'UserData',1,... 'String',ALGONAMES); % == Edit lines ================================================================ bottom=0.95-3.5*height; % Precision of solution htxprec=uicontrol( ... 'Style','text', ... 'Units','normalized', ... 'Position',[left bottom width 0.9*height], ... 'String',PREC_TITLE(1,:)); bottom=bottom-height; hedprec = uicontrol(... 'Units','normalized', ... 'ListboxTop',0, ... 'Position',[left bottom width height], ... 'Style','edit',... 'String',num2str(DEF_PRECISION(1)) ); % # of iterations bottom=bottom-1.5*height; htxiter=uicontrol( ... 'Style','text', ... 'Units','normalized', ... 'Position',[left bottom width 0.9*height], ... 'String','Iterations'); bottom=bottom-0.9*height; hediter = uicontrol(... 'Units','normalized', ... 'ListboxTop',0, ... 'Position',[left bottom width height], ... 'Style','edit',... 'String',1); % ============================================================================== % Store handlers handlers=struct(... 'line',struct('handler',-1,'alpha',0,'alpha1',0,'alpha2',0,'lambda',0,'theta',0,'t',0),... 'btstep',hbtstep,... 'btstop',hbtstop,... 'btclose',hbtclose,... 'btplay',hbtplay,... 'btreset',hbtreset,... 'btinfo',hbtinfo,... 'btload',hbtload,... 'btcreat',hbtcreat,... 'pualgo',hpualgo,... 'console',hconsole,... 'edprec',hedprec,... 'editer',hediter,... 'txprec',htxprec,... 'axes1',haxes1,... 'xbanim',hxbanim); set(hfigure,'UserData',handlers); % Reset adaptation, t=0 demo_anderson('reset',hfigure); % Put figure on desktop set(hfigure,'Visible','on'); drawnow;case 'creatdata' % == Invoke data set creator ============================================% creatset('normal',2,'demo_anderson','created',hfigure); createdata('gauss',2,'demo_anderson','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 0])==1, if check2dgauss(pathname), file.pathname=pathname; file.path=path; file.name=name; set(h.btload,'UserData',file); demo_anderson('loadsets',hfigure); demo_anderson('reset',hfigure); else errordlg('This file does not contain required data.','Bad file','modal'); endcase 'getfile' % == Invoke standard open file dialog ==================================== % Opens file and checks if contains apropriate data, if yes loads data.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -