-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvisualize_inputSel.m
111 lines (96 loc) · 3.77 KB
/
visualize_inputSel.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
function [X, R2] = visualize_inputSel( iis_res, Nvar, Nrun, max_iter, map )
% [X, R2] = visualize_inputSel( iis_res, Nvar, Nrun, max_iter, map )
%
% This function plots the results of multiple runs of the IIS algorithm to
% analyze the input ranking and the variability of the final MISO models'
% performance over different runs.
%
% input:
% iis_res = cell array containing the output of the
% iterative_input_selection funtion
% Nvar = number of candidate input variables (in theory this is
% equal to the number of columns of the dataset, in practice
% it can be reduced to max_iter)
% Nrun = number of IIS runs
% max_iter = max number of iterations in each run of IIS
% map = colormap (default = hot)
%
% output:
% X = matrix containing the indices of the selected input for
% each run (on the columns)
% R2 = corresponding model performance
%
%
% Copyright 2014 Stefano Galelli and Matteo Giuliani
% Assistant Professor, Singapore University of Technology and Design
% http://people.sutd.edu.sg/~stefano_galelli/index.html
% Research Fellow, Politecnico di Milano
% http://home.deib.polimi.it/giuliani/
%
%
% Please refer to README.txt for further information.
%
%
% This file is part of MATLAB_IterativeInputSelection.
%
% MATLAB_IterativeInputSelection is free software: you can redistribute
% it and/or modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation, either version 3 of the
% License, or (at your option) any later version.
%
% This code is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with MATLAB_IterativeInputSelection.
% If not, see <http://www.gnu.org/licenses/>.
%
% check number of inputs
if(nargin<4)
error( 'too few arguments' ) ;
error( 'usage: visualize_inputSel( iis_res, Nvar, Nrun, max_iter, map ) ' );
end
if(nargin<5)
mymap = 'Hot';
else
mymap = map;
end
% extract results
sel_variables = nan(Nvar,Nrun);
R2 = nan(Nvar,Nrun);
for i = 1:Nrun
eval(['result_iis = iis_res{',num2str(i),'};'])
if strcmp(result_iis.exit_condition,...
'An input variable was selected twice') == 1
nVariables = length(fieldnames(result_iis)) - 3;
else if strcmp(result_iis.exit_condition,...
'The maximum number of iterations was reached') == 1
nVariables = max_iter;
else
nVariables = length(fieldnames(result_iis)) - 2;
end
end
for j = 1: nVariables % max_iter-1
eval(['sel_variables(j,i) = iis_res{',num2str(i),'}.iter_',num2str(j),'.best_SISO(1);']);
eval(['R2(j,i) = iis_res{',num2str(i),'}.iter_',num2str(j),'.MISO.cross_validation.performance.Rt2_val_pred_mean;']);
if( j>1) && (R2(j,i) < R2(j-1,i)) % check overfitting
sel_variables(j,i) = nan;
R2(j,i) = nan;
end
end
end
% selected variables and model performance over multiple runs
X = sel_variables;
X(isnan(X)) = 0;
figure; subplot(2,1,1); imagesc(X); colormap(mymap)
ylabel('input ranking');
subplot(2,1,2); plot(max(R2), 'k', 'LineWidth', 2); grid on;
axis([1 Nrun fix(min(max(R2))*100)/100 fix(max(max(R2))*100+1)/100]);
ylabel('model performance R2');
xlabel('IIS run');
% This code has been written by Matteo Giuliani.
end