-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplotPA.m
258 lines (231 loc) · 8.15 KB
/
plotPA.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
% function plotPA(Data,Sim,s,options)
function plotPA(varargin)
persistent fh
%% Check and assign inputs
if nargin >= 2
Data = varargin{1};
Sim = varargin{2};
% getSimulationMEMOIR passes also mFine, logL_PA only passes .m
if ~isfield(Sim, 'mFine')
Sim.mFine = Sim.m;
end
% If also sampling results should be plottet vs sigma points
if ~isfield(Sim, 'mFineTrue')
samples_vs_sp = 0;
else
samples_vs_sp = 1;
end
else
error('Not enough inputs.')
end
% Figure handle
s = varargin{3};
%if(~isvalid(fh))
fh(s) = figure;
% else
% if length(fh) < s
% fh(s) = figure;
% elseif(isempty(fh(s)))
% fh(s) = figure;
% end
% end
figure(fh(s));
% Simulations for sigma points
if nargin >= 4
SP = varargin{4};
else
SP = [];
end
% Options
options.data.col = 'b';
options.data.ls = 'none';
options.data.mean_lw = 2;
options.data.bound_lw = 1;
options.data.bound_ls = '--';
options.sim.col = 'r';
options.sim.area_col = [0.7,0.7,0.7];
options.sim.border_col = [0.6,0.6,0.6];
options.sim.ls = '-';
options.sim.mean_lw = 2;
options.sim.bound_lw = 1;
options.sim_true.col = 'g';
options.sim_true.area_col = [0.2,0.7,0.2];
options.sim_true.border_col = [0,0.6,0];
options.sim_true.ls = '--';
options.sim_true.mean_lw = 2;
options.sim_true.bound_lw = 1;
options.error.col = 'b';
options.error.ls = 'none';
options.error.lw = 1;
options.title = Data.name;
if nargin == 4
options = setdefault(varargin{4},options);
end
set(gcf,'Name',options.title);
%% Subplot dimensions
n_y = size(Sim.m, 2);
if ~isempty(Sim)
nc = 2;
nr = n_y;
else
nc = ceil(sqrt(n_y));
nr = ceil(n_y/nc);
end
% Check if this experiment is a dose response experiment
if (isfield(Data, 'condition') && ~isempty(Data.condition))
conditions = unique(Data.condition,'rows');
numConditions = size(conditions,1);
if (numConditions > 1)
% Get the label for the condition
if (isfield(Data, 'conditionName') && ~isempty(Data.conditionName))
conditionName = Data.conditionName;
else
warning('It looks like a dose-response-experiment should be plotted, but Data.conditionName is not set.');
conditionName = 'dose';
end
% Find the row, which contains the information about the dose
drRow = find(conditions(2,:) - conditions(1,:),1);
doses = conditions(:,drRow);
steps = Data.condition(:,drRow);
tmpSteps = nan(size(steps));
for iStep = 1:length(steps)
for iDose = 1:length(doses)
if (steps(iStep) == doses(iDose))
tmpSteps(iStep) = iDose;
end
end
end
dataSteps = tmpSteps;
steps = (1 : length(doses))';
else
steps = Sim.t;
dataSteps = Data.PA.time;
end
else
numConditions = 1;
if ~isempty(Sim)
steps = Sim.t;
end
dataSteps = Data.PA.time;
end
%% Visualization: Data and Simulation
if ~isempty(Sim)
% Loop: measurands
for j = 1:n_y
% Data and simulation
subplot(nr, nc, 2*(j-1)+1);
hold off;
lhCount = 1;
% Plot noise
lh(lhCount) = fill([steps(1:end); steps(end:-1:1)],...
[Sim.mFine(1:end,j) - Sim.Sigma_m(1:end,j);...
Sim.mFine(end:-1:1,j) + Sim.Sigma_m(end:-1:1,j)],...
options.sim.area_col);
hold on;
plot(steps, Sim.mFine(:,j) - Sim.Sigma_m(:,j),'-',...
'linewidth',options.sim.bound_lw,...
'linestyle',options.sim.ls,...
'color',options.sim.border_col);
plot(steps, Sim.mFine(:,j) +Sim.Sigma_m(:,j),'-',...
'linewidth',options.sim.bound_lw,...
'linestyle',options.sim.ls,...
'color',options.sim.border_col);
alpha(0.5);
if samples_vs_sp
% Plot noise
lhCount = lhCount + 1;
lh(lhCount) = fill([steps(1:end); steps(end:-1:1)],...
[Sim.mFineTrue(1:end,j) - Sim.Sigma_m(1:end,j);...
Sim.mFineTrue(end:-1:1,j) + Sim.Sigma_m(end:-1:1,j)],...
options.sim_true.area_col);
plot(steps, Sim.mFineTrue(:,j) - Sim.Sigma_m(:,j),'-',...
'linewidth',options.sim_true.bound_lw,...
'linestyle',options.sim_true.ls,...
'color',options.sim_true.border_col);
plot(steps, Sim.mFineTrue(:,j) + Sim.Sigma_m(:,j),'-',...
'linewidth',options.sim_true.bound_lw,...
'linestyle',options.sim_true.ls,...
'color',options.sim_true.border_col);
alpha(0.5);
end
% Plot data points
lhCount = lhCount + 1;
lh(lhCount) = plot(dataSteps, Data.PA.m(:,j), '+',...
'linewidth',options.data.mean_lw,...
'linestyle',options.data.ls,...
'color',options.data.col);
% Plot simulation
lhCount = lhCount + 1;
lh(lhCount) = plot(steps, Sim.mFine(:,j),'-',...
'linewidth',options.sim.mean_lw,...
'linestyle',options.sim.ls,...
'color',options.sim.col);
if samples_vs_sp
% Plot noise
lhCount = lhCount + 1;
lh(lhCount) = plot(steps, Sim.mFineTrue(:,j),'-',...
'linewidth',options.sim_true.mean_lw,...
'linestyle',options.sim_true.ls,...
'color',options.sim_true.col);
end
if (numConditions == 1)
xlabel('time');
else
xlabel(conditionName);
thisPlot = gca();
thisPlot.XTick = 1:length(doses);
thisPlot.XTickLabel = num2str(doses);
end
ylabel(Data.measurands{j});
xlim(dataSteps([1,end]));
if (j == 1)
if samples_vs_sp
legend(lh,{'noise (SP)', 'noise (Sam)', 'data', 'model (SP)', 'model (Sam)'});
else
legend(lh,{'noise', 'data', 'model'});
end
end
subplot(nr,nc,2*(j-1)+2);
hold off;
plot(dataSteps,Data.PA.m(:,j)-Sim.m(:,j),'o',...
'linewidth',options.error.lw,...
'linestyle',options.error.ls,...
'color',options.error.col); hold on;
if (numConditions == 1)
xlabel('time');
else
xlabel(conditionName);
thisPlot = gca();
thisPlot.XTick = 1:length(doses);
thisPlot.XTickLabel = num2str(doses);
end
ylabel(['error of mean(' Data.measurands{j} ')']);
xlim(steps([1,end]));
end
end
%% Visualization: Data
if isempty(Sim)
% Loop: measurands
for j = 1:n_y
subplot(nr,nc,j);
hold off;
plot(dataSteps, Data.PA.m(:,j), 'o',...
'linewidth',options.data.mean_lw,...
'linestyle',options.data.ls,...
'color',options.data.col);
hold on;
if (numConditions == 1)
xlabel('time');
else
xlabel(conditionName);
thisPlot = gca();
thisPlot.XTick = 1:length(doses);
thisPlot.XTickLabel = num2str(doses);
end
ylabel(['error of var(' Data.measurands{j} ')']);
xlim(dataSteps([1,end]));
end
end
%%
drawnow
end