Home > . > prt_plot_histograms.m

prt_plot_histograms

PURPOSE ^

FORMAT prt_plot_histograms(PRT, model, fold, axes_handle)

SYNOPSIS ^

function prt_plot_histograms(PRT, model, fold, axes_handle)

DESCRIPTION ^

 FORMAT prt_plot_histograms(PRT, model, fold, axes_handle)

 This function plots 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.

 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function prt_plot_histograms(PRT, model, fold, axes_handle)
0002 % FORMAT prt_plot_histograms(PRT, model, fold, axes_handle)
0003 %
0004 % This function plots the histogram that appears on prt_ui_results.
0005 %
0006 % The maximum number of classes that can be ploted is 7. However, this can
0007 % be increased by editing the function. Just add more colours to the
0008 % colourList variable.
0009 %
0010 % Inputs:
0011 %       PRT             - data/design/model structure (it needs to contain
0012 %                         at least one estimated model).
0013 %       model           - the number of the model that will be ploted
0014 %       fold            - the number of the fold
0015 %       axes_handle     - (Optional) axes where the plot will be displayed
0016 %
0017 % Output:
0018 %       None
0019 %__________________________________________________________________________
0020 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
0021 
0022 % Written by M. J. Rosa
0023 % $Id: prt_plot_histograms.m 706 2013-06-07 14:33:34Z cphillip $
0024 
0025 nfold = length(PRT.model(model).output.fold);
0026 
0027 
0028 %Check the number of classes
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     % if folds wise
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 %Make list of classes
0072 for i=1:nClasses
0073     classNames{i} = PRT.model(model).input.class(i).class_name;
0074 end
0075 %If you want to use more classes, just add more colours to the list bellow
0076 colourList = {'black','red', 'blue', 'green', 'cyan', 'magenta', 'yellow'};
0077 
0078 
0079 %If no axes_handle is given, create a new window
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 %                 axis xy
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                     % can't plot density, be happy with a histogram
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]; % makes a list of the classes used in the plot
0110             end
0111         end
0112         
0113         %Make list of classes used to put in the legend
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         % do nothing, no func_val available
0124     end
0125     
0126 else
0127     error(['Too many classes, Max number of classes: ' num2str(length(colourList))]);
0128 end

Generated on Tue 10-Feb-2015 18:16:33 by m2html © 2005