Skip to content
Snippets Groups Projects
Commit a1ac5a19 authored by Miroslav Shaltev's avatar Miroslav Shaltev
Browse files

separate sgtelib

parent 6644564d
Branches master
No related tags found
No related merge requests found
Showing
with 3 additions and 1218 deletions
AC_INIT(nomad, 3.7.2, miroslav.shaltev@shaltev.de) AC_INIT(nomad, 3.8.1, miroslav.shaltev@shaltev.de)
AC_PREREQ([2.63]) AC_PREREQ([2.63])
AC_CONFIG_HEADERS([config.h]) AC_CONFIG_HEADERS([config.h])
...@@ -51,6 +51,8 @@ if test "x$mpi" = "xtrue"; then ...@@ -51,6 +51,8 @@ if test "x$mpi" = "xtrue"; then
fi fi
NOMAD_ENABLE_MODULE([MPI],[mpi]) NOMAD_ENABLE_MODULE([MPI],[mpi])
PKG_CHECK_MODULES(SGTELIB, sgtelib)
AC_PROG_CPP AC_PROG_CPP
AC_CONFIG_FILES([Makefile src/Makefile docs/Makefile nomad.pc nomadmpi.pc]) AC_CONFIG_FILES([Makefile src/Makefile docs/Makefile nomad.pc nomadmpi.pc])
AC_OUTPUT AC_OUTPUT
X = [ 0 25 ;
0 50 ;
0 55 ;
0 57 ;
0 83 ;
0 92 ;
1 47 ;
1 48 ;
1 66 ;
1 75 ;
1 93 ;
1 96 ;
2 5 ;
2 8 ;
2 13 ;
2 25 ;
2 55 ;
2 57 ;
2 70 ;
2 75 ;
3 12 ;
3 34 ;
3 47 ;
3 62 ;
3 76 ;
3 84 ;
3 93 ;
4 1 ;
4 15 ;
4 20 ;
4 28 ;
4 29 ;
4 34 ;
4 35 ;
4 53 ;
4 78 ;
4 81 ;
4 89 ;
5 14 ;
5 16 ;
5 22 ;
5 24 ;
5 26 ;
5 38 ;
5 51 ;
5 59 ;
5 68 ;
]
XX = [
1 2.2 ;
2 1.5 ;
2 1.2 ;
4 3.4 ;
];
Z = [ 0 ;
0 ;
0 ;
0 ;
0 ;
0 ;
2209 ;
3481 ;
4356 ;
5625 ;
8649 ;
9216 ;
-50 ;
-128 ;
-338 ;
-1250 ;
-6050 ;
-6498 ;
-9800 ;
-11250 ;
432 ;
3468 ;
6627 ;
11532 ;
17328 ;
21168 ;
25947 ;
-4 ;
-900 ;
-1600 ;
-3136 ;
-3364 ;
-4624 ;
-4900 ;
-11236 ;
-24336 ;
-26244 ;
-31684 ;
980 ;
1280 ;
2420 ;
2880 ;
3380 ;
7220 ;
13005 ;
17405 ;
23120 ;
];
ZZ=[
2.5 ;
3.4 ;
3.5 ;
5.5 ;
];
close all
clear all
clc
output_dir = '.';
input_file = 'output_hartman3.txt';
output_file = [output_dir 'metric_comparison_hartman3.pdf'];
plot_metrics_comparison(input_file,output_file);
close all;
input_file = 'output_hartman6.txt';
output_file = [output_dir 'metric_comparison_hartman6.pdf'];
plot_metrics_comparison(input_file,output_file);
close all;
input_file = 'output_braninhoo.txt';
output_file = [output_dir 'metric_comparison_braninhoo.pdf'];
plot_metrics_comparison(input_file,output_file);
close all;
input_file = 'output_camelback.txt';
output_file = [output_dir 'metric_comparison_camelback.pdf'];
plot_metrics_comparison(input_file,output_file);
close all;
input_file = 'output_rosenbrock.txt';
output_file = [output_dir 'metric_comparison_rosenbrock.pdf'];
plot_metrics_comparison(input_file,output_file);
close all;
function plot_metrics_comparison(input_file,output_file)
% output_dir = '/home/bastien/Bureau/MUSU/MUSU_2015_01_01_WorkingPaper/figs/';
% input_file = 'output_hartman6.txt';
% output_dir = '/home/bastien/Bureau/MUSU/PAPER_OrderErrorForEnsembles/figs/';
% output_file = [output_dir 'metric_comparison_hartman6.pdf'];
%close all
texOptions = {'fontname','times','fontsize',14};
m_order = [1 2 3 4];
model_list = cell(0);
metric_list = cell(0);
tab = [];
fid = fopen(input_file);
line = fgetl(fid);
while ischar(line)
if isempty(line)
line = fgetl(fid);
continue;
end
line = cleanSpaces(line);
w = getWords(line);
if isempty(w{end})
w(end)=[];
end
if strcmp(w{1},'metrics')
w(1) = [];
vs = zeros(1,length(w));
for i = 1:length(w)
vs(1,i) = str2num(w{i});
end
tab = [tab ; vs];
% disregard data and delete last model
if max(vs)<-1
model_list(end) = [];
tab(end,:) = [];
end
elseif strcmp(w{1},'list_metrics')
w(1) = [];
metric_list = w;
disp(metric_list);
elseif strcmp(w{1},'output')
% nothing
elseif strcmp(w{1},'TYPE')
disp('=================')
line
line = cleanSpaces(line);
line
line = strrep(line,'TYPE','');
line = strrep(line,'DEGREE','');
line = strrep(line,'KERNEL_COEF -1','OPT');
line = strrep(line,'KERNEL_COEF','');
line = strrep(line,'KERNEL_','');
line = strrep(line,'D1','');
line = strrep(line,'WEIGHT','');
line = strrep(line,'METRIC','');
line = strrep(line,'ENSEMBLE','Ens.');
line = strrep(line,'OPTIM','Optim.');
line = strrep(line,'SELECT','Select');
line = strrep(line,'RIDGE 0.001','Ridge 1e-3');
line = strrep(line,'RIDGE 0','');
line = cleanSpaces(line);
line = strrep(line,'RBFI I','RBFI PolyH. ');
line = strrep(line,'PRESET',' ');
line = cleanSpaces(line);
model_list{end+1} = line;
else
disp(line)
error('line not recognized');
end
line = fgetl(fid);
end
fclose(fid);
% Count
NM = length(metric_list);
NS = length(model_list);
% Reorder
metric_list = metric_list(m_order);
tab = tab(:,m_order);
% Build fancy names
metric_fancy_names = metric_list;
metric_fancy_names = strrep(metric_fancy_names,'LOO','RMSE');
metric_fancy_names = strrep(metric_fancy_names,'RMSECV','PRESS');
metric_fancy_names = strrep(metric_fancy_names,'OETP','OE');
xmin = zeros(1,NM);
xmax = zeros(1,NM);
for nm=1:NM
e = tab(:,nm);
xmin(nm) = min(e(e>0));
if any(e==0)
xmin(nm) = xmin(nm)/10;
end
xmax(nm) = max(e);
end
xmin = 10.^floor(log10(xmin));
xmax = 10.^ceil (log10(xmax));
%
%
% xmin(:) = 0.0;
% xmax(:) = 1;
MODEL_TYPES = {'PRS','KS','RBFI','LOWESS','Ens.'};
%MODEL_TYPES = {'PRS','KS','RBFI','RBFI PolyH'};
%figure('color','w','position',[959 19 932 945]);
%figure('color','w','position',[949 483 932 481]);
%figure('color','w','position',[793 14 648 770]);
%figure('color','w','position',[509 574 932 210]);
figure('color','w','position',[586 408 847 374]);
set(gcf,'units','normalized');
coladd = 2.5
height = 0.85;
width = 0.7;
for nm=1:NM
% ORder
t = tab(:,nm)
[t,t] = sort(t);
t(t) = (1:length(t))
pos = [ (nm+coladd-1)/(NM+coladd) (1-height)/2 width/(NM+coladd) height];
subplot('position',pos); hold on;
for ns=1:NS
w = getWords(model_list{ns});
c = -1;
for i=1:length(MODEL_TYPES)
if ~isempty(strfind(model_list{ns},MODEL_TYPES{i}))
c = i;
end
end
if c==-1
w{1}
MODEL_TYPES
error('not recognised...');
end
c = get_color(c+1,length(MODEL_TYPES)+1);
c = 1-0.7*(1-c);
fill([xmin(nm)*[1 1] tab(ns,nm)*[1 1]],ns+[-0.4 +0.4 +0.4 -0.4],c);
text(0.75,ns,num2str(t(ns)));
%text(0.75,ns, num2str(t(ns)));
end
set(gca,'units','normalized');
title(metric_fancy_names{nm},texOptions{:});
if nm==1
disp('Modify ytick');
set(gca,'ytick',(1:NS),'yticklabel',model_list,texOptions{:});
else
set(gca,'ytick',[],'yticklabel',[],texOptions{:});
end
%set(gca,'xscale','log');
%xlim([xmin(nm) xmax(nm)]);
%set(gca,'xtick',[xmin(nm) xmax(nm)]);
set(gca,'ydir','reverse','xgrid','on','xminorgrid','off','box','on');
ylim([0.5 NS+0.5]);
end
export_fig([output_file],'-pdf');
output_file = strrep(output_file,'.pdf','_correlation.tex');
fid = fopen(output_file,'w');
newline = char(10);
s = '\begin{tabular}{| c ||';
for i=1:NM
s = [s ' c |'];
end
fwrite(fid,[s '}' newline]);
fwrite(fid,['\hline' newline]);
s = '';
for i=1:NM
s = [s ' & ' metric_fancy_names{i} ];
end
fwrite(fid,[s ' \\' newline]);
fwrite(fid,['\hline\hline' newline]);
for i=1:NM
mi = tab(:,i);
fwrite(fid,[metric_fancy_names{i} newline]);
for j=1:NM
if j>=i
mj = tab(:,j);
c = corr([mi mj]);
c = c(2,1);
c = 0.01*round(c*100);
s = num2str(c);
if abs(c)~=1 && c~=0 && 10*c==round(10*c)
s = [s '0'];
if isempty(find(s=='.'))
error('PROBLEM...');
end
end
else
s = ' ';
end
if j==NM
s = [s ' \\'];
end
fwrite(fid,[ ' & ' s newline]);
end
fwrite(fid,['\hline' newline]);
end
fwrite(fid,'\end{tabular}');
fclose(fid);
%edit(output_file);
close all
%clear all
clc
disp('=========== EXPLORER =============');
addpath('../Matlab_Server');
! make -j 4
model=cell(0,1);
model{end+1} = 'TYPE LOWESS SHAPE_COEF -1 PRESET DEN '
model{end+1} = 'TYPE LOWESS SHAPE_COEF -1 PRESET DGN '
texOptions = {'fontname','times','fontsize',14};
disp('=========== START =============');
% GOOD!!
X = randn(50,1);
Z = sin(2*pi*X)+0.1*randn(size(X));
Z = cos(pi*X).*sign(X);
%figure('color','w','position',[1466 527 455 437]); hold on;
figure('color','w','position',[198 95 933 639]); hold on;
pointer(1) = plot(X,Z,'ok','linewidth',2);
NN = 1000;
zoom = 1.0;
XX = sort([linspace(zoom*min(X),zoom*max(X),NN)' ; X ]);
%XX = 0.5;
metric = inf*ones(length(model),2);
for i=1:length(model)
disp('Model : ');
model{i}
disp('Init');
sgtelib_server_start(model{i},true)
sgtelib_server_ping;
disp('Data');
sgtelib_server_newdata(X,Z);
disp('Predict');
[ZZ,std,ei,cdf] = sgtelib_server_predict(XX);
metric(i,1) = sgtelib_server_metric('RMSECV');
metric(i,2) = sgtelib_server_metric('OECV');
marker = '';%get_marker(i,length(model));
pointer(i+1) = plot(XX,ZZ,['-' marker],'color',get_color(i+1,length(model)+1));
sgtelib_server_stop;
end
legend_txt = {'Training points'};
for i=1:length(model)
name = model{i};
name = strrep(name,'TYPE ENSEMBLE WEIGHT SELECT METRIC','Select');
name = strrep(name,'RMSECV','PRESS');
name = strrep(name,'KERNEL_COEF ',' $\lambda$=');
name = strrep(name,'TYPE',' ');
name = strrep(name,'DEGREE','Degree');
name = strrep(name,'RIDGE 0.001','Ridge 1e-3');
name = strrep(name,'RIDGE 0.0',' ');
name = strrep(name,'SHAPE_COEF',' ');
name = strrep(name,'PRESET',' ');
name = strrep(name,'Degree 2',' ');
name = cleanSpaces(name);
legend_txt{i+1} = name;
end
legend(pointer,legend_txt,'location','best','interpreter','latex');
%shift_legend_size([-0.15 0 +0.1 0]);
%axis([0 +1 -1.5 +1.5])
xlabel('x',texOptions{:});
ylabel('y',texOptions{:});
set(gca,texOptions{:});
output_dir = './';
output_file = [output_dir 'plot_function_2.pdf'];
export_fig([output_file],'-pdf');
for i=1:length(model)
disp(legend_txt{i+1});
s = ' ';
s = [s num2str(metric(i,1),8)];
s(20) = ' ';
s = [s num2str(metric(i,2),8)];
disp(s);
end
\ No newline at end of file
close all
clear all
clc
disp('=========== EXPLORER =============');
addpath('../Matlab_Server');
WRITE = false;
! make -j 4
model = 'TYPE KRIGING'
sgtelib_server_start(model)
disp('=========== START =============');
sgtelib_server_ping;
f = @(x) sin(5*x) + 1.5*x + x.^2;
xmin = -2;
xmax = +1.5;
zmin = -3;
zmax = +5;
X = [ -2 ; -1 ; 0.5 ; 1.5 ];
Z = f(X);
XX = linspace(xmin,xmax,1000)';
ZZtrue = f(XX);
figure('color','w'); hold on;
pointer = [];
leg_txt = cell(0);
k = 0;
pointer(1) = plot(XX,ZZtrue,'--b');
leg_txt{1} = 'True function f(x) (unknown)';
legend(pointer,leg_txt,'location','northwest'); legend('boxoff');
axis([xmin xmax zmin zmax]);
xlabel('x')
drawnow
if WRITE
export_fig(['SurrogateBasedOptim_A' sprintf('%02d',k) '.pdf'],'-pdf'); k=k+1;
end
pointer(2) = plot(X,Z,'ok');
leg_txt{2} = 'Observations';
legend(pointer,leg_txt,'location','northwest'); legend('boxoff');
axis([xmin xmax zmin zmax]);
drawnow
if WRITE
export_fig(['SurrogateBasedOptim_A' sprintf('%02d',k) '.pdf'],'-pdf'); k=k+1;
end
set(legend,'box','off')
sgtelib_server_newdata(X,Z);
for ii=1:8
[ZZ,std,ei,cdf] = sgtelib_server_predict(XX);
pointer(3) = plot(XX,ZZ,'r');
if ii==1
leg_txt{3} = 'Surrogate model';
else
leg_txt{3} = 'Updated surrogate model';
end
legend(pointer,leg_txt,'location','northwest'); legend('boxoff');
axis([xmin xmax zmin zmax]);
drawnow
if WRITE
export_fig(['SurrogateBasedOptim_A' sprintf('%02d',k) '.pdf'],'-pdf'); k=k+1;
end
[ZZmin,imin] = min(ZZ);
XXmin = XX(imin);
pointer(4) = plot(XXmin,ZZmin,'or');
leg_txt{4} = ['Candidate: x=' num2str(XXmin,3) ];
legend(pointer,leg_txt,'location','northwest'); legend('boxoff');
axis([xmin xmax zmin zmax]);
drawnow
if WRITE
export_fig(['SurrogateBasedOptim_A' sprintf('%02d',k) '.pdf'],'-pdf'); k=k+1;
end
Xnew = XXmin;
Znew = f(Xnew);
pointer(5) = plot(Xnew,Znew,'ob');
leg_txt{5} = ['True value of candidate: f(' num2str(XXmin,3) ') = ' num2str(Znew,3)];
legend(pointer,leg_txt,'location','northwest'); legend('boxoff');
axis([xmin xmax zmin zmax]);
drawnow
if WRITE
export_fig(['SurrogateBasedOptim_A' sprintf('%02d',k) '.pdf'],'-pdf'); k=k+1;
end
delete(pointer(3:5));
pointer(3:5) = [];
leg_txt(3:5) = [];
plot(Xnew,Znew,'ko');
sgtelib_server_newdata(Xnew,Znew);
end
sgtelib_server_stop;
close all
clear all
clc
disp('=========== EXPLORER =============');
addpath('../Matlab_Server');
WRITE = false;
! make -j 4
model = 'TYPE KRIGING'
sgtelib_server_start(model);
disp('=========== START =============');
sgtelib_server_ping;
f = @(x) sin(8*x) + 1.5*x + x.^2 ;
xmin = -2;
xmax = +1.5;
zmin = -3;
zmax = +5;
X = [ -2 ; -1.4 ; -0.6 ; 0.8; 1.5 ];
Z = f(X);
Zmin = min(Z);
XX = linspace(xmin,xmax,1000)';
ZZtrue = f(XX);
figure('color','w'); hold on;
pointer = [];
leg_txt = cell(0);
k = 0;
pointer(1) = plot(XX,ZZtrue,'--b');
leg_txt{1} = 'True function f(x) (unknown)';
legend(pointer,leg_txt,'location','northwest'); legend('boxoff');
axis([xmin xmax zmin zmax]);
xlabel('x')
drawnow
if WRITE
export_fig(['SurrogateBasedOptim_B' sprintf('%02d',k) '.pdf'],'-pdf'); k=k+1;
end
pointer(2) = plot(X,Z,'ok');
leg_txt{2} = 'Observations';
legend(pointer,leg_txt,'location','northwest'); legend('boxoff');
axis([xmin xmax zmin zmax]);
drawnow
if WRITE
export_fig(['SurrogateBasedOptim_B' sprintf('%02d',k) '.pdf'],'-pdf'); k=k+1;
end
set(legend,'box','off')
sgtelib_server_newdata(X,Z);
for ii=1:50
[ZZ,std,ei,cdf] = sgtelib_server_predict(XX);
pointer(3) = plot(XX,ZZ,'r');
if ii==1
leg_txt{3} = 'Surrogate model';
else
leg_txt{3} = 'Updated surrogate model';
end
std = std/max(std);
pointer_sup(1) = plot(XX,ZZ+std,'--r');
pointer_sup(2) = plot(XX,ZZ-std,'--r');
drawnow
u = (Zmin-ZZ)./std;
ei = std.*( u.*normcdf(u)+normpdf(u) );
if max(ei)>0
ei = ei/max(ei);
end
pointer(4) = plot(XX,ei,'k');
leg_txt{4} = 'Expected Improvement';
legend(pointer,leg_txt,'location','northwest'); legend('boxoff');
axis([xmin xmax zmin zmax]);
drawnow
if WRITE
export_fig(['SurrogateBasedOptim_B' sprintf('%02d',k) '.pdf'],'-pdf'); k=k+1;
end
pause(0.3)
if min(ei)==max(ei)
break;
end
[eimin,imin] = max(ei);
XXmin = XX(imin);
drawnow
pointer(5) = plot(XXmin,eimin,'ok');
leg_txt{5} = ['Candidate: x=' num2str(XXmin,3) ];
legend(pointer,leg_txt,'location','northwest'); legend('boxoff');
axis([xmin xmax zmin zmax]);
drawnow
if WRITE
export_fig(['SurrogateBasedOptim_B' sprintf('%02d',k) '.pdf'],'-pdf'); k=k+1;
end
Xnew = XXmin;
Znew = f(Xnew);
Zmin = min(Zmin,Znew);
pointer(6) = plot(Xnew,Znew,'ob');
leg_txt{6} = ['True value of candidate: f(' num2str(XXmin,3) ') = ' num2str(Znew,3)];
legend(pointer,leg_txt,'location','northwest'); legend('boxoff');
axis([xmin xmax zmin zmax]);
drawnow
if WRITE
export_fig(['SurrogateBasedOptim_B' sprintf('%02d',k) '.pdf'],'-pdf'); k=k+1;
end
delete(pointer(3:6));
delete(pointer_sup);
pointer(3:6) = [];
leg_txt(3:6) = [];
plot(Xnew,Znew,'ko');
sgtelib_server_newdata(Xnew,Znew);
drawnow
pause(0.3);
end
sgtelib_server_stop;
close all
clear all
clc
model = 'TYPE ENSEMBLE WEIGHT OPTIM METRIC OECV';
sgtelib_server_start(model,true)
sgtelib_server_ping;
P = 100;
X = sort(randn(P,1));
Z(:,1) = X.^2-X-3;
Z(:,2) = sign(X).*cos(X) + 0.1*randn(size(X));
Z(:,3) = mod(round(X),2)-0.5;
M = size(Z,2);
sgtelib_server_newdata(X,Z);
PP = 1000;
XX = sort([linspace(min(X)-1,max(X)+1,PP)' ; X]);
figure;
hold on;
for i=1:M
plot(X,Z(:,i),'o','color',get_color(i,M));
end
[ZZ,std,ei,cdf] = sgtelib_server_predict(XX);
disp('metrics...')
sgtelib_server_metric('RMSE')
sgtelib_server_metric('RMSECV')
sgtelib_server_metric('OECV')
for i=1:M
plot(XX,ZZ(:,i),'-','color',get_color(i,M),'linewidth',2);
plot(XX,ZZ(:,i)+std(:,i),'--','color',get_color(i,M));
plot(XX,ZZ(:,i)-std(:,i),'--','color',get_color(i,M));
end
% plot(xlim,[0 0],'--k');
% disp('Get CV values');
% [Zh,Sh,Zv,Sv] = sgtelib_server_cv;
% for i=1:M
% plot(X,Zv(:,i),'o','color',get_color(i,M));
% for j=1:P
% plot(X(j)*[1 1],Zv(j,i)+Sv(j,i)*[-1 +1],'-','color',get_color(i,M));
% end
% end
% disp('Plot EFI');
% figure;
% efi = ei(:,1).*prod(cdf(:,2:end),2);
% efi = max(1e-16,efi);
% plot(XX,efi,'g');
% set(gca,'yscale','log')
close all
%clear all
clc
disp('=========== EXPLORER =============');
model = 'TYPE ENSEMBLE WEIGHT SELECT METRIC OECV DISTANCE OPTIM'
model = 'TYPE KS DISTANCE OPTIM'
model = 'TYPE ENSEMBLE WEIGHT SELECT METRIC OECV DISTANCE OPTIM'
%model = 'TYPE PRS_CAT DEGREE 3'
%model = 'TYPE RBF DISTANCE OPTIM'
model = 'TYPE LOWESS DISTANCE OPTIM'
f = @(x) x(:,2).^2 .* x(:,1) .* ( 2*mod(x(:,1),2)-1 )
% f = @(x) 40*(x(:,1)==0)+...
% 35*(x(:,2)==0)+...
% 35*cos(x(:,1)/4)+...
% 30*sin(x(:,2)/9);
% Data points
x1max = 5;
x2max = 100;
p = 50;
X = [round(rand(p,1)*x1max) round(rand(p,1)*x2max) ];
X = unique(X,'rows');
Z = f(X);
sgtelib_server_start(model,true)
sgtelib_server_ping;
sgtelib_server_newdata(X,Z);
% Prediction
[x1,x2] = meshgrid( (0:x1max) , (0:x2max) );
XX = [x1(:) x2(:)];
[ZZ,std,ei,cdf] = sgtelib_server_predict(XX);
ZZ = reshape(ZZ,x2max+1,x1max+1);
figure('color','w'); hold on;
surf(x1,x2,ZZ,'facealpha',0.5);
plot3(X(:,1),X(:,2),Z,'ko','linewidth',3,'markersize',5);
dv = max(Z)-min(Z);
zlim([min(Z)-dv/3,max(Z)+dv/3]);
set(gca,'view',[116 50]);
xlabel('x1');
ylabel('x2');
sgtelib_server_stop;
close all
clear all
clc
disp('=========== EXPLORER =============');
! make -j 4
model = 'TYPE LOWESS DISTANCE OPTIM KERNEL_SHAPE OPTIM KERNEL_TYPE OPTIM RIDGE OPTIM METRIC OECV'
model = 'TYPE KRIGING DISTANCE NORM2_IS0 METRIC OECV'
% creation of model
sgtelib_server_start(model,true)
sgtelib_server_ping;
% Test function
%f = @(x) cos(sqrt(0.5*x(:,1))).*cos(0.1*x(:,2));
f = @(x) 40*(x(:,1)==0)+...
35*(x(:,2)==0)+...
35*cos(x(:,1)/4)+...
30*sin(x(:,2)/9);
% Dimension
N = 2;
% Number of sampling points along each dimension
PP1 = 25;
PP2 = 20;
% Bounds along each dimension
x1min = 0;
x1max = +30;
x2min = 0;
x2max = +30;
% Create data
scale_x1 = linspace(x1min,x1max,PP1)
scale_x2 = linspace(x2min,x2max,PP2)
[x1,x2] = meshgrid( scale_x1 , scale_x2 );
XX = [x1(:) x2(:)];
PP = (PP1)*(PP2);
ZZ = f(XX);
% Selection of some training points
P = 30;
i = randperm(PP);
i = i(1:P);
X = XX(i,:);
Z = ZZ(i,:);
% Sending data
sgtelib_server_newdata(X,Z);
% Prediction
[ZZ,std,ei,cdf] = sgtelib_server_predict(XX);
figure
subplot(2,2,1);hold on;
plot3(X(:,1),X(:,2),Z,'k.');
surf(x1,x2,reshape(f(XX),PP2,PP1));
set(gca,'view',[-37.5000 30.0000]);
set(gca,'ydir','normal')
xlabel('Real Z');
xlim([min(scale_x1) max(scale_x1)]);
ylim([min(scale_x2) max(scale_x2)]);
%zlim([-2 +2]);
subplot(2,2,2);hold on;
plot3(X(:,1),X(:,2),Z,'k.');
surf(x1,x2,reshape(ZZ,PP2,PP1));
set(gca,'view',[-37.5000 30.0000]);
xlabel('Zh');
xlim([min(scale_x1) max(scale_x1)]);
ylim([min(scale_x2) max(scale_x2)]);
%zlim([-2 +2]);
subplot(2,2,3);hold on;
imagesc(scale_x1,scale_x2,reshape(f(XX),PP2,PP1));
set(gca,'ydir','normal');
plot(X(:,1),X(:,2),'k.');
axis([min(scale_x1) max(scale_x1) min(scale_x2) max(scale_x2)])
subplot(2,2,4);hold on;
imagesc(scale_x1,scale_x2,reshape(ZZ,PP2,PP1));
set(gca,'ydir','normal');
plot(X(:,1),X(:,2),'k.');
axis([min(scale_x1) max(scale_x1) min(scale_x2) max(scale_x2)])
disp('metric:')
sgtelib_server_metric('AOECV')
sgtelib_server_stop;
close all
clear all
clc
disp('=========== EXPLORER =============');
! make -j 4
%model = 'TYPE PRS'
model = 'TYPE ENSEMBLE DISTANCE OPTIM WEIGHT SELECT '
model = 'TYPE KRIGING DISTANCE OPTIM METRIC OECV'
%model = 'TYPE ENSEMBLE WEIGHT SELECT METRIC OECV DISTANCE OPTIM PRESET SUPER1'
%model = 'TYPE LOWESS KERNEL_TYPE OPTIM DISTANCE OPTIM'
%model = 'TYPE KS DISTANCE IS0'
%model = 'TYPE ENSEMBLE WEIGHT SELECT METRIC OECV DISTANCE IS0 PRESET SUPER1'
f = @(x) 40*(x(:,1)==0)+...
35*(x(:,2)==0)+...
35*cos(x(:,1)/4)+...
30*sin(x(:,2)/9);
% Data points
x1max = 30;
x2max = 35;
p1 = 5;
p2 = 12;
p = 10;
X = [
zeros(p1,1) round(rand(p1,1)*x2max) ;...
round(rand(p2,1 )*x1max) zeros(p2,1) ;...
round(rand(p,1)*x1max) round(rand(p,1)*x2max) ];
X = unique(X,'rows');
Z = f(X);
sgtelib_server_start(model,true)
sgtelib_server_ping;
sgtelib_server_newdata(X,Z);
% Prediction
[x1,x2] = meshgrid( (0:x1max) , (0:x2max) );
XX = [x1(:) x2(:)];
[ZZ,std,ei,cdf] = sgtelib_server_predict(XX);
ZZ = reshape(ZZ,x2max+1,x1max+1);
figure('color','w'); hold on;
surf(x1,x2,ZZ,'facealpha',0.5);
plot3(X(:,1),X(:,2),Z,'ko','linewidth',3,'markersize',5);
dv = max(Z)-min(Z);
zlim([min(Z)-dv/3,max(Z)+dv/3]);
set(gca,'view',[116 50]);
xlabel('x1');
ylabel('x2');
sgtelib_server_stop;
close all
clear all
clc
disp('=========== EXPLORER =============');
! make -j 4
model = 'TYPE ENSEMBLE PRESET SUPER1 WEIGHT SELECT METRIC RMSE '
f = @(x) cos(sqrt(4*x(:,1))).*cos(3*x(:,2))+(x(:,1)>0.5)+(x(:,2)>0.5);
% Number of data points
P = 50;
% Data points
X = rand(P,2);
Z = f(X);
% Create model
PP = 50;
[x1,x2] = meshgrid( linspace(0,1,PP) , linspace(0,1,PP) );
XX = [x1(:) x2(:)];
sgtelib_server_start(model,true)
sgtelib_server_ping;
sgtelib_server_newdata(X,Z);
[ZZ,std,ei,cdf] = sgtelib_server_predict(XX);
figure('color','w'); hold on;
surf(x1,x2,reshape(ZZ,PP,PP));
plot3(X(:,1),X(:,2),Z,'ko','linewidth',3,'markersize',5);
set(gca,'view',[-36 66]);
sgtelib_server_stop;
close all
clear all
clc
disp('=========== EXPLORER =============');
%rand('twister',3)
! make -j 4
model = 'TYPE PRS DEGREE 2 RIDGE 0.01'
%model = 'TYPE RBF DISTANCE_TYPE NORM2_IS0 KERNEL_COEF 2 KERNEL_TYPE D2'
%model = 'TYPE KS DISTANCE_TYPE NORM2_IS0 KERNEL_COEF 10 KERNEL_TYPE D2'
%model = 'TYPE ENSEMBLE WEIGHT SELECT METRIC RMSECV'
model = 'TYPE ENSEMBLE WEIGHT SELECT METRIC OECV'
% model = 'TYPE KS'
% model = 'TYPE LOWESS'
%f = @(x) sum(x.^2,2);
N = 10;
P = 100;
M = 1;
X = randn(P,N);
Z = randn(P,M);
toBeDelData;
M = size(Z,2);
PP = 100;
dx = 0.1;
XX = zeros(PP,N);
for i=2:PP
r = randn(1,N);
r = dx*r/norm(r);
XX(i,:) = XX(i-1,:)+r;
end
sgtelib_server_start(model,true)
sgtelib_server_ping;
sgtelib_server_newdata(X,Z);
[ZZmodel,std,ei,cdf] = sgtelib_server_predict(XX);
m = sgtelib_server_metric('RMSECV')
function [Zh,Sh,Zv,Sv] = sgtelib_server_cv
% sgtelib_server_ping;
% Remove flags
system('rm -f flag_cv_* 2>/dev/null');
% Create flag
system('touch flag_cv_transmit');
% Wait for reception flag
sgtelib_server_wait_file('flag_cv_finished');
% Read Output file
[Zh,Sh,Zv,Sv] = sgtelib_server_read_matrix('flag_cv_finished');
% Remove all flags
system('rm -f flag_cv_* 2>/dev/null');
close all
clear all
% Start server
model = 'TYPE PRS DEGREE 2';
model = 'TYPE ENSEMBLE METRIC LINV WEIGHTS OPTIM'
sgtelib_server_start('TYPE PRS DEGREE 2',true)
% Test if server is ok and ready
sgtelib_server_ping;
% Build data points
N = 2;
M = 1;
P = 100;
X = rand(P,N);
Z = rand(P,M);
% Feed server
sgtelib_server_newdata(X,Z);
% Prediction points
PXX = 1000;
XX = rand(PXX,N);
%Prediction
[ZZ,std,ei,cdf] = sgtelib_server_predict(XX);
% Plot
figure; hold on;
plot3(X(:,1),X(:,2),Z,'*k');
plot3(XX(:,1),XX(:,2),ZZ,'or')
% Stop server
sgtelib_server_stop;
\ No newline at end of file
function M = sgtelib_server_info
% sgtelib_server_ping;
% Remove flags
system('rm -f flag_info_* 2>/dev/null');
% Write infoion point
system('touch flag_info_transmit');
% Wait for reception flag
sgtelib_server_wait_file('flag_info_finished');
function M = sgtelib_server_metric(metric_str)
% sgtelib_server_ping;
% Remove flags
system('rm -f flag_metric_* 2>/dev/null');
% Write metricion point
system(['echo ' metric_str ' >> flag_metric_create']);
% Create flag
system('mv flag_metric_create flag_metric_transmit');
% Wait for reception flag
sgtelib_server_wait_file('flag_metric_finished');
% Read Output file
M = importdata('flag_metric_finished');
% Remove all flags
system('rm -f flag_metric_* 2>/dev/null');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment