Commit a1ac5a19 authored by Miroslav Shaltev's avatar Miroslav Shaltev
Browse files

separate sgtelib

parent 6644564d
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_CONFIG_HEADERS([config.h])
......@@ -51,6 +51,8 @@ if test "x$mpi" = "xtrue"; then
fi
NOMAD_ENABLE_MODULE([MPI],[mpi])
PKG_CHECK_MODULES(SGTELIB, sgtelib)
AC_PROG_CPP
AC_CONFIG_FILES([Makefile src/Makefile docs/Makefile nomad.pc nomadmpi.pc])
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;