addpath liblinear-1.93-fw\matlab\

%% data
X = randn(1000,150);
X = X*rand(150,200);
a = [rand(100,1);rand(100,1)*.1];
a = a/sum(a);
Y0 = X*a+randn(1000,1)*5;
Y = sign(Y0)*.5+1.5;
Xtr = X(1:500,:);
Xte = X(501:1000,:);
Y0tr = Y0(1:500); % for regression
Y0te = Y0(501:1000);
Ytr = Y(1:500);
Yte = Y(501:1000);

%% classification
ftPenal = [ones(1,100)*1,ones(1,100)*10];
ftPenal = ftPenal/mean(ftPenal);
param = struct('ftPenal',ftPenal,'lambda',100000); % LR

model = classf_lr_fw_tr(Xtr,Ytr,param);
[pred, prob] = classf_lr_fw_te(model,Xte);
nnz(pred==Yte)/size(Xte,1)

param = struct('ftPenal',ftPenal,'c',.00001); % SVM
model = classf_svm_fw_tr(Xtr,Ytr,param);
[pred, prob] = classf_svm_fw_te(model,Xte);
nnz(pred==Yte)/size(Xte,1)

%% regression
ftPenal = [ones(1,100)*1,ones(1,100)*10];
ftPenal = ftPenal/mean(ftPenal);
param = struct('ftPenal',ftPenal,'lambda',10000); % ridge
model = regress_ridge_fw_tr(Xtr,Y0tr,param);
[pred] = regress_ridge_fw_te(model,Xte);
sqrt(mean((pred-Y0te).^2))

param = struct('ftPenal',ftPenal,'c',.000001); % SVR
model = regress_svr_fw_tr(Xtr,Y0tr,param);
[pred] = regress_svr_fw_te(model,Xte);

sqrt(mean((pred-Y0te).^2))