[Home]
TLRM
A Demo Matlab code (L2n_TeL2SVR_M.mat) for "Large Scale Non-convex Regression with Truncated Loss via Majorization-Minimization Algorithm" (TLRM). (Click [Here] to download the matlab codes for other methods in TLRM.)
Reference
Ling-Wei Huang, Yuan-Hai Shao, Xiao-Jing Lv, Chun-Na Li. Large Scale Non-convex Regression with Truncated Loss via Majorization-Minimization Algorithm. Submitted to European Journal of Operational Research, EJOR-D-23-02033.
Main Function
Required: the mex files "LIB_train_L2.mexw64","LIB_predict_L2.mexw64" of LIBSVM, or "Linear_train.mexw64", "Linear_predict.mexw64" of Liblinear.
[ PredictY , model ] = L2n_TeL2SVR_M( ValX , Trn , Para )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % Solving L2-norm Truncated-eL2-loss SVR by TLRM
% % min 0.5*w'*w + C * min{ L2(aerr) , L2(mu) }
% % s.t. L2(z) = max{z-eps,0}^2
% % aerr = |Y-(X*w+b)|
% % Ref - Ling-Wei Huang, Yuan-Hai Shao*, Xiao-Jing Lv, Chun-Na Li.
% % Large Scale Non-convex Regression with Truncated Loss via Majorization-Minimization Algorithm.
% % Submitted to European Journal of Operational Research, 2024.
% % Site - http://www.optimal-group.org/Resources/Code/TLRM.html.
% _______________________________ Input _______________________________
% Trn.X - m x n matrix, explanatory variables in training data
% Trn.Y - m x 1 vector, response variables in training data
% ValX - mt x n matrix, explanatory variables in Validation data
% Para.p1 - the emperical risk parameter C
% Para.p2 - the eps-insensitive parameter
% Para.p3 - the truncated related parameter for residual or loss
% Para.kpar - kernel para, include type and para value of kernel
% ______________________________ Output ______________________________
% PredictY - mt x 1 vector, predicted response variables for ValX
% model - model related info: w, b, nSV/wks, time, iter, etc.
%
% % Written by Ling-Wei Huang.
% % Latest Update: 2023.04.05.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Base Model Switch - control variable: BM
% % 0 -- LIBLINEAR_L2n_eL2SVR_primal (Default) [1b]
% % with bias in decision funciton, but NOT in objective funciton.
% % 1 -- LIBLINEAR_L2n_eL2SVR_primal [2b]
% % with bias in decision funciton, and in objective funciton.
% % 2 -- LIBLINEAR_L2n_eL2SVR_primal (Not recommanded) [0b]
% % NEITHER bias in decision funciton, NOR in objective funciton.
% % 3 -- LIBLINEAR_L2n_eL2SVR_dual [2b]
% % with bias in decision funciton, and in objective funciton.
% % 4 -- LIBLINEAR_L2n_eL2SVR_dual (Not recommanded) [0b]
% % NEITHER bias in decision funciton, NOR in objective funciton.
% % 5 -- LIBSVM_L2n_eL2SVR
% % kernel method can be used
% % 6 -- standard SVR_dual via QP
%% Usage
% load T14+c1+m200+1000+0+Uniform+IQR.mat
% Trn.X = X; Trn.Y = Y;
% ValX = X_t; ValY = Y_t;
% Para.p1 = 10^0;
% Para.rY = 0.5*range(Y);
% Para.iqr = iqr(Y);
% Para.p2 = 0.15;
% Para.p3 = 0.3;
% Para.kpar.ktype = "rbf";
% Para.kpar.kp1 = 2^6;
% [PredictY,model] = L2n_TeL2SVR_M( ValX , Trn , Para);
% RMSE = sqrt(sum((PredictY-ValY).^2)/length(ValY));
%% Input
X0 = sparse(Trn.X); Y0 = Trn.Y;
C = Para.p1;
epsl = Para.p2 * Para.rY;
mu=epsl+Para.p3 * Para.rY;
kpar = Para.kpar; ktype = kpar.ktype; kp1 = kpar.kp1;
BM = 0; if ktype~="lin", BM = 5; end
BMFun_trn = str2func("Linear_train");
BMFun_prd = str2func("Linear_predict");
switch BM
case 0
opt = sprintf('-s 11 -B 1 -R -c %f -p %f -q', C, epsl); % primal 1b
case 1
opt = sprintf('-s 11 -B 1 -c %f -p %f -q', C, epsl); % primal 2b
case 2
opt = sprintf('-s 11 -c %f -p %f -q', C, epsl); % primal 0b
case 3
opt = sprintf('-s 12 -B 1 -c %f -p %f -q', C, epsl); % dual 2b
case 4
opt = sprintf('-s 12 -c %f -p %f -q', C, epsl); % dual 0b
case 5
BMFun_trn = str2func("LIB_train_L2");
BMFun_prd = str2func("LIB_predict_L2");
switch ktype
case "lin"
opt = sprintf('-s 3 -t 0 -c %f -p %f -q', C, epsl);
case "poly"
gamma = 1; coef0 = 0; degree = kp1;
opt = sprintf('-s 3 -t 1 -c %f -p %f -g %f -r %f -d %f -q', C, epsl, gamma, coef0, degree);
case "rbf"
gamma = kp1;
opt = sprintf('-s 3 -t 2 -c %f -p %f -g %f -q', C, epsl, gamma);
case "sig"
gamma = kp1; coef0 = 0;
opt = sprintf('-s 3 -t 2 -c %f -p %f -g %f -r %f -h 0 -q', C, epsl, gamma, coef0);
case "pre"
opt = sprintf('-s 3 -t 4 -c %f -p %f -h 0 -q', C, epsl);
end
end
%% Initialization
tt = tic;
[m,n]= size(X0); em = ones(m,1);
switch BM
case {0,1,3} % ppd 122b
wbk = zeros(n+1,1);
case {2,4} % pd 0b
wbk = zeros(n,1);
case 5 % nonlinear
zm1 = zeros(m+1,1); aabk = zm1;
end
aerr = em;
%% Liblinear/Libsvm-based iter
for iter = 1 : 100
id_le = aerr <= mu;
if iter==1, wks=logical(em); else, wks=id_le; end % Good init
if min(aerr)>mu, wks=aerr<=prctile(aerr,50); end
X = X0(wks,:); Y = Y0(wks);
model = BMFun_trn( Y , X , opt );
aerr = abs( Y0 - BMFun_prd(em, X0, model, '-q') );
if BM == 5
aab = zm1;
tmp = zeros(length(Y),1);
tmp(model.sv_indices) = model.sv_coef;
aab(wks) = tmp;
idsv = aab~=0;
aab(end) = -model.rho;
else
wb = model.w';
end
if BM == 5
if norm(aabk - aab)/norm(aab) < 1e-6, break, end
aabk = aab;
else
if norm(wbk - wb)/norm(wb) < 1e-3, break, end
wbk = wb;
end
end
tr_time = toc(tt);
%% Prediction & Output
ValX = sparse(ValX); [mv,~] = size(ValX);
[PredictY,~,~] = BMFun_prd(ones(mv,1), ValX, model, '-q');
switch BM
case {0,1,3}
model.b = model.w(end);
model.w = model.w(1:end-1)'; % -B: w=[weight;bias]
model.n_SV = -1;
case 5
model.w = model.SVs' * model.sv_coef ;
model.b = -model.rho;
model.n_SV = model.totalSV;
model.ind_SV = idsv;
case {2,4}
model.b = 0;
model.w = model.w'; % -B: w=[weight;bias]
model.n_SV = -1;
end
model.tr_time = tr_time;
model.n_iter = iter;
model.n_wks = sum(wks); % working set final round
end
Contacts
Any question or advice please email to Ling-Wei Huang (xhuanglw@163.com).
- Last updated: Apr 14, 2024.