[Home]


TLMM

A Demo Matlab code (TL1SVMMM_lin.mat) for "TLMM: A fast Majorize-Minimize algorithm for truncated loss classifiers". (Click [Here] to download the complete matlab codes.)


Reference

Xiaofang Li, Lingwei Huang, Yuanhai Shao. TLMM: A fast Majorize-Minimize algorithm for truncated loss classifiers. Submitted, 2022. (Xiaofang Li and Lingwei Huang are co-first authors.)(Corresponding author: Yuanhai Shao.)


Main Function

Note: Some functions for the basic model of TL1SVMMM_lin.mat are required: the mex files of "train.c" and "predict.c" in Liblinear-2.430 toolbox. See more details in the download file TLMM_code.zip

function [PredictY,MOD] = TL1SVMMM_lin( TestX , Train , Para )
% Solving [L2-norm Truncated Hinge SVC] via TLMM algorithm. % min 0.5*w'*w + p1*e'*min(max(1-Y.*(X*w+b),0),eps) % Variables: [w,b] in R^{n+1}. % ______________________________ Input _______________________________ % Train.X - m x n matrix, explanatory variables in training data % Train.Y - m x 1 vector, response variables in training data % TestX - mt x n matrix, explanatory variables in testing data % Para.C - the regularization parameter % Para.s - the parameter s = {s|eps<1-s}, eps is the truncated value % ______________________________ Output ______________________________ % PredictY - mt x 1 vector, predicted response variables for testing data % MOD - model related info: n_iter, tr_time, etc. % % Written by Xiaofang Li, Lingwei Huang, lateset update: 2022.04.14. %
%% Usage
% load Echo.mat X Y % %load Vehicle.mat X Y % Train.X = X; Train.Y = Y; % TestX = X; TestY = Y; % Para.C = 2^5; % Para.s = -1; % [PredictY,MOD] = TL1SVMMM_lin( TestX , Train , Para) ; % Accuracy = sum(PredictY == TestY)/length(TestY); %
%% Input
X0 = Train.X; Y0 = Train.Y; Maxiter = 500; C = Para.C; s = Para.s; tol_w = 1e-6; tol_obj = 1e-8; flag = 0; tt = tic;
%% Initialization
obj = -1; [m,n]= size(X0); wk = ones(n+1,1); YX = Y0 .* [X0,ones(m,1)]; ob = @(w,yf,C) 0.5*(w'*w) + C*sum(max(1-yf,0)); lib_opt = sprintf('-s 3 -B 1 -c %f -q',C); w = wk;
%% MM iteration
for iter = 1 : Maxiter yf = YX*wk; % eq(15) ads = adjust_s(s, yf, Y0); ind = yf > ads; % eq(16) yf( yf < ads ) = ads; objk = ob(wk,yf,C); if abs(objk-obj)/abs(obj) < tol_obj, flag = 1; break, end X = X0(ind,:); Y = Y0(ind); % The basic model of TLMM algorithm model = train( Y , sparse(X) , lib_opt ); % eq(17) wk = model.w'; if norm(w-wk)/norm(w) < tol_w, break, end w = wk; obj = objk; end tr_time = toc(tt);
%% Prediction
[mt,~] = size(TestX); [PredictY,~,~] = predict(ones(mt,1), sparse(TestX),model,'-q');
%% Output
MOD.n_iter = iter - flag; MOD.tr_time = tr_time;
end
Contacts


Any question or advice please email to Xiaofang Li (320354062@qq.com), Lingwei Huang (xhuanglw@163.com) or Yuanhai Shao (shaoyuanhai21@163.com).