msmo.m

来自「很好用的统计模式识别工具箱」· M 代码 · 共 95 行

M
95
字号
function [malpha,mbias,nsv,kercnt] = msmo(X,I,ker,arg,C,epsilon,tolerance,info)% MSMO solves multiclass SVM problem by the SMO.% [malpha,mbias,nsv,kercnt] = msmo(X,I,ker,arg,C,epsilon,tolerance,info)%% MSMO solves multiclass Support Vector Problem problem %  by the use of Sequential Minimal Optimizer.%  The input K-class problem is decomposed onto %  K binary problems: i-th class against remaining (K-1)%  classes. The binary problems are solved by the use %  of the SMO which results to the K decision rules.%  % Mandatory inputs:%  X [NxL] contains L training N-dimensional patterns.%  I [1xL] labels of the patterns; integers from 1 to K.%  ker [string] kernel identifier (see "help smoc").%  arg [...] arguments of given kernel (see "help smoc").%  C [1x1] trade-off between maximal margin and training error.%% Optional inputs:%  epsilon [real] tolerance of KKT-conditions fulfilment %    (default is 0.001).%  tolerance [real] minimal change of optimized Lagrangeians %    (default is 0.001).%  info [int] if info is 1 then prints which decision rule is%    being built (default is 0).%% Output: %  malpha [KxL] found Lagrange multipliers.%  mbias [Kx1] found biases.%  nsv [int] number of SVs%  kercnt [int] number of kernel evaluations.%  % For instance malpha{i} and mbias{i} are the multipliers and% bias for i-th binary problem: i-th class against the others.%% See also MSVMCLASS, SMO, SVM.%% Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac% (c) Czech Technical University Prague, http://cmp.felk.cvut.cz% Modifications
%  21-Oct-2001, V.Franc%  18-September-2001, V. Franc, created% -- Processing of the input arguments ----------------if nargin < 5,   error('Not enough input arguments.');endif nargin < 6,   epsilon = 0.001;endif nargin < 7,   tolerance = 0.001;endif nargin < 8,   info = 0;end% -- Init variables -------------------------------K = max( I );    % maximal class label
L= size(X,2);% preallocate variablesmalpha=zeros(K,L);mbias=zeros( K,1 );% -- Build decision rules -------------------------------kercnt = 0;for i= 1:K,           if info == 1,      disp( sprintf('Building rule %d-th of %d.', i, K));   end     Idich=multi2dicho( I, i );      [malpha(i,:),mbias(i),nsv,akercnt]=smo(X,Idich,ker,arg,C,epsilon,tolerance);      kercnt = kercnt + akercnt;   endnsv = length( find( sum(malpha)));return;

⌨️ 快捷键说明

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