clc; clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code to generate Figure 2 : LIDAR data set %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load LIDAR data set
load('lidar.mat')
% Make a model structure
model = initlssvm(x,y,[],[],'gauss_kernel');
% Tune the model via 10-fold L_2 cross-validation
model = tunelssvm(model,'crossval');
% Train the final model
model = trainlssvm(model);
% Visualize the result
model = plotlssvm(model);
xlabel('range'); ylabel('log ratio')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc; clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code to generate Figure 3 : NBA data set %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load('nba.mat')
model = initlssvm(x,y,[],[],'gauss_kernel');
model = tunelssvm(model,'leaveoneout');
model = plotlssvm(model);
axis([7 42 160 205 0.2 0.75])
xlabel('Minutes per game')
ylabel('Height (cm)')
zlabel('Points per minute')
% Create contour plot
figure(2)
model = plotlssvm(model,'contour');
xlabel('Minutes per game')
ylabel('Height (cm)')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc; clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code to generate Figure 4 : Robust regression %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X = -5+10*rand(250,1);
epsilon = 0.35;
sel = rand(length(X),1)>epsilon;
Y = sinc(X)+sel.*normrnd(0,.1,length(X),1)+(1-sel).*trnd(1,length(X),1);
model = initlssvm(X,Y,[],[],'gauss_kernel');
model = tunelssvm(model,'rcrossval',{10,'mae'},'wmyriad');
% model = tunelssvm(model,'rcrossval',{10,'mae'},'whuber');
% model = tunelssvm(model,'rcrossval',{10,'mae'},'whampel');
% model = tunelssvm(model,'rcrossval',{10,'mae'},'wlogistic');
model = robustlssvm(model);
model = plotlssvm(model);
% plot true function
Xs = sort(X);
hold all; plot(Xs,sinc(Xs));
% Create right panel of Figure 4
figure(2)
model = plotlssvm(model);
hold all; plot(Xs,sinc(Xs));
axis([-5 5 -1.5 1.5])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc; clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code to generate Figure 5 : Confidence intervals %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load('fossil.mat')
model = initlssvm(x,y,[],[],'gauss_kernel');
model = tunelssvm(model,'crossval');
model = trainlssvm(model);
model = plotlssvm(model);
hold all;
ci = cilssvm(model,0.05,'pointwise');
fill([x;flipud(x)],[ci(:,1);flipud(ci(:,2))],'g','FaceAlpha',0.5,'EdgeAlpha',1,'EdgeColor','w');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc; clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code to generate Figure 6 : heteroscedastic toy example %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x = linspace(-5,5,300)';
y = sin(x)+sqrt(0.05*x.^2+0.01).*randn(300,1);
model = initlssvm(x,y,[],[],'gauss_kernel');
model = tunelssvm(model,'crossval',{10,'mae'});
model = trainlssvm(model);
model = plotlssvm(model);
hold all;
ci = cilssvm(model,0.05,'simultaneous','heteroscedastic');
fill([x;flipud(x)],[ci(:,1);flipud(ci(:,2))],'g','FaceAlpha',0.5,'EdgeAlpha',1,'EdgeColor','w');
plot(x,sin(x),'k','LineWidth',2)
clc; clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code to generate Figure 7 : additive toy model %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X = rand(300,12);
Y = 10*sin(pi*X(:,1))+20*(X(:,2)-0.5).^2+10*X(:,3)-5*X(:,4)+randn(300,1);
model = initlssvm(X,Y,[],[],'gaussadd_kernel','multiple');
model = tunelssvm(model,'crossval',{10,'mae'});
model = trainlssvm(model);
model = plotlssvmadd(model);
clc; clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code to generate Figure 8 : diabetes data %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load('diabetes.mat')
model = initlssvm([age basedef],Cpeptide,[],[],'gaussadd_kernel','multiple');
model = tunelssvm(model,'crossval',{6,'mae'});
model = plotlssvmadd(model,{'age','base deficit'});
clc; clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code to generate Figure 9a : Beluga data set %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load('beluga.mat')
model = initlssvm(period,nursingtime,[],[],'gauss_kernel');
% First, model selection accounting for correlation
model = tunelssvm(model,'crossval2lp1',{'mse'});
plotlssvm(model); hold on;
% second classical leave-one-out CV
model = tunelssvm(model,'leaveoneout',{'mse'});
Yhat = simlssvm(model,period);
plot(period,Yhat,'g-')
xlabel('Period'); ylabel('Nursing time (s)')
clc; clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code to generate Figure 9b : US birth rate data set %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load('birth.mat')
model = initlssvm(year,birthrate,[],[],'gauss_kernel');
% First, model selection accounting for correlation
model = tunelssvm(model,'crossval2lp1',{'mse'});
plotlssvm(model); hold on;
% second classical leave-one-out CV
model = tunelssvm(model,'leaveoneout',{'mse'});
Yhat = simlssvm(model,year);
plot(year,Yhat,'g-')
xlabel('Year'); ylabel('Birth rate')
%
%EOF
%