-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodelSelectionPlot.m
More file actions
130 lines (102 loc) · 4.57 KB
/
Copy pathmodelSelectionPlot.m
File metadata and controls
130 lines (102 loc) · 4.57 KB
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
% ************************************************************************
% Function: modelSelectionPlot
% Purpose: Plot the results from the model selection as it progresses
%
% Parameters:
%
%
% Output:
% stop: flag instructing routines whether to stop
%
% ************************************************************************
function stop = modelSelectionPlot( results, state, opt, optPlot )
persistent modelOutputFigure count
stop = false;
switch state
case 'initial'
modelOutputFigure = figure();
count = 0;
case 'iteration'
figure( modelOutputFigure );
count = count + 1;
nVar = size( results.bestHP, 2 );
if opt.varJoint
bestHP = table2array( results.bestHP );
bestJoint = strcat( bestHP(1:count,2), {' + '}, bestHP(1:count,1) );
bestHPcat = categorical( bestJoint );
descr = strcat( results.descr(2), {' + '}, ...
results.descr(1) );
plotObj = histogram( bestHPcat );
set( plotObj, 'LineWidth', 1.5 );
xlabel( descr );
ylabel('Selection Frequency');
else
[ rows, cols ] = sqdim( nVar );
for i = 1:nVar
subplotObj = subplot( rows, cols, i );
if strcmp( results.varDef{i}.Type, 'real' )
bestHP = results.bestHP.(results.var(i))(1:count);
if results.isLog(i)
bestHP = log10( bestHP );
interval = ( log10(results.lim{i}(2)) ...
- log10(results.lim{i}(1)) )/100;
x = log10(results.lim{i}(1)):interval: ...
log10(results.lim{i}(2));
pdca = fitdist( bestHP , 'Kernel', 'Kernel', 'Normal' );
y = pdf( pdca, x );
y = y./sum(y);
x = 10.^x; % reverse transform
plotObj = semilogx( x, y ); % but plot with transform
else
interval = ( results.lim{i}(2) ...
- results.lim{i}(1) )/100;
x = results.lim{i}(1):interval: ...
results.lim{i}(2);
pdca = fitdist( bestHP , 'Kernel', 'Kernel', 'Normal' );
y = pdf( pdca, x );
y = y./sum(y);
plotObj = plot( x, y );
end
xlim( results.lim{i} );
ylabel('Selection Probability');
ytickformat( '%.3f' );
else
bestHP = results.bestHP.(results.var(i))(1:count);
if strcmp( results.var(i), 'standardize' )
temp = strings( length(bestHP), 1 );
temp( bestHP==1 ) = 'No';
temp( bestHP==2 ) = 'Yes';
bestHP = temp;
end
bestHP = categorical( bestHP );
plotObj = histogram( bestHP );
ylabel('Selection Frequency');
end
xlabel( results.descr(i) );
% set preferred properties
set( subplotObj, 'FontName', optPlot.font );
set( subplotObj, 'FontSize', optPlot.fontSize );
set( subplotObj, 'LineWidth', optPlot.axisLineWidth );
set( subplotObj, 'Box', optPlot.box );
set( subplotObj, 'TickDir', optPlot.tickDirection );
set( subplotObj, 'TickLength', optPlot.tickLength );
set( plotObj, 'LineWidth', optPlot.lineWidth );
end
end
drawnow;
case 'done'
fig = figure( modelOutputFigure );
nVar = size( results.bestHP, 2 );
for i = 1:nVar
subplotObj = fig.Children(nVar-i+1);
pos = subplotObj.Position(1:2) + [-0.1 0.14];
dim = [ pos 0.1 0.1 ];
annotation( 'textbox', dim, ...
'String', ['(' char(64+i) ')'], ...
'LineStyle', 'none', ...
'FontName', optPlot.font, ...
'FontSize', optPlot.fontSize+4 );
end
otherwise
end
end