-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprt_plot_histograms.m
More file actions
130 lines (110 loc) · 3.87 KB
/
Copy pathprt_plot_histograms.m
File metadata and controls
130 lines (110 loc) · 3.87 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 prt_plot_histograms(PRT, model, fold, axes_handle)
% Function to plot the histogram that appears on prt_ui_results.
%
% The maximum number of classes that can be ploted is 7. However, this can
% be increased by editing the function. Just add more colours to the
% colourList variable.
%
% FORMAT prt_plot_histograms(PRT, model, fold, axes_handle)
% Inputs:
% PRT - data/design/model structure (it needs to contain
% at least one estimated model).
% model - the number of the model that will be ploted
% fold - the number of the fold
% axes_handle - (Optional) axes where the plot will be displayed
%
% Output:
% None
%__________________________________________________________________________
% Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
% Written by M. J. Rosa
% $Id: prt_plot_histograms.m 706 2013-06-07 14:33:34Z cphillip $
nfold = length(PRT.model(model).output.fold);
%Check the number of classes
nClasses = length(PRT.model(model).input.class);
if fold == 1
fVals = [];
targets = [];
for f = 1:nfold,
targets = [targets;PRT.model(model).output.fold(f).targets];
if isfield(PRT.model(model).output.fold(f),'func_val')
fVvals_exist = 1;
fVals = [fVals;PRT.model(model).output.fold(f).func_val];
else
fVvals_exist = 0;
fVals = [fVals;...
PRT.model(model).output.fold(f).predictions];
end
end
for i=1:nClasses
targval(:, i) = targets == i;
end
else
% if folds wise
targets = PRT.model(model).output.fold(fold-1).targets;
for i=1:nClasses
targval(:, i) = targets == i;
end
if isfield(PRT.model(model).output.fold(fold-1),'func_val')
fVals = PRT.model(model).output.fold(fold-1).func_val;
fVvals_exist = 1;
else
fVvals_exist = 0;
fVals = PRT.model(model).output.fold(fold-1).predictions;
end
end
%Make list of classes
for i=1:nClasses
classNames{i} = PRT.model(model).input.class(i).class_name;
end
%If you want to use more classes, just add more colours to the list bellow
colourList = [0 0 0; 1 0 0; cbrewer('qual','Set3',max(nClasses,3))];
%If no axes_handle is given, create a new window
if ~exist('axes_handle', 'var')
figure;
axes_handle = axes;
else
set(axes_handle, 'XScale','linear');
end
cla(axes_handle, 'reset');
rotate3d off
% axis xy
set(axes_handle,'Color',[1,1,1])
classNames_legend = {};
if fVvals_exist
classes_used = [];
for cl=1:nClasses
func_vals = fVals(targval(:,cl));
if ~isempty(func_vals)
if exist('ksdensity','file')==2
[f,x] = ksdensity(func_vals,'width',[]);
plot(axes_handle,x,f,'Color',colourList(cl,:),'LineWidth',2);
hold(axes_handle,'on')
else
% can't plot density, be happy with a histogram
[myHist,myX]=hist(func_vals,100);
bar(axes_handle,myX,myHist,'Color',colourList(cl,:));
hold(axes_handle,'on')
end
if cl == nClasses, hold(axes_handle,'off'); end
classes_used = [classes_used,cl]; % makes a list of the classes used in the plot
end
end
%Make list of classes used to put in the legend
nClasses_used = length(classes_used);
for i=1:nClasses_used
classNames_legend{i} = classNames{classes_used(i)};
end
xlabel(axes_handle,'function value','FontWeight','bold');
else
% do nothing, no func_val available
end
hold on
lims = get(axes_handle,'YLim');
if strcmp(PRT.model(model).input.machine.function,'prt_machine_gpml')
x = 0.5*ones(2,1);
else
x = zeros(2,1);
end
plot(axes_handle,x,lims,'--','Color',[1 1 1]*.6);
legend(axes_handle,[classNames_legend,{'Threshold'}]);