Home > . > prt_plot_prediction.m

prt_plot_prediction

PURPOSE ^

FORMAT prt_plot_prediction(PRT, model, fold, marker_size, axes_handle)

SYNOPSIS ^

function prt_plot_prediction(PRT, model, fold, marker_size, axes_handle)

DESCRIPTION ^

 FORMAT prt_plot_prediction(PRT, model, fold, marker_size, axes_handle)

 This function plots the prediction plot that appears on prt_ui_results
 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
       marker_size     - (Optional) the size of the markers in the plot,
                         the default is 7
       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_prediction(PRT, model, fold, marker_size, axes_handle)
0002 % FORMAT prt_plot_prediction(PRT, model, fold, marker_size, axes_handle)
0003 %
0004 % This function plots the prediction plot that appears on prt_ui_results
0005 % Inputs:
0006 %       PRT             - data/design/model structure (it needs to contain
0007 %                         at least one estimated model).
0008 %       model           - the number of the model that will be ploted
0009 %       fold            - the number of the fold
0010 %       marker_size     - (Optional) the size of the markers in the plot,
0011 %                         the default is 7
0012 %       axes_handle     - (Optional) axes where the plot will be displayed
0013 %
0014 % Output:
0015 %       None
0016 %__________________________________________________________________________
0017 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
0018 
0019 % Written by M. J. Rosa
0020 % $Id: prt_plot_prediction.m 706 2013-06-07 14:33:34Z cphillip $
0021 
0022 
0023 nfold = length(PRT.model(model).output.fold);
0024 bcl = 0;
0025 
0026 
0027 fVals   = [];
0028 targets = [];
0029 
0030 for f = 1:nfold,
0031     targets = [targets;PRT.model(model).output.fold(f).targets];
0032     if isfield(PRT.model(model).output.fold(f),'func_val')
0033         fVvals_exist = 1;
0034         fVals  = [fVals;PRT.model(model).output.fold(f).func_val];
0035     else
0036         fVvals_exist = 0;
0037         fVals  = [fVals;...
0038             PRT.model(model).output.fold(f).predictions];
0039     end
0040 end
0041 tarmax = max(targets);
0042 if fold==1
0043     targpos = targets == 1;
0044     if length(find(targpos))~=length(targets) && ~isempty(find(targpos))
0045         %both classes are present across all folds (for class labels)
0046         bcl = 1;
0047     end
0048 end
0049     
0050 if fold>1
0051     % if folds wise
0052     targets = PRT.model(model).output.fold(fold-1).targets;
0053     targpos = targets == tarmax;
0054     if isfield(PRT.model(model).output.fold(fold-1),'func_val')
0055         fVals  = PRT.model(model).output.fold(fold-1).func_val;
0056         fVvals_exist = 1;
0057     else
0058         fVvals_exist = 0;
0059         fVals  = PRT.model(model).output.fold(fold-1).predictions;
0060     end
0061 end
0062 
0063 
0064 %Defined the marker size, if no value is given
0065 if ~exist('marker_size', 'var')
0066     marker_size = 7;
0067 end
0068 %If no axes_handle is given, create a new window
0069 if ~exist('axes_handle', 'var')
0070     figure;
0071     axes_handle = axes;
0072 else
0073     set(axes_handle, 'XScale','linear');
0074 end
0075 
0076 cla(axes_handle, 'reset');
0077 rotate3d off
0078 colorbar('peer',axes_handle,'off')
0079 set(axes_handle,'Color',[1,1,1])
0080 % predictions
0081 if fVvals_exist
0082     if fold == 1
0083         foldlabels = 1:nfold;
0084         for f = 2:nfold+1
0085             targets = PRT.model(model).output.fold(f-1).targets;
0086             targpos = targets == tarmax; %both for SVM and GP, linear
0087             fVals   = PRT.model(model).output.fold(f-1).func_val;
0088             func_valsc1 = fVals(targpos);
0089             func_valsc2 = fVals(~targpos);
0090             yc1 = (f-1)*ones(length(func_valsc1),1);
0091             yc2 = (f-1)*ones(length(func_valsc2),1);
0092             if f==2
0093                 maxfv = max(abs([func_valsc1;func_valsc2]));
0094             else
0095                 maxtmp = max(abs([func_valsc1;func_valsc2]));
0096                 if maxfv < maxtmp, maxfv = maxtmp; end
0097             end
0098             pl1 = plot(axes_handle,func_valsc1,yc1,'kx','MarkerSize',marker_size);
0099             hold(axes_handle,'on');
0100             if ~isempty(yc1), isyc1 = 1; plot1 = pl1; else isyc1 = 0; end
0101             pl2 = plot(axes_handle,func_valsc2,yc2,'ro','MarkerSize',marker_size);
0102             hold(axes_handle,'on');
0103             if ~isempty(yc2), isyc2 = 1; plot2 = pl2; else isyc2 = 0; end
0104         end
0105     else
0106         foldlabels  = fold-1;
0107         func_valsc1 = fVals(targpos);
0108         func_valsc2 = fVals(~targpos);
0109         yc1 = (fold-1)*ones(length(func_valsc1),1);
0110         yc2 = (fold-1)*ones(length(func_valsc2),1);
0111         maxfv = max(abs([func_valsc1;func_valsc2]));
0112         pl1 = plot(axes_handle,func_valsc1,yc1,'kx','MarkerSize',marker_size);
0113         hold(axes_handle,'on');
0114         if ~isempty(yc1), isyc1 = 1; plot1 = pl1; else isyc1 = 0; end
0115         pl2 = plot(axes_handle,func_valsc2,yc2,'ro','MarkerSize',marker_size);
0116         hold(axes_handle,'on');
0117         if ~isempty(yc2), isyc2 = 1; plot2 = pl2; else isyc2 = 0;  end
0118     end
0119     % Change the x axis for gaussian process or RT - change in
0120     % the future
0121     y = [0:nfold+1]';
0122     if strcmp(PRT.model(model).input.machine.function,'prt_machine_gpml');
0123         x = 0.5*ones(nfold+2,1);
0124         plot(axes_handle,x,y,'--','Color',[1 1 1]*.6);
0125         xlim(axes_handle,[0 1]);
0126     elseif strcmp(PRT.model(model).input.machine.function,'prt_machine_RT_bin')
0127         % nothing to do - just leave auto scaling
0128     else
0129         x = zeros(nfold+2,1);
0130         plot(axes_handle,x,y,'--','Color',[1 1 1]*.6);
0131         xlim(axes_handle,[-maxfv-0.5 maxfv+0.5]);
0132     end
0133     ylim(axes_handle,[0 nfold+1.3]);
0134     xlabel(axes_handle,'function value','FontWeight','bold');
0135     h=ylabel(axes_handle,'fold','FontWeight','bold');
0136     set(h,'Rotation',90)
0137     
0138     %These 2 lines were added. See if it's better to give the class names
0139     %as input
0140     classNames{1} = PRT.model(model).input.class(2).class_name;
0141     classNames{2} = PRT.model(model).input.class(1).class_name;
0142     
0143     
0144     if (isyc1 && isyc2) || bcl
0145         legend([plot1,plot2],classNames,'Color',[1,1,1]);
0146     else
0147         if isyc1
0148             legend(plot1,classNames{1});
0149         else
0150             legend(plot2,classNames{2});
0151         end
0152     end
0153     set(axes_handle,'YTick',foldlabels)
0154     hold(axes_handle,'off');
0155     set(axes_handle,'Color',[1,1,1],'Visible','on')
0156     %                 axis normal
0157     %                 axis xy
0158     title(axes_handle,'')
0159 else
0160     set(axes_handle,'Color',[1,1,1])
0161     beep
0162     disp('No function values to display!')
0163 end

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