% This routine automatically tunes c and sigmasq for an SVM formulation % that uses quadratic penalties for margin violations. The tuning is done % by minimizing the Radius/Margin function. % % function [c,sigmasq,b,testerr]=npa(infile,outfile1,outfile2,n,m,mtest) % % Description of input variables... % % infile - The name of the file containing the examples. Note % that each example has to be arranged in the following % order: % x1 x2 ... xn class-label % the class label should be either -1 or +1. The first m % rows should have the training examples and the next mtest % rows should have the test examples; see m, mtest below. % % outfile1 - The name of the first output file. This output file will % contain information about the final support vectors. % Each row is a support vector stored in the following % manner: % class-label alpha x1 x2 ... xn % % outfile2 - Temporary output file that contains some useful information % on what happened in the solution process. % % n - The dimension of the input vector. % % m - Number of training examples. % % mtest - Number of test examples. % % The code has been written for n < 61 and (m+mtest) < 9001. % % Description of output variables... % % c - Optimal value of c. % % b - This b value determines the location of the separating % plane in the high-dimensional kernel space. % % sigmasq - Optimal value of sigmasq. % % testerr - Percentage error on the test set. % % Note: The final classification function is as usual: % sum over support vectors of class-label*alpha*Kernel + b, % where the kernel function is: % K(x,xbar) = exp(-0.5*normsq(x-xb)/sigmasq) % function [c,sigmasq,b,testerr]=npa(infile,outfile1,outfile2,n,m,mtest) error(nargchk(6,6,nargin)); nargin % % checking for the type of arguments % if ~ischar(infile) | ~ischar(outfile1) | ~ischar(outfile2) error('filenames should be single-quoted string'); end [d,e] = size(n); if e ~= 1 error('Dimension of the input vector should be a scalar'); end [d,e] = size(m); if e ~= 1 error('Number of training examples should be a scalar'); end [d,e] = size(mtest); if e ~= 1 error('Number of test examples should be a scalar'); end % infile outfile1 outfile2 n m mtest % [c,sigmasq,b,testerr]=npa_fort(infile,outfile1,outfile2,n,m,mtest) end