-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_results.m
107 lines (90 loc) · 3.12 KB
/
plot_results.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
%% Plot Results
% Plots results from the source optimisation example.
%
% You should first run mot.optimise2D to generate the results file.
load('result_2d.mat');
p = table2struct(best);
p = mot.parse(p);
mot.simulate(p);
%%
% Load trajectories
pos = utils.read_output('pos.txt');
ids = [];
for frame=pos'
captured = frame.vec(:,3) > 0.25;
ids = unique([ids; frame.id(captured)]);
end
% Build trajectories of each atom
trajectories = {};
for id=ids'
trajectory = zeros(0,3);
for i=1:length(pos)
index = find(pos(i).id == id);
if ~isempty(index)
trajectory(end+1,:)=pos(i).vec(index,:);
end
end
trajectories{end+1} = trajectory;
end
vel = utils.read_output('vel.txt');
% Color code by initial velocity
colors = {};
cmap = parula();
vmax = 140;
for id=ids'
index = find(vel(1).id == id);
velocity = vel(1).vec(index,:);
v = sum(velocity.^2).^0.5;
colors{end+1} = interp1(vmax*linspace(0, 1, length(cmap)), cmap, v, 'linear');
end
%%
% Plot a figure showing the evolution of the machine learning algorithm
clf;
set(gcf, 'Units', 'centimeters');
pos = get(gcf, 'Position');
set(gcf, 'Position', [ pos(1) pos(2) 9 12 ]);
set(gca, 'Units', 'centimeters', 'Position', [ 1.2 7.2 7.2 4.4 ]);
plot(result.ObjectiveMinimumTrace); hold on;
plot(result.ObjectiveTrace, 'k.', 'Color', [ 0.4 0.6 0.8 ])
xlabel('iteration number', 'Interpreter', 'latex');
ylabel('cost function', 'Interpreter', 'latex');
% Improve figure aesthetics
set(gcf, 'Color', 'w');
set(get(gca, 'XAxis'), 'TickLabelInterpreter', 'latex');
set(get(gca, 'YAxis'), 'TickLabelInterpreter', 'latex');
box(gca, 'on');
grid(gca, 'on');
set(gca, 'GridLineStyle', ':');
% Plot trajectories of best results
axes('Units', 'centimeters', 'Position', [ 1.2 1.2 7.2 5 ]);
for i=1:length(trajectories)
p = trajectories{i}*1e3;
plot(p(:,1), p(:,3), '-', 'Color', colors{i}); hold on;
end
xlim([ -10 20 ]);
ylim([ -30 40 ]);
xlabel('$x$ (mm)', 'Interpreter', 'latex');
ylabel('$z$ (mm)', 'Interpreter', 'latex');
set(gcf, 'Color', 'w');
set(get(gca, 'XAxis'), 'TickLabelInterpreter', 'latex');
set(get(gca, 'YAxis'), 'TickLabelInterpreter', 'latex');
box(gca, 'on');
grid(gca, 'on');
set(gca, 'GridLineStyle', ':');
annotation('textbox', 'Units', 'Centimeters', 'Position', [ 1.3 1.7 1 1 ], 'String', '$\rightarrow$', 'Interpreter', 'Latex', 'FontSize', 20, 'LineStyle', 'none');
annotation('textbox', 'Units', 'Centimeters', 'Position', [ 3.9 5.1 1 1 ], 'String', '$\uparrow$', 'Interpreter', 'Latex', 'FontSize', 20, 'LineStyle', 'none');
annotation('textbox', 'Units', 'Centimeters', 'Position', [ -0.1 11.1 1 1 ], 'String', '(a)', 'Interpreter', 'Latex', 'FontSize', 11, 'LineStyle', 'none');
annotation('textbox', 'Units', 'Centimeters', 'Position', [ -0.1 5.5 1 1 ], 'String', '(b)', 'Interpreter', 'Latex', 'FontSize', 11, 'LineStyle', 'none');
%%
% Save figure
set(gcf, 'Units', 'centimeters');
pos = get(gcf, 'Position');
w = pos(3);
h = pos(4);
p = 0.01;
set(gcf,...
'PaperUnits','centimeters',...
'PaperPosition',[p*w p*h w h],...
'PaperSize',[w*(1+2*p) h*(1+2*p)]);
set(gcf, 'Renderer', 'painters')
saveas(gcf, 'optimiser.pdf')