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

📄 demo_linclass.m

📁 很好的matlab模式识别工具箱
💻 M
📖 第 1 页 / 共 3 页
字号:
function result = demo_linclass(action,hfigure,varargin)% DEMO_LINCLASS Demo on the algorithms learning linear classifiers.%% Synopsis:%  demo_linclass%% Description:%  DEMO_LINCLASS demonstrates use of the algorithms which find %  linear decision hyperplane between two (dichotomy)%  vector sets. The demo requires 2D input training data.%%  The program vizualizes found hyperplane in the current %  algorithm step. The missclassified vector used by the%  demonstrated iterative algorithms for update is vizualized%  as well. Text description of the found solution is%  printed at the bottom part of window.%%  Following algorithms can be tested:%%  Perceptron  - Perceptron learning rule (see 'help perceptron').%  Kozinec     - Kozinec's algorithm (see 'help ekozinec', eps=-1). %  e-Kozinec   - Kozinec's algorithm finding eps-optimal hyperplane%                (see 'help ekozinec', eps > 0).%  Linear SVM   - Linear Supprot Vector Machines for separable data%                (see 'help smo', C=inf, ker='linear').%% Control:%  Algorithm  - Dselects algorithm for testing.%  Epsilon    - Input parameter of 'ekozinec' algorithm %               (see 'help ekozinec').%  Iterations - Number of iterations in one step.%  Animation  - Enables/dissables animation - smooth changeover %               between two algorithm states.%%  FIG2EPS     - Exports screen to the PostScript file.%  Load data   - Loads input training data from file.%  Create data - Invokes program for creating training data.%  Reset       - Sets the algorithm to the initial state.%  Play        - Runs the algorithm.%  Stop        - Stops the running algorithm.%  Step        - Perform one step of the algorithm.%  Info        - Invoke the info box.%  Close       - Close the program.%% See also %  PERCEPTRON, EKOZINEC, SVM.%% 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:% 19-sep-2003, VF% 17-Feb-2003, VF% 24. 6.00 V. Hlavac, comments polished.% 11-dec-2000 V. Franc, a little increasing of code readibility% 15-dec-2000LINE_WIDTH=1;        % width of separation lineANIM_STEPS=10;       % number of steps during the line animationBORDER=0.2;          % minimal space between axis and points%DATA_IDENT='Finite sets, Enumeration';  % file identifierALGOS=['Perceptron';'Kozinec   ';'e-Kozinec ';  'LinearSVM '];WRONGPOINT_SIZE = 13;% 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 =======   % == Figure =============================================   left=0.1;   width=0.8;   bottom=0.1;   height=0.8;   hfigure=figure('Name','Linear discriminant function', ...      'Visible','off',...    'NumberTitle','off', ...      'Units','normalized', ...      'Position',[left bottom width height],...      'Units','normalized', ...      'tag','Demo_Linclass',...      'RendererMode','manual');   % == Axes =========================================   left=0.1;   width=0.65;   bottom=0.35;   height=0.60;   haxes1=axes(...       'Units','normalized', ...      'Box','on', ...      'DrawMode','fast',...      'UserData',[],...      'Position',[left bottom width height]);   xlabel('feature x_1');   ylabel('feature x_2');   % == 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_linclass(''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', ...      'Callback','demo_linclass(''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_linclass(''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_linclass(''reset'',gcf)');   % Creat data   bottom=bottom+1.5*height;    hbtcreat = uicontrol(...      'Units','Normalized', ...      'ListboxTop',0, ...        'Position',[left bottom width height], ...      'String','Create data', ...      'Callback','demo_linclass(''creatdata'',gcf)');   % Load data   bottom=bottom+1*height;    hbtload = uicontrol(...      'Units','Normalized', ...      'ListboxTop',0, ...        'Position',[left bottom width height], ...      'String','Load data', ...      'Callback','demo_linclass(''getfile'',gcf)');   % == 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 height], ...      'String','Algorithm');   % popup menu   bottom=bottom-height;   hpualgo=uicontrol( ...      'Style','popup', ...      'Units','normalized', ...      'CallBack','demo_linclass(''epshandler'',gcf)',...      'Position',[left bottom width height], ...      'String',ALGOS);   % == Edit line ========================================   % epsilon   bottom=bottom-1.2*height;   htxeps=uicontrol( ...      'Style','text', ...      'Units','normalized', ...      'Position',[left bottom width 0.9*height], ...      'Enable','off',...      'String','epsilon');   bottom=bottom-height;   hedeps = uicontrol(...    'Units','normalized', ...      'ListboxTop',0, ...        'Position',[left bottom width height], ...      'Style','edit',...      'Enable','off',...      'CallBack','demo_linclass(''epshandler'',gcf)',...      'String','1e-2');   % # of iterations   bottom=bottom-1.1*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',...      'CallBack','demo_linclass(''iterhandler'',gcf)',...      'String','1');   % == Check boxes ==============================================   % Make check box to determine if a line will be drawn in one    % step or smooth plot.   bottom=bottom-height*1.2;    hxbanim = uicontrol(...    'Style','checkbox', ...    'Units','normalized', ...    'ListboxTop',0, ...    'Position',[left bottom width height], ...    'String','Animation');    % ============================================================   % Store handlers   handlers=struct(...      'line',struct('handler',-1,'alpha',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,...      'editer',hediter,...      'edeps',hedeps,...      'txeps',htxeps,...      'axes1',haxes1,...      'xbanim',hxbanim);   set(hfigure,'UserData',handlers)   % Reset   demo_linclass('reset',hfigure);   % Put figure on desktop   set(hfigure,'Visible','on');   drawnow;case 'iterhandler'   % == Handler for edit line Iterations ===============   h=get(hfigure,'UserData');   iter=round(str2num(get(h.editer,'String')));   if isempty(iter) | iter < 1, iter=1; end   set(h.editer,'String',num2str(iter));case 'epshandler'   % == Handler for edit line Epsilon =======================   h=get(hfigure,'UserData');   % if algorithm e-Kozinec is selected then ...   if get(h.pualgo,'Value')==3,      set(h.edeps,'Enable','on');      set(h.txeps,'Enable','on');      epsil=str2num(get(h.edeps,'String'));      if epsil < 0,         epsil=1;         set(h.edeps,'String',num2str(epsil));      end   else      set(h.edeps,'Enable','off');      set(h.txeps,'Enable','off');   endcase 'creatdata'   % == Invoke data set creator ================================   createdata('finite',2,'demo_linclass','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 check2ddata(pathname),      file.pathname=pathname;      file.path=path;      file.name=name;      set(h.btload,'UserData',file);      demo_linclass('loadsets',hfigure);      demo_linclass('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 appropriate data,    % if yes loads data.   h=get(hfigure,'UserData');   [name,path]=uigetfile('*.mat','Open file');   if name~=0,      file.pathname=strcat(path,name);      file.path=path;      file.name=name;      if check2ddata(file.pathname),%      if checkdat(file.pathname,DATA_IDENT,2,[0 0])==1,         set(h.btload,'UserData',file);         demo_linclass('loadsets',hfigure);

⌨️ 快捷键说明

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