-
Notifications
You must be signed in to change notification settings - Fork 18
/
plotfn_20.m
72 lines (71 loc) · 2.9 KB
/
plotfn_20.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
%==========================================================================
% A modular code for teaching Surrogate Modeling-Based Optimization
% Author: Yong Hoon Lee ([email protected])
%==========================================================================
% PlotFN_20 Script
%==========================================================================
% Plot samples
axes(fh1);
pl11 = plot(x_sample{k}(:,1),x_sample{k}(:,2),'x'); hold on;
% Plot contours of the constructed RBF model
axes(fh2);
hold off;
xv = linspace(pc.lb(1),pc.ub(1),101);
yv = linspace(pc.lb(2),pc.ub(2),101);
[XMG,YMG] = meshgrid(xv,yv);
ZMG = zeros(101,101);
for j = 1:101
ZMG(:,j) = tps_rbf_objfn([XMG(:,j),YMG(:,j)],weight,center);
end
[~,ctrpred] = contourf(XMG,YMG,ZMG,50); hold on;
ctrpred.LineStyle = 'none';
plot(xopt(1),xopt(2),'o','MarkerFaceColor',[1 1 1],'Color','none');
%set(ctrpred,'LevelList',ctrlvl);
cbarpred = colorbar('east');
set(cbarpred,'Position',[0.36,0.2,0.01,0.25]);
set(cbarpred,'Color',[1 1 1]);
% Plot optimal point
axes(fh1);
pl12 = plot(xopt(1),xopt(2),'ok');
if (k>1)
plot([xopt_history{k-1}(1),xopt(1)],...
[xopt_history{k-1}(2),xopt(2)],'-k');
end
% Plot distance and error
axes(fh4);
pl41 = semilogy(k,norm(xopt - xtrue),'ko'); hold on;
axes(fh5);
pl51 = semilogy(k,norm(fopt - ftrue),'ko'); hold on;
pl52 = semilogy(k,norm(fopt - f_hf_opt),'kx'); hold on;
% Plot labels and legends
axes(fh1);
xlabel('$x_1$','Interpreter','latex','FontSize',14);
ylabel('$x_2$','Interpreter','latex','FontSize',14);
title('Predicted solution trajectory','Interpreter','latex','FontSize',14);
legend([pl11,pl12],{['Samples (',num2str(size(fsmp,1)),' generated)'],...
'Predicted solution'},...
'Interpreter','latex','FontSize',14);
axis([pc.lb(1),pc.ub(1),pc.lb(2),pc.ub(2)]);
axes(fh2);
xlabel('$x_1$','Interpreter','latex','FontSize',14);
ylabel('$x_2$','Interpreter','latex','FontSize',14);
title('Predicted response','Interpreter','latex','FontSize',14);
axis([pc.lb(1),pc.ub(1),pc.lb(2),pc.ub(2)]);
axes(fh3);
xlabel('$x_1$','Interpreter','latex','FontSize',14);
ylabel('$x_2$','Interpreter','latex','FontSize',14);
title('True response','Interpreter','latex','FontSize',14);
axis([pc.lb(1),pc.ub(1),pc.lb(2),pc.ub(2)]);
axes(fh4);
xlabel('iteration','Interpreter','latex','FontSize',14);
ylabel('distance','Interpreter','latex','FontSize',14);
legend([pl41],{'$||x_{\mathrm{predicted}} - x_{\mathrm{true}}||$'},...
'Interpreter','latex','FontSize',14,'Location','northoutside');
title('Distance to true solution','Interpreter','latex','FontSize',14);
axes(fh5);
xlabel('iteration','Interpreter','latex','FontSize',14);
ylabel('error','Interpreter','latex','FontSize',14);
legend([pl51,pl52],{'$||f_{\mathrm{predicted}} - f_{\mathrm{true}}||$',...
'$||f_{\mathrm{predicted}} - f_{\mathrm{hi-fi\; fn}}||$'},...
'Interpreter','latex','FontSize',14,'Location','northoutside');
title('Error','Interpreter','latex','FontSize',14);