📄 demo_svm.html
字号:
<span class=quotes>'Position'</span>,[left bottom width 0.9*height], ...<br> <span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>,...<br> <span class=quotes>'String'</span>,SMO_PARAM);<br> bottom=bottom-height*.8;<br> hed_param = <span class=graph>uicontrol</span>(...<br> <span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>, ...<br> <span class=quotes>'ListboxTop'</span>,0, ...<br> <span class=quotes>'Position'</span>,[left bottom width height], ...<br> <span class=quotes>'Style'</span>,<span class=quotes>'edit'</span>,...<br> <span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>,...<br> <span class=quotes>'CallBack'</span>,<span class=quotes>'demo_svm('</span><span class=quotes>'param_handler'</span><span class=quotes>',gcf)'</span>,...<br> <span class=quotes>'String'</span>,DEF_SMO_PARAM);<br> <br><br> <span class=comment>% == Check boxes ==============================================</span><br> bottom=bottom-height*1.2;<br> hxb_background = <span class=graph>uicontrol</span>(...<br> <span class=quotes>'Style'</span>,<span class=quotes>'checkbox'</span>, ...<br> <span class=quotes>'Units'</span>,<span class=quotes>'normalized'</span>, ...<br> <span class=quotes>'ListboxTop'</span>,0, ...<br> <span class=quotes>'Position'</span>,[left bottom width height], ...<br> <span class=quotes>'String'</span>,<span class=quotes>'Background'</span>);<br><br> <span class=comment>% ============================================================</span><br> data=struct(...<br> <span class=quotes>'bt_close'</span>,hbt_close,...<br> <span class=quotes>'bt_train'</span>,hbt_train,...<br> <span class=quotes>'bt_reset'</span>,hbt_reset,...<br> <span class=quotes>'bt_info'</span>,hbt_info,...<br> <span class=quotes>'bt_load'</span>,hbt_load,...<br> <span class=quotes>'bt_creat'</span>,hbt_creat,...<br> <span class=quotes>'pu_algo'</span>,hpu_algo,...<br> <span class=quotes>'pu_kernel'</span>, hpu_kernel,...<br> <span class=quotes>'ed_arg'</span>, hed_arg,...<br> <span class=quotes>'tx_arg'</span>, htx_arg,...<br> <span class=quotes>'tx_cconst'</span>, htx_cconst,...<br> <span class=quotes>'ed_cconst'</span>, hed_cconst,...<br> <span class=quotes>'tx_param'</span>, htx_param,...<br> <span class=quotes>'ed_param'</span>, hed_param,...<br> <span class=quotes>'console'</span>,hconsole,...<br> <span class=quotes>'axes'</span>,haxes,...<br> <span class=quotes>'xb_background'</span>,hxb_background);<br> <span class=graph>set</span>(hfigure,<span class=quotes>'UserData'</span>,data );<br><br> <span class=comment>% Reset</span><br> demo_svm(<span class=quotes>'reset'</span>,hfigure);<br><br> <span class=comment>% Put figure on desktop</span><br> <span class=graph>set</span>(hfigure,<span class=quotes>'Visible'</span>,<span class=quotes>'on'</span>);<br> drawnow;<br> <br><span class=comment>%== Trains SVM and displays result ================================</span><br><span class=label>case</span> <span class=quotes>'train'</span><br> data = <span class=graph>get</span>( hfigure, <span class=quotes>'UserData'</span>);<br> <br> trn = <span class=graph>get</span>( data.<span class=graph>axes</span>, <span class=quotes>'UserData'</span> );<br> <br> <span class=keyword>if</span> isempty( trn ),<br> <span class=jump>return</span>;<br> <span class=keyword>end</span><br> <br> C = str2num(<span class=graph>get</span>( data.ed_cconst, <span class=quotes>'String'</span> ));<br> ker_inx = <span class=graph>get</span>( data.pu_kernel, <span class=quotes>'Value'</span> );<br> <span class=keyword>if</span> ker_inx == 1,<br> ker = <span class=quotes>'linear'</span>;<br> <span class=keyword>elseif</span> ker_inx == 2;<br> ker = <span class=quotes>'poly'</span>;<br> <span class=keyword>else</span> <br> ker = <span class=quotes>'rbf'</span>;<br> <span class=keyword>end</span><br> arg = str2num(<span class=graph>get</span>( data.ed_arg, <span class=quotes>'String'</span> ));<br> <br> [Alpha,bias] = svm_train( data, trn, ker, arg, C );<br> <br> <span class=comment>% focus on the axes</span><br> <span class=graph>axes</span>( data.<span class=graph>axes</span> );<br> <br> <span class=comment>% Clear axes</span><br> clrchild( data.<span class=graph>axes</span>);<br> <br> <span class=comment>% get options</span><br> options.background = <span class=graph>get</span>( data.xb_background, <span class=quotes>'Value'</span>); <br> <br> <span class=comment>% plot decision function</span><br> model.sv.X = trn.X;<br> model.sv.y = trn.I;<br> ppatterns(model.sv); <br> inx=find( Alpha ~= 0 );<br> model.sv.X = trn.X(:,inx);<br> model.sv.y = trn.I(:,inx);<br> model.Alpha = Alpha(:,inx)';<br> model.b = bias;<br> model.options.ker = ker;<br> model.options.arg = arg;<br> psvm( model, options );<br> <br><span class=comment>%== Handler for Algorithm popup menu ==========================</span><br><span class=label>case</span> <span class=quotes>'algo_handler'</span><br> data=<span class=graph>get</span>(hfigure,<span class=quotes>'UserData'</span>);<br> <br> <span class=comment>% which algorithm ?</span><br> <span class=keyword>switch</span> <span class=graph>get</span>(data.pu_algo, <span class=quotes>'Value'</span> )<br> <br> <span class=label>case</span> 1 <span class=comment>% SMO</span><br> <span class=graph>set</span>(data.tx_cconst,<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br> <span class=graph>set</span>(data.ed_cconst,<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br> <span class=graph>set</span>(data.tx_param,<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br> <span class=graph>set</span>(data.tx_param,<span class=quotes>'String'</span>,SMO_PARAM);<br> <span class=graph>set</span>(data.ed_param,<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br> <span class=graph>set</span>(data.ed_param,<span class=quotes>'String'</span>,DEF_SMO_PARAM);<br> <br><span class=comment>% case 2 % Matlab toolbox</span><br><span class=comment>% set(data.tx_cconst,'Enable','on');</span><br><span class=comment>% set(data.ed_cconst,'Enable','on');</span><br><span class=comment>% set(data.tx_param,'Enable','off');</span><br><span class=comment>% set(data.ed_param,'Enable','off');</span><br> <br><span class=comment>% case 3 % Kernel-SK</span><br> <span class=label>case</span> 2 <span class=comment>% Kernel-SK</span><br> <span class=graph>set</span>(data.tx_cconst,<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br> <span class=graph>set</span>(data.ed_cconst,<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br> <span class=graph>set</span>(data.tx_param,<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br> <span class=graph>set</span>(data.ed_param,<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br> <span class=graph>set</span>(data.tx_param,<span class=quotes>'String'</span>,KERNELSK_PARAM);<br> <span class=graph>set</span>(data.ed_param,<span class=quotes>'String'</span>,DEF_KERNELSK_PARAM);<br><span class=comment>% case 4 % Matlab toolbox</span><br><span class=comment>% set(data.tx_cconst,'Enable','on');</span><br><span class=comment>% set(data.ed_cconst,'Enable','on');</span><br><span class=comment>% set(data.tx_param,'Enable','off');</span><br><span class=comment>% set(data.ed_param,'Enable','off');</span><br><span class=comment>% case 5 % Kernel Perceptron</span><br> <span class=label>case</span> 3 <span class=comment>% Kernel Perceptron</span><br> <span class=graph>set</span>(data.tx_cconst,<span class=quotes>'Enable'</span>,<span class=quotes>'off'</span>);<br> <span class=graph>set</span>(data.ed_cconst,<span class=quotes>'Enable'</span>,<span class=quotes>'off'</span>);<br> <span class=graph>set</span>(data.tx_param,<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br> <span class=graph>set</span>(data.ed_param,<span class=quotes>'Enable'</span>,<span class=quotes>'on'</span>);<br> <span class=graph>set</span>(data.tx_param,<span class=quotes>'String'</span>,KPERCEPTR_PARAM);<br> <span class=graph>set</span>(data.ed_param,<span class=quotes>'String'</span>,DEF_KPERCEPTR_PARAM);<br> <span class=keyword>end</span><br> <br> <br><span class=comment>%== Handler for C-const edit line ===========================</span><br><span class=label>case</span> <span class=quotes>'cconst_handler'</span><br> data=<span class=graph>get</span>(hfigure,<span class=quotes>'UserData'</span>);<br><br> C = str2num(<span class=graph>get</span>(data.ed_cconst,<span class=quotes>'String'</span>));<br> <br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -