📄 demo_svm.html
字号:
<html><head> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1"> <title>demo_svm.m</title><link rel="stylesheet" type="text/css" href="../../m-syntax.css"></head><body><code><span class=defun_kw>function</span> <span class=defun_out>result </span>= <span class=defun_name>demo_svm</span>(<span class=defun_in>action,hfigure,varargin</span>)<br><span class=h1>% DEMO_SVM Demo on Support Vector Machines.</span><br><span class=help>%</span><br><span class=help>% <span class=help_field>Synopsis:</span></span><br><span class=help>% demo_svm</span><br><span class=help>%</span><br><span class=help>% <span class=help_field>Description:</span></span><br><span class=help>% DEMO_SVM demonstrates algorithms training the binary </span><br><span class=help>% SVM classifier L1-soft and L2-soft margin [Vapnik95]</span><br><span class=help>% [Cris00]. The input training vectors must be 2-dimensional </span><br><span class=help>% and can be interactively created by the user.</span><br><span class=help>%</span><br><span class=help>% Following algorithms can be tested:</span><br><span class=help>%</span><br><span class=help>% - Sequential Minimal Optimizer (SMO) for L1-norm soft margin.</span><br><span class=help>% - QP solver (quadprog) used to train SVM with L2-norm soft margin.</span><br><span class=help>% - Kernel Perceptron for separable hyperplane.</span><br><span class=help>%</span><br><span class=help>% <span class=help_field>Control:</span></span><br><span class=help>% Algorithm - algorithm for testing.</span><br><span class=help>% Kernel - non-linear kernel.</span><br><span class=help>% Kernel argument - argument of the non-linear kernel.</span><br><span class=help>% C-constant - trade-off (regularization) constant.</span><br><span class=help>% parameters - parameters of the selected algorithm.</span><br><span class=help>% background - if selected then the background color</span><br><span class=help>% denotes the sign and the intenzity denotes the value </span><br><span class=help>% of the found decision function.</span><br><span class=help>%</span><br><span class=help>% FIG2EPS - exports screen to the PostScript file.</span><br><span class=help>% Load data - loads input training sets from file.</span><br><span class=help>% Create data - calls program for creating point sets.</span><br><span class=help>% Reset - clears the screen.</span><br><span class=help>% Train SVM - trains and displays the SVM classifer.</span><br><span class=help>% Info - calls the info box.</span><br><span class=help>% Close - close the program.</span><br><span class=help>%</span><br><span class=help>% See also </span><br><span class=help>% SMO, SVMQUADPROG, KPERCEPTR.</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>% 2-june-2004, VF</span><br><span class=help1>% 18-July-2003, VF</span><br><span class=help1>% 6-march-2002, V.Franc</span><br><span class=help1>% 23-oct-2001, V.Franc</span><br><br><hr>BORDER=0.2; <span class=comment>% minimal space between axis and points</span><br>DATA_IDENT=<span class=quotes>'Finite sets, Enumeration'</span>; <span class=comment>% file identifier</span><br>ALGOS=[<span class=quotes>'SMO (L1) '</span>;...<br> <span class=quotes>'QUADPROG (L2) '</span>;...<br> <span class=quotes>'Kernel-Perceptron '</span>];<br>KERNELS=[<span class=quotes>'Linear '</span>;...<br> <span class=quotes>'Polynomial'</span>;...<br> <span class=quotes>'RBF '</span>];<br><br>SMO_PARAM = <span class=quotes>'epsilon,tolerance'</span>;<br>DEF_SMO_PARAM = <span class=quotes>'1e-3,1e-3'</span>;<br>KERNELSK_PARAM = <span class=quotes>'epsilon,iter_limit'</span>;<br>DEF_KERNELSK_PARAM = <span class=quotes>'1e-3,inf'</span>;<br>KPERCEPTR_PARAM = <span class=quotes>'tmax'</span>;<br>DEF_KPERCEPTR_PARAM = <span class=quotes>'inf'</span>;<br><br><span class=comment>% if number of arguments is less then 1, that means first call of this</span><br><span class=comment>% function. Every other calls set up at least argument action</span><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 =======</span><br><br> <span class=comment>% == Figure =============================================</span><br> left=0.1;<br> width=0.8;<br> bottom=0.1;<br> height=0.8;<br> hfigure=<span class=graph>figure</span>(<span class=quotes>'Name'</span>,<span class=quotes>'Support Vector Machines'</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>'Units'</span>,<span class=quotes>'normalized'</span>, ...<br> <span class=quotes>'tag'</span>,<span class=quotes>'demo_svm'</span>);<br><br> <span class=comment>% == Axes =========================================</span><br> left=0.1;<br> width=0.65;<br> bottom=0.35;<br> height=0.60;<br> haxes=<span class=graph>axes</span>(...<br> <span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>, ...<br> <span class=quotes>'UserData'</span>,[],...<br> <span class=quotes>'Position'</span>,[left bottom width height]);<br> xlabel(<span class=quotes>'feature x'</span>);<br> ylabel(<span class=quotes>'feature y'</span>);<br><br> <span class=comment>% == Comment window =================================</span><br> <span class=comment>% Comment Window frame</span><br> bottom=0.05;<br> height=0.2;<br> <span class=graph>uicontrol</span>( ...<br> <span class=quotes>'Style'</span>,<span class=quotes>'frame'</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>'BackgroundColor'</span>,[0.5 0.5 0.5]);<br><br> <span class=comment>% Text label</span><br> <span class=graph>uicontrol</span>( ...<br> <span class=quotes>'Style'</span>,<span class=quotes>'text'</span>, ...<br> <span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>, ...<br> <span class=quotes>'Position'</span>,[left height-0.01 width 0.05], ...<br> <span class=quotes>'BackgroundColor'</span>,[0.5 0.5 0.5], ...<br> <span class=quotes>'ForegroundColor'</span>,[1 1 1], ...<br> <span class=quotes>'String'</span>,<span class=quotes>'Comment Window'</span>);<br><br> <span class=comment>% Edit window</span><br> border=0.01;<br> hconsole=<span class=graph>uicontrol</span>( ...<br> <span class=quotes>'Style'</span>,<span class=quotes>'edit'</span>, ...<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>'Max'</span>,10, ...<br> <span class=quotes>'BackgroundColor'</span>,[1 1 1], ...<br> <span class=quotes>'Position'</span>,[left+border bottom width-2*border height-0.05], ...<br> <span class=quotes>'Enable'</span>,<span class=quotes>'inactive'</span>,...<br> <span class=quotes>'String'</span>,<span class=quotes>''</span>);<br><br><br> <span class=comment>% == Buttons ===========================================</span><br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -