function [model] = regress_svr_fw_tr(X,Y,param)
%	linear svr with feature weighting. See classf_lr_fw_tr for meanings of the parameters
%	Depends on the modified liblinear toolbox. Please first run make.m in
%	liblinear-1.93-fw/matlab to build mex files for your system, then add
%	the folder to your path.

% Please refer to Ke Yan et al., Improving the transfer ability of 
% prediction models for electronic noses, Sensors and Actuators	B: Chemical, 2015
%	Copyright 2015 YAN Ke, Tsinghua Univ. http://yanke23.tk, xjed09@gmail.com

[nSmp,nFt] = size(X);

% default parameters
c = 1;
ftPenal = ones(1,nFt); % penalization weight of each feature. if ftPenal(i)
% is large, the i'th feature will be less relied in the model

defParam

type = sprintf('-s 11 -q -c %f -B 1',c); % -s should be 11

model = train(Y, sparse(X), ftPenal, type);

end

%{
options:
-s type : set type of solver (default 1)
  for multi-class classification
	 0 -- L2-regularized logistic regression (primal)
	 1 -- L2-regularized L2-loss support vector classification (dual)
	 2 -- L2-regularized L2-loss support vector classification (primal)
	 3 -- L2-regularized L1-loss support vector classification (dual)
	 4 -- support vector classification by Crammer and Singer
	 5 -- L1-regularized L2-loss support vector classification
	 6 -- L1-regularized logistic regression
	 7 -- L2-regularized logistic regression (dual)
  for regression
	11 -- L2-regularized L2-loss support vector regression (primal)
	12 -- L2-regularized L2-loss support vector regression (dual)
	13 -- L2-regularized L1-loss support vector regression (dual)
-c cost : set the parameter C (default 1)
-p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)
-e epsilon : set tolerance of termination criterion
	-s 0 and 2
		|f'(w)|_2 <= eps*min(pos,neg)/l*|f'(w0)|_2,
		where f is the primal function and pos/neg are # of
		positive/negative data (default 0.01)
	-s 11
		|f'(w)|_2 <= eps*|f'(w0)|_2 (default 0.001) 
	-s 1, 3, 4 and 7
		Dual maximal violation <= eps; similar to libsvm (default 0.1)
	-s 5 and 6
		|f'(w)|_inf <= eps*min(pos,neg)/l*|f'(w0)|_inf,
		where f is the primal function (default 0.01)
	-s 12 and 13\n"
		|f'(alpha)|_1 <= eps |f'(alpha0)|,
		where f is the dual function (default 0.1)
-B bias : if bias >= 0, instance x becomes [x; bias]; if < 0, no bias term added (default -1)
-wi weight: weights adjust the parameter C of different classes (see README for details)
-v n: n-fold cross validation mode
-q : quiet mode (no outputs)
%}