Sparse support vector machine
\begin{equation} \min_{(\mathbf{w};b)\in\mathbb{R}^{n+1}}~\frac{1}{2}\parallel \mathbf{w} \parallel^2 + C \sum_{i=1}^m\ell\left(1-y_i(b+ \mathbf{a}_i^\top\mathbf{w})\right) \tag{SVM} \end{equation}
◻️ Step function regularized SVM \begin{equation} \min_{(\mathbf{w};b)\in\mathbb{R}^{n+1}}~\frac{1}{2}\parallel \mathbf{w} \parallel^2 + C \sum_{i=1}^m\mathrm{step}\left(1-y_i(b+ \mathbf{a}_i^\top\mathbf{w})\right) \tag{L01SVM} \end{equation}
◻️ Sparsity constrained quadratic kernel-based SVM \begin{equation} \min_{\boldsymbol{\alpha}\in\mathbb{R}^{m}}~\frac{1}{2} \boldsymbol{\alpha}^\top \mathbf{Q} \boldsymbol{\alpha} +\frac{1}{2}\sum_{i=1}^m h_{cC}(\alpha_i) -\mathbf{e}^\top\boldsymbol{\alpha}, ~~~~ \text{s.t.} ~~\mathbf{y}^\top\boldsymbol{\alpha}=0,~\parallel \boldsymbol{\alpha} \parallel_0\leq s \tag{SCSVM} \end{equation}
According to the Representer Theorem, optimal solution $ \mathbf{w}^* $ to (SVM) and optimal solution $\boldsymbol{\alpha}^* $ to the dual SVM satisfy $ \mathbf{w}^* = \sum_{i=1}^m \alpha_i^* y_i \mathbf{a}_i $. The training vectors $ \mathbf{a}_i $ corresponding to nonzero $ \alpha_i^* $ are known as support vectors. Therefore, both models (SFRSVM) and (SCSVM) enable the reduction of support vectors.
NM01 - S Zhou, L Pan, N Xiu, and H Qi, Quadratic convergence of smoothing Newton's method for 0/1 loss optimization, SIOPT, 31:3184-3211, 2021.NSSVM - S Zhou, Sparse SVM for sufficient data reduction, IEEE TPAMI, 44:5560-5571, 2022.
clc; close all; clear all; addpath(genpath(pwd));
load dhrb.mat;
load dhrbclass.mat;
[m0,n] = size(A);
A = normalization(A,2); % data normalization
m = ceil(0.9*m0); % data splition
Train = randperm(m0,m);
Ttest = setdiff(1:m0,Train);
Atrain = A(Train,:);
Atest = A(Ttest,:);
ytrain = y(Train,:);
ytest = y(Ttest);
t = 1;
pars.C = 0.25;
solver = {'NM01','NSSVM'};
out = SSVMpack(Atrain,ytrain,solver{t},pars);
acc = accuracy(Atrain,out.w,ytrain);
tacc = accuracy(Atest,out.w,ytest);
fprintf(' Training Time: %5.3fsec\n',out.time);
fprintf(' Training Size: %dx%d\n',size(Atrain,1),size(Atrain,2));
fprintf(' Training Accuracy: %5.2f%%\n', acc*100);
fprintf(' Testing Size: %dx%d\n',size(Atest,1),size(Atest,2));
fprintf(' Testing Accuracy: %5.2f%%\n',tacc*100);
fprintf(' Number of Support Vectors: %d\n',out.sv);
function out = SSVMpack(A,y,solver,pars)
% -------------------------------------------------------------------------
% This package aims to solve the binary classification problems
% Inputs:
% A: The smaple matrix \in R^{m-by-n}, (REQUIRED)
% y: The binary label \in R^m, b_i\in{-1,1} (REQUIRED)
% solver: A text string, can be one of {'NM01','NSSVM'} (REQUIRED)
% pars: Parameters are optional (OPTIONAL)
% ------------- For NSSVM --------------------------------------
% pars.alpha -- Starting point in \R^m (default zeros(m,1))
% pars.s0 -- The initial sparsity (default n(log(m/n))^2))
% pars.C -- A positive scalar in (0,1] (default 1/4)
% pars.c -- A positive scalar in (0,1] (default 1/40)
% pars.tune -- Tune the sparsity level
% Do not tune the sparsity level (default 0)
% pars.maxit -- Maximum number of iterations (default 1000)
% pars.tol -- Tolerance of the halting criteria (default 1e-4)
% pars.disp -- Display results for each step (default 1)
% Do not display results for each step
% ------------- NM01 -------------------------------------------
% pars.x0 -- The initial point (default zeros(n,1))
% pars.C -- The penalty parameter (default 1)
% pars.tau -- A useful paramter (default 5)
% pars.maxit -- Maximum number of iterations (default 1000)
% pars.tol -- Tolerance of the halting criteria (default 1e-4)
% pars.disp -- Display results for each step (default 1)
% Do not display results for each step
% -------------------------------------------------------------------------
% Outputs:
% out.w: The solution of the primal problem, i.e., the classifier
% out.sv: Number of support vectors
% out.time CPU time
% out.iter: Number of iterations
% Out.acc: Classification accuracy
% -------------------------------------------------------------------------
% Send your comments and suggestions to <slzhou2021@163.com>
% Warning: Accuracy may not be guaranteed !!!!!!
% -------------------------------------------------------------------------