forked from ICB-DCM/PESTO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotMultiStarts.m
203 lines (186 loc) · 6.57 KB
/
plotMultiStarts.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
function fh = plotMultiStarts(parameters, varargin)
% plotMultiStarts plots the result of the multi-start
% optimization stored in parameters.
%
% USAGE:
% fh = plotMultiStarts(parameters)
% fh = plotMultiStarts(parameters,fh)
% fh = plotMultiStarts(parameters,fh,options)
%
% plotMultiStarts() uses the following PestoPlottingOptions members:
% * PestoPlottingOptions::add_points
% * PestoPlottingOptions::title
% * PestoPlottingOptions::draw_bounds
%
% Parameters:
% parameters: parameter struct containing information about parameters
% and log-posterior.
% varargin:
% fh: handle of figure in which profile likelihood is plotted. If no
% figure handle is provided, a new figure is opened.
% options: options of plotting as instance of PestoPlottingOptions
%
% Return values:
% fh: figure handle
%
% History:
% * 2012/05/31 Jan Hasenauer
% * 2016/10/07 Daniel Weindl
%% CHECK AND ASSIGN INPUTS
% Check, if parameters has all necessary fieds
parameters = checkSanityOfStructs(parameters, 'parameters');
% Open figure
if length(varargin) >= 1 && ~isempty(varargin{1}) && isvalid(varargin{1})
fh = figure(varargin{1});
else
fh = figure('Name','plotMultiStarts');
end
% Options
defaultOptions = PestoPlottingOptions();
defaultOptions.add_points.par = [];
defaultOptions.add_points.logPost = [];
defaultOptions.add_points.col = [0,0.8,0];
defaultOptions.add_points.ls = '-';
defaultOptions.add_points.lw = 1;
defaultOptions.add_points.m = 'd';
defaultOptions.add_points.ms = 8;
defaultOptions.add_points.name = 'add. point';
if length(varargin) >= 2
options = varargin{2};
options = handlePlottingOptionArgument(options);
options = setdefault(options, defaultOptions);
options.add_points = setdefault(options.add_points, defaultOptions.add_points);
else
options = defaultOptions;
end
%% SORT RESULTS
[parameters] = sortMultiStarts(parameters);
%% CLUSTERING
n_starts = length(parameters.MS.logPost);
if (n_starts > 1)
clust = cluster(linkage(pdist(parameters.MS.logPost)),'cutoff',0.1,'criterion','distance');
else
clust = 1;
end
uclust = unique(clust);
for iclust = 1:length(uclust)
sizecluster(iclust) = sum(clust == uclust(iclust));
end
%% ASSIGN COLORS
Col = colormap(gray(n_starts+ceil(n_starts/3)));
Col = Col.^(1/3);
Col(1,:) = [1,0,0];
% sort clusters
for iclust = 1:length(uclust)
Jclust(iclust) = max(parameters.MS.logPost(find(clust == uclust(iclust))));
end
Jclust(isnan(Jclust)) = -Inf;
[~,idx] = sort(Jclust,'descend');
uclust = uclust(idx);
sizecluster = sizecluster(idx);
if(sizecluster(1)>1)
ColClust = [1,0,0;flipud(parula(max(sum(sizecluster>1)-1,0)))];
else
ColClust = flipud(parula(sum(sizecluster>1)));
end
for iclust = 1:length(uclust)
if(sizecluster(iclust)>1)
Col(clust == uclust(iclust),:) = repmat(ColClust(sum(sizecluster(1:iclust)>1),:),[sizecluster(iclust),1]);
end
end
%% PLOT OBJECTIVES
subplot(2,2,1);
n_finished_starts = 0;
for j = 1 : n_starts
if ~isnan(parameters.MS.logPost(j))
n_finished_starts = j;
else
break;
end
end
plot(1:n_finished_starts,parameters.MS.logPost(1:n_finished_starts),'-','color',0.9*[1,1,1],'linewidth',2);
hold on;
for j = n_finished_starts:-1:1
plot(j,parameters.MS.logPost(j),'o','color',Col(j,:),'linewidth',2);
hold on;
end
if ~isempty(options.add_points.logPost)
if length(options.add_points.logPost) == 1
if (n_starts == 1)
addPointsX = [0.85 1.15];
addPointsY = options.add_points.logPost * [1 1];
else
addPointsX = 1 : n_starts;
addPointsY = options.add_points.logPost * ones(size(1:n_starts));
end
plot(addPointsX,addPointsY,options.add_points.ls,'color',...
options.add_points.col(1,:),'linewidth',options.add_points.lw);
hold on;
else
plot(1:length(options.add_points.logPost),options.add_points.logPost,...
options.add_points.ls,'color',options.add_points.col(1,:),...
'linewidth',options.add_points.lw,'marker',options.add_points.m,...
'markersize',options.add_points.ms); hold on;
end
end
hold off;
xlim([1-0.2,n_starts+0.2]);
xlabel('start');
ylabel('log-likelihood');
if options.title
title('all estimates');
end
%% PLOT TOP TEN OBJECTIVES
subplot(2,2,3);
plot(1:min(n_starts,10),parameters.MS.logPost(1:min(n_starts,10)),'-','color',0.9*[1,1,1],'linewidth',2); hold on;
for j = min(n_starts,10):-1:1
plot(j,parameters.MS.logPost(j),'o','color',Col(j,:),'linewidth',2); hold on;
end
if ~isempty(options.add_points.logPost)
if length(options.add_points.logPost) == 1
plot(1:min(n_starts,10),options.add_points.logPost*ones(size(1:min(n_starts,10))),...
options.add_points.ls,'color',options.add_points.col(1,:),...
'linewidth',options.add_points.lw); hold on;
else
plot(1:min(length(options.add_points.logPost),10),options.add_points.logPost(1:min(length(options.add_points.logPost),10)),...
options.add_points.ls,'color',options.add_points.col(1,:),...
'linewidth',options.add_points.lw,'marker',options.add_points.m,...
'markersize',options.add_points.ms); hold on;
end
end
hold off;
xlim([1-0.2,min(n_starts,10)+0.2]);
if(any(~isnan(parameters.MS.logPost(1:min(n_starts,10)))))
ylim([min(parameters.MS.logPost(1),min(parameters.MS.logPost(1:min(n_starts,10)))-1),parameters.MS.logPost(1)+1]);
end
xlabel('start');
ylabel('log-likelihood');
if options.title
title('top 10 estimates');
end
%% PLOT PARAMETERS
subplot(2,2,[2,4]);
for j = n_finished_starts:-1:1
plot(parameters.MS.par(:,j)',1:parameters.number,'-o','color',Col(j,:),'linewidth',2); hold on;
end
plot(parameters.MS.par(:,1)',1:parameters.number,'r-o','linewidth',2); hold on;
if options.draw_bounds
plot(parameters.min([1,1:parameters.number,parameters.number])',[0.99,1:parameters.number,parameters.number+0.01],'b--','linewidth',2); hold on;
plot(parameters.max([1,1:parameters.number,parameters.number])',[0.99,1:parameters.number,parameters.number+0.01],'b--','linewidth',2); hold on;
end
if ~isempty(options.add_points.logPost)
for j = 1:size(options.add_points.par,2)
plot(options.add_points.par(:,j)',1:parameters.number,options.add_points.ls,...
'color',options.add_points.col(1,:),'linewidth',options.add_points.lw,...
'marker',options.add_points.m,'markersize',options.add_points.ms); hold on;
end
end
hold off;
ylim([1-0.01,parameters.number+0.01]);
ylabel(' ');
xlabel('parameter value');
set(gca,'ytick',1:parameters.number,'yticklabel',parameters.name)
if options.title
title('estimated parameters');
end
drawnow;