-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
178 lines (128 loc) · 5.71 KB
/
main.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
clear
close all
Run_this = 'One_of_each'; % sit back and wait. It will cycle through all
% % or uncomment this
% Run_this = 'Just_one'; % Choose Gradient_Type and ROI_Type below
% % and some of these
% Gradient_Type = 'standard_0';
% Gradient_Type = 'standard_1';
% Gradient_Type = 'exact';
% Gradient_Type = 'midpoint';
%
% ROI_Type = 'Gr';
% ROI_Type = 'GrBW';
% ROI_Type = 'BW';
load('Time.mat')
load('Opimization.mat')
switch Run_this
case 'Just_one'
load(sprintf('Space_%s.mat',ROI_Type))
Optimization.Par.Grad = Gradient_Type;
fprintf(2,'Running GRADPREC with a %s gradient on a %s type of ROI\n\n',Optimization.Par.Grad,ROI_Type)
if contains(Optimization.Par.Grad,'exa')
Optimization.par_Ncores = 2;
% or e.g. Optimization.par_Ncores = feature('numcores');
% or 23 as in the paper.
if Optimization.par_Ncores > 1
parpool;
end
fprintf(1,'The exact gradient is run with %i CPU cores. You might want to adjust this...\n\n',Optimization.par_Ncores)
end
Optimization = GRADPREC(Space,Time,Optimization);
Simulation = SIMULATION([],Space,Time,[],'u',Optimization.uo,'v',Optimization.vo,'s',[],'Output','MapsSingle');
figure
colormap jet
subplot(2,3,1)
imagesc(Space.Mtarget_map(:,:,:,:,1),[-1,1])
colorbar
axis equal off
title({'';'M_x/M_0'})
subplot(2,3,2)
imagesc(Space.Mtarget_map(:,:,:,:,2),[-1,1])
title({sprintf('Target of a %s type',ROI_Type);'M_y/M_0'})
colorbar
axis equal off
subplot(2,3,3)
imagesc(Space.Mtarget_map(:,:,:,:,3),[-1,1])
title({'';'M_z/M_0'})
colorbar
axis equal off
subplot(2,3,4)
imagesc(Simulation.M_t{1}(:,:,:,:,1),[-1,1])
title('M_x(T)/M_0')
colorbar
axis equal off
subplot(2,3,5)
imagesc(Simulation.M_t{1}(:,:,:,:,2),[-1,1])
title({sprintf('GRADPREC after %i iterations with a %s gradient\n\n',Optimization.ksafe-1,Optimization.Par.Grad);'M_y(T)/M_0'})
colorbar
axis equal off
subplot(2,3,6)
imagesc(Simulation.M_t{1}(:,:,:,:,3),[-1,1])
title('M_z(T)/M_0')
colorbar
axis equal off
drawnow
case 'One_of_each'
Gradient_Type_ = {'standard_0','standard_1','exact','midpoint','standard_0_loop','standard_1_loop'};
ROI_Type_ = {'Gr','GrBW','BW'};
Optimization_array = cell(3,4);
Simulation_array = cell(3,4);
for r = 1:3
load(sprintf('Space_%s.mat',ROI_Type_{r}))
for g = 1:4
Optimization.Par.Grad = Gradient_Type_{g};
fprintf(2,'\n\nRunning GRADPREC with a %s gradient on a %s type of ROI\n\n',Optimization.Par.Grad,ROI_Type_{r})
if contains(Optimization.Par.Grad,'exa')
Optimization.par_Ncores = 2;
% or e.g. Optimization.par_Ncores = feature('numcores');
% or 23 as in the paper.
if Optimization.par_Ncores > 1
parpool;
end
fprintf(1,'The exact gradient is run with %i CPU cores. You might want to adjust this...\n\n',Optimization.par_Ncores)
end
Optimization_array{r,g} = GRADPREC(Space,Time,Optimization);
Simulation_array{r,g} = SIMULATION([],Space,Time,[],'u',Optimization_array{r,g}.uo,'v',Optimization_array{r,g}.vo,'s',[],'Output','MapsSingle');
figure
colormap jet
subplot(2,3,1)
imagesc(Space.Mtarget_map(:,:,:,:,1),[-1,1])
colorbar
axis equal off
title({'';'M_x/M_0'})
subplot(2,3,2)
imagesc(Space.Mtarget_map(:,:,:,:,2),[-1,1])
title({sprintf('Target of a %s type',ROI_Type_{r});'M_y/M_0'})
colorbar
axis equal off
subplot(2,3,3)
imagesc(Space.Mtarget_map(:,:,:,:,3),[-1,1])
title({'';'M_z/M_0'})
colorbar
axis equal off
subplot(2,3,4)
imagesc(Simulation_array{r,g}.M_t{1}(:,:,:,:,1),[-1,1])
title('M_x(T)/M_0')
colorbar
axis equal off
subplot(2,3,5)
imagesc(Simulation_array{r,g}.M_t{1}(:,:,:,:,2),[-1,1])
title({sprintf('GRADPREC after %i iterations with a %s gradient\n\n',Optimization_array{r,g}.ksafe-1,Optimization.Par.Grad);'M_y(T)/M_0'})
colorbar
axis equal off
subplot(2,3,6)
imagesc(Simulation_array{r,g}.M_t{1}(:,:,:,:,3),[-1,1])
title('M_z(T)/M_0')
colorbar
axis equal off
drawnow
end
end
%%
figure
for n = 1:3
subplot(1,3,n)
bar([1,2,3,4],[mean(Optimization_array{n,1}.Durations),mean(Optimization_array{n,2}.Durations),mean(Optimization_array{n,3}.Durations),mean(Optimization_array{n,4}.Durations)])
end
end