0001 function prt_plot_histograms(PRT, model, fold, axes_handle)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 nfold = length(PRT.model(model).output.fold);
0026
0027
0028
0029 nClasses = length(PRT.model(model).input.class);
0030
0031 if fold == 1
0032 fVals = [];
0033 targets = [];
0034
0035 for f = 1:nfold,
0036 targets = [targets;PRT.model(model).output.fold(f).targets];
0037 if isfield(PRT.model(model).output.fold(f),'func_val')
0038 fVvals_exist = 1;
0039 fVals = [fVals;PRT.model(model).output.fold(f).func_val];
0040 else
0041 fVvals_exist = 0;
0042 fVals = [fVals;...
0043 PRT.model(model).output.fold(f).predictions];
0044 end
0045 end
0046
0047
0048 for i=1:nClasses
0049 targval(:, i) = targets == i;
0050 end
0051
0052 else
0053
0054 targets = PRT.model(model).output.fold(fold-1).targets;
0055
0056 for i=1:nClasses
0057 targval(:, i) = targets == i;
0058 end
0059
0060
0061 if isfield(PRT.model(model).output.fold(fold-1),'func_val')
0062 fVals = PRT.model(model).output.fold(fold-1).func_val;
0063 fVvals_exist = 1;
0064 else
0065 fVvals_exist = 0;
0066 fVals = PRT.model(model).output.fold(fold-1).predictions;
0067 end
0068 end
0069
0070
0071
0072 for i=1:nClasses
0073 classNames{i} = PRT.model(model).input.class(i).class_name;
0074 end
0075
0076 colourList = {'black','red', 'blue', 'green', 'cyan', 'magenta', 'yellow'};
0077
0078
0079
0080 if ~exist('axes_handle', 'var')
0081 figure;
0082 axes_handle = axes;
0083 else
0084 set(axes_handle, 'XScale','linear');
0085 end
0086
0087 cla(axes_handle, 'reset');
0088 rotate3d off
0089
0090 set(axes_handle,'Color',[1,1,1])
0091
0092 if nClasses <= length(colourList)
0093 if fVvals_exist
0094 classes_used = [];
0095 for cl=1:nClasses
0096 func_vals = fVals(targval(:,cl));
0097 if ~isempty(func_vals)
0098 if exist('ksdensity','file')==2
0099 [f,x] = ksdensity(func_vals,'width',[]);
0100 plot(axes_handle,x,f,colourList{cl},'LineWidth',2);
0101 hold(axes_handle,'on')
0102 else
0103
0104 [myHist,myX]=hist(func_vals,100);
0105 bar(axes_handle,myX,myHist,colourList{cl});
0106 hold(axes_handle,'on')
0107 end
0108 if cl == nClasses, hold(axes_handle,'off'); end
0109 classes_used = [classes_used,cl];
0110 end
0111 end
0112
0113
0114 nClasses_used = length(classes_used);
0115 for i=1:nClasses_used
0116 classNames_legend{i} = classNames{classes_used(i)};
0117 end
0118
0119 legend(axes_handle,classNames_legend);
0120
0121 xlabel(axes_handle,'function value','FontWeight','bold');
0122 else
0123
0124 end
0125
0126 else
0127 error(['Too many classes, Max number of classes: ' num2str(length(colourList))]);
0128 end