Home > . > prt_ui_custom_CV.m

prt_ui_custom_CV

PURPOSE ^

PRT_UI_CUSTOM_CV M-file for prt_ui_custom_CV.fig

SYNOPSIS ^

function varargout = prt_ui_custom_CV(varargin)

DESCRIPTION ^

 PRT_UI_CUSTOM_CV M-file for prt_ui_custom_CV.fig
 
 PRT_UI_CUSTOM_CV, by itself, creates a new PRT_UI_CUSTOM_CV or 
 raises the existing singleton*.

 H = PRT_UI_CUSTOM_CV returns the handle to a new PRT_UI_CUSTOM_CV 
 or the handle to the existing singleton*.

 PRT_UI_CUSTOM_CV('CALLBACK',hObject,eventData,handles,...) calls the 
 local function named CALLBACK in PRT_UI_CUSTOM_CV.M with the given 
 input arguments.

 PRT_UI_CUSTOM_CV('Property','Value',...) creates a new PRT_UI_CUSTOM_CV
 or raises the existing singleton*.  Starting from the left, property 
 value pairs are applied to the GUI before prt_ui_custom_CV_OpeningFcn 
 gets called.  An unrecognized property name or invalid value makes 
 property application stop.  All inputs are passed to prt_ui_custom_CV_OpeningFcn
 via varargin.

 *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
  instance to run (singleton)".

 See also: GUIDE, GUIDATA, GUIHANDLES
__________________________________________________________________________
 Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = prt_ui_custom_CV(varargin)
0002 % PRT_UI_CUSTOM_CV M-file for prt_ui_custom_CV.fig
0003 %
0004 % PRT_UI_CUSTOM_CV, by itself, creates a new PRT_UI_CUSTOM_CV or
0005 % raises the existing singleton*.
0006 %
0007 % H = PRT_UI_CUSTOM_CV returns the handle to a new PRT_UI_CUSTOM_CV
0008 % or the handle to the existing singleton*.
0009 %
0010 % PRT_UI_CUSTOM_CV('CALLBACK',hObject,eventData,handles,...) calls the
0011 % local function named CALLBACK in PRT_UI_CUSTOM_CV.M with the given
0012 % input arguments.
0013 %
0014 % PRT_UI_CUSTOM_CV('Property','Value',...) creates a new PRT_UI_CUSTOM_CV
0015 % or raises the existing singleton*.  Starting from the left, property
0016 % value pairs are applied to the GUI before prt_ui_custom_CV_OpeningFcn
0017 % gets called.  An unrecognized property name or invalid value makes
0018 % property application stop.  All inputs are passed to prt_ui_custom_CV_OpeningFcn
0019 % via varargin.
0020 %
0021 % *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
0022 %  instance to run (singleton)".
0023 %
0024 % See also: GUIDE, GUIDATA, GUIHANDLES
0025 %__________________________________________________________________________
0026 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
0027 
0028 % Written by J. Schrouff
0029 % $Id: prt_ui_custom_CV.m 672 2013-03-18 14:48:18Z schrouff $
0030 
0031 % Edit the above text to modify the response to help prt_ui_custom_CV
0032 
0033 % Last Modified by GUIDE v2.5 15-Jul-2013 13:13:28
0034 
0035 % Begin initialization code - DO NOT EDIT
0036 gui_Singleton = 1;
0037 gui_State = struct('gui_Name',       mfilename, ...
0038                    'gui_Singleton',  gui_Singleton, ...
0039                    'gui_OpeningFcn', @prt_ui_custom_CV_OpeningFcn, ...
0040                    'gui_OutputFcn',  @prt_ui_custom_CV_OutputFcn, ...
0041                    'gui_LayoutFcn',  [] , ...
0042                    'gui_Callback',   []);
0043 if nargin && ischar(varargin{1})
0044     gui_State.gui_Callback = str2func(varargin{1});
0045 end
0046 
0047 if nargout
0048     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0049 else
0050     gui_mainfcn(gui_State, varargin{:});
0051 end
0052 % End initialization code - DO NOT EDIT
0053 
0054 
0055 % --- Executes just before prt_ui_custom_CV is made visible.
0056 function prt_ui_custom_CV_OpeningFcn(hObject, eventdata, handles, varargin)
0057 % This function has no output args, see OutputFcn.
0058 % hObject    handle to figure
0059 % eventdata  reserved - to be defined in a future version of MATLAB
0060 % handles    structure with handles and user data (see GUIDATA)
0061 % varargin   command line arguments to prt_ui_custom_CV (see VARARGIN)
0062 
0063 set(handles.figure1,'Name','PRoNTo :: Custom Cross-Validation')
0064 %set size of the window, taking screen resolution and platform into account
0065 S0= spm('WinSize','0',1);   %-Screen size (of the current monitor)
0066 if ispc
0067     PF='MS Sans Serif';
0068 else
0069     PF= spm_platform('fonts');     %-Font names (for this platform)
0070     PF=PF.helvetica;
0071 end
0072 tmp  = [S0(3)/1280 (S0(4))/800];
0073 ratio=min(tmp)*[1 1 1 1];
0074 FS = 1 + 0.85*(min(ratio)-1);  %factor to scale the fonts
0075 x=get(handles.figure1,'Position');
0076 set(handles.figure1,'DefaultTextFontSize',FS*12,...
0077     'DefaultUicontrolFontSize',FS*12,...
0078     'DefaultTextFontName',PF,...
0079     'DefaultAxesFontName',PF,...
0080     'DefaultUicontrolFontName',PF)
0081 set(handles.figure1,'Position',ratio.*x)
0082 set(handles.figure1,'Resize','on')
0083 
0084 % Choose the color of the different backgrounds and figure parameters
0085 color=prt_get_defaults('color');
0086 set(handles.figure1,'Color',color.bg1)
0087 aa=get(handles.figure1,'children');
0088 for i=1:length(aa)
0089     if strcmpi(get(aa(i),'type'),'uipanel')
0090         set(aa(i),'BackgroundColor',color.bg2)
0091         bb=get(aa(i),'children');
0092         if ~isempty(bb)
0093             for j=1:length(bb)
0094                 if isfield(get(bb(j)),'Style')
0095                 if ~isempty(find(strcmpi(get(bb(j),'Style'),{'text',...
0096                         'radiobutton','checkbox'}))) 
0097                     set(bb(j),'BackgroundColor',color.bg2)
0098                 elseif ~isempty(find(strcmpi(get(bb(j),'Style'),'pushbutton'))) 
0099                     set(bb(j),'BackgroundColor',color.fr)
0100                 end
0101                 set(bb(j),'FontUnits','pixel')
0102                 xf=get(bb(j),'FontSize');
0103                 set(bb(j),'FontSize',ceil(FS*xf),'FontName',PF,...
0104                     'FontUnits','normalized','Units','normalized')
0105                 end
0106             end
0107         end
0108     elseif strcmpi(get(aa(i),'type'),'uicontrol')
0109         if ~isempty(find(strcmpi(get(aa(i),'Style'),{'text',...
0110                 'radiobutton','checkbox','listbox'})))
0111             set(aa(i),'BackgroundColor',color.bg1)
0112         elseif ~isempty(find(strcmpi(get(aa(i),'Style'),'pushbutton')))
0113             set(aa(i),'BackgroundColor',color.fr)
0114         end
0115     end
0116     set(aa(i),'FontUnits','pixel')
0117     xf=get(aa(i),'FontSize');
0118     if ispc
0119         set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
0120             'FontUnits','normalized','Units','normalized')
0121     else
0122         set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
0123             'Units','normalized')
0124     end
0125 end
0126 
0127 
0128 %get information from the PRT.mat
0129 if ~isempty(varargin)
0130     handles.CV=varargin{1};
0131     dat=num2cell(handles.CV);
0132     handles.ID=varargin{2};
0133     handles.in=varargin{3};
0134     handles.prt=varargin{4};
0135     handles.leg=varargin{5};
0136 end
0137 set(handles.editcv,'Data',dat);
0138 disp_CV(hObject,handles,handles.ID,handles.CV)
0139 set(handles.editcv,'ColumnEditable',true(1,size(handles.CV,2)));
0140 lc=cell(size(handles.CV,2),1);
0141 for i=1:size(handles.CV,2)
0142     lc{i}=['fold ',num2str(i)];
0143 end
0144 set(handles.editcv,'ColumnName',lc)
0145 lr=cell(size(handles.CV,1),1);
0146 ID = handles.ID;
0147 ng = length(unique(ID(:,1)));
0148 if ng>1 % Labels of table contain the group names
0149     for i = 1:length(lr)
0150         lr{i}=[handles.prt.group(ID(i,1)).gr_name,' '];
0151     end
0152 end
0153 ns = length(unique(ID(:,2)));
0154 if ns>1  % Labels of table contain the subject names
0155     for i = 1:length(lr)
0156         lr{i}=[lr{i},...
0157             handles.prt.group(ID(i,1)).subject(ID(i,2)).subj_name,' '];
0158     end
0159 end      
0160 nm = length(unique(ID(:,3)));
0161 if nm>1  % Labels of table contain the modality names
0162     for i = 1:length(lr)
0163         lr{i}=[lr{i},...
0164             handles.prt.group(ID(i,1)).subject(ID(i,2)).modality(ID(i,3)).mod_name,...
0165             ' '];
0166     end
0167 end
0168             
0169 nc = length(unique(ID(:,4)));
0170 if nc>1  % Labels of table contain the modality names
0171     for i = 1:length(lr)
0172         lr{i}=[lr{i},...
0173             handles.prt.group(ID(i,1)).subject(ID(i,2)).modality(ID(i,3)).design.conds(ID(i,4)).cond_name,...
0174             ' '];
0175     end
0176 end
0177 
0178 
0179 % lg=unique(lg);
0180 % lc=unique(lc);
0181 % if isempty(lg)
0182 %     nc=char([handles.leg.lc]);
0183 %     [du1,loc]=ismember(lc,handles.leg.lci);
0184 %     nc=nc(loc,:);
0185 % elseif isempty(lc)
0186 %     nc=char([handles.leg.lg]);
0187 %     [du1,loc]=ismember(lg,handles.leg.lcg);
0188 %     nc=nc(loc,:);
0189 % else
0190 %     [du1,loc]=ismember(lc,handles.leg.lci);
0191 %     [du1,loc1]=ismember(lg,handles.leg.lcg);
0192 %     nc=char([handles.leg.lg(loc1);handles.leg.lc(loc)]);
0193 % end
0194 % sg='c';
0195 % lc=[repmat(sg,length(lc),1), num2str(lc),repmat('   ',length(lc),1)];
0196 % sg='G';
0197 % lg=[repmat(sg,length(lg),1), num2str(lg),repmat('   ',length(lg),1)];
0198 % cc=strvcat(lg,lc);
0199 set(handles.editcv,'RowName',lr)
0200 % set(handles.tlegends,'String',[cc,nc])
0201 handles.flagdone=0;
0202 handles.selectedcells=[];
0203 % Update handles structure
0204 guidata(hObject, handles);
0205 
0206 % UIWAIT makes prt_ui_specify_CV_basis wait for user response (see UIRESUME)
0207 uiwait(handles.figure1);
0208 
0209 
0210 
0211 
0212 % --- Outputs from this function are returned to the command line.
0213 function varargout = prt_ui_custom_CV_OutputFcn(hObject, eventdata, handles) 
0214 % varargout  cell array for returning output args (see VARARGOUT);
0215 % hObject    handle to figure
0216 % eventdata  reserved - to be defined in a future version of MATLAB
0217 % handles    structure with handles and user data (see GUIDATA)
0218 
0219 % Get default command line output from handles structure
0220 if isfield(handles,'output') && ~isempty(handles.output)
0221     varargout{1} = handles.output;
0222 else
0223     varargout{1}=[];
0224 end
0225 
0226 %This figure can be deleted now
0227 if isfield(handles,'figure1') && handles.flagdone
0228     delete(handles.figure1)
0229 end
0230 
0231 
0232 
0233 
0234 % --- Executes when entered data in editable cell(s) in editcv.
0235 function editcv_CellEditCallback(hObject, eventdata, handles)
0236 % hObject    handle to editcv (see GCBO)
0237 % eventdata  structure with the following fields (see UITABLE)
0238 %    Indices: row and column indices of the cell(s) edited
0239 %    PreviousData: previous data for the cell(s) edited
0240 %    EditData: string(s) entered by the user
0241 %    NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
0242 %    Error: error string when failed to convert EditData to appropriate value for Data
0243 % handles    structure with handles and user data (see GUIDATA)
0244 handles.CV=cell2mat(get(handles.editcv,'Data'));
0245 % No way to get the last cell selected in time, only in indices, so need to
0246 % select the multiple cells in increasing order!!!
0247 if ~isempty(handles.selectedcells)
0248     vtp=handles.CV(handles.selectedcells(end,1),handles.selectedcells(end,2));
0249 end
0250 if any(any(~ismember(vtp,[0,1,2])))
0251     beep
0252     disp('Values should be either 0, 1 or 2')
0253     return
0254 else
0255     tcol=unique(handles.selectedcells(:,2));
0256     ncol=length(tcol);
0257     for i=1:ncol
0258         icol=find(handles.selectedcells(:,2)==tcol(i));
0259         handles.CV(handles.selectedcells(icol,1),tcol(i))= ...
0260             vtp*ones(length(icol),1);
0261     end
0262     dat=num2cell(handles.CV);
0263     set(handles.editcv,'Data',dat)
0264     disp_CV(hObject,handles,handles.ID,handles.CV)
0265     % Update handles structure
0266     guidata(hObject, handles);
0267 end
0268 
0269 
0270 
0271 % --- Executes when selected cell(s) is changed in editcv.
0272 function editcv_CellSelectionCallback(hObject, eventdata, handles)
0273 % hObject    handle to editcv (see GCBO)
0274 % eventdata  structure with the following fields (see UITABLE)
0275 %    Indices: row and column indices of the cell(s) currently selecteds
0276 % handles    structure with handles and user data (see GUIDATA)
0277 handles.selectedcells=eventdata.Indices;
0278 % Update handles structure
0279 guidata(hObject, handles);
0280 
0281 
0282 
0283 % --- Executes on button press in done_button.
0284 function done_button_Callback(hObject, eventdata, handles)
0285 % hObject    handle to done_button (see GCBO)
0286 % eventdata  reserved - to be defined in a future version of MATLAB
0287 % handles    structure with handles and user data (see GUIDATA)
0288 handles.CV=cell2mat(get(handles.editcv,'Data'));
0289 if any(any(~ismember(handles.CV,[0,1,2])))
0290     beep
0291     disp('Values should be either 0, 1 or 2')
0292     return
0293 end
0294 %checks
0295 ind=[];
0296 for i=1:size(handles.CV,2)
0297     %if columns are set to 0, then delete them
0298     if ~any(handles.CV(:,i))
0299         beep
0300         disp(['Column ',num2str(i),' has only zero values, it will be removed'])
0301     else %each column should have at least a train and a test instance
0302         if all(handles.CV(:,i)==1) %only train data
0303             beep
0304             disp(['Column ',num2str(i),' contains only train data'])
0305             return
0306         elseif all(handles.CV(:,i)==2) %only test data
0307             beep
0308             disp(['Column ',num2str(i),' contains only test data'])
0309             return
0310         else
0311             ind=[ind,i];
0312         end
0313     end
0314 end
0315 handles.CV=handles.CV(:,ind);
0316 [modelid, PRT] = prt_init_model(handles.prt,handles.in);
0317 PRT.model(modelid).input.cv_mat     = handles.CV;
0318 PRT.model(modelid).input.cv_type=handles.in.cv.type;
0319 
0320 % Save PRT.mat
0321 % -------------------------------------------------------------------------
0322 disp('Updating PRT.mat.......>>')
0323 if spm_check_version('MATLAB','7') >= 0
0324     save(handles.in.fname,'-V7','PRT');
0325 else
0326     save(handles.in.fname,'-V6','PRT');
0327 end
0328 handles.flagdone=1;
0329 % Update handles structure
0330 guidata(hObject, handles);
0331 uiresume(handles.figure1)
0332 
0333 
0334 
0335 % --- Executes on button press in save_button.
0336 function save_button_Callback(hObject, eventdata, handles)
0337 % hObject    handle to save_button (see GCBO)
0338 % eventdata  reserved - to be defined in a future version of MATLAB
0339 % handles    structure with handles and user data (see GUIDATA)
0340 %checks
0341 ind=[];
0342 for i=1:size(handles.CV,2)
0343     %if columns are set to 0, then delete them
0344     if ~any(handles.CV(:,i))
0345         beep
0346         disp(['Column ',num2str(i),' has only zero values, it will be removed'])
0347     else %each column should have at least a train and a test instance
0348         if all(handles.CV(:,i)==1) %only train data
0349             beep
0350             disp(['Column ',num2str(i),' contains only train data'])
0351             return
0352         elseif all(handles.CV(:,i)==2) %only test data
0353             beep
0354             disp(['Column ',num2str(i),' contains only test data'])
0355             return
0356         else
0357             ind=[ind,i];
0358         end
0359     end
0360 end
0361 handles.CV=handles.CV(:,ind);
0362 disp_CV(hObject,handles,handles.ID,handles.CV)
0363 CV=handles.CV;
0364 if ~ispc
0365     handles.in.fname = strrep(handles.in.fname,'\',filesep);
0366 end
0367 a=fileparts(handles.in.fname);
0368 cvnam=fullfile(a,['CV_model_',handles.in.model_name,'.mat']);
0369 disp('Saving Cross-Validation matrix in a .mat.......>>')
0370 if spm_check_version('MATLAB','7') >= 0
0371     save(cvnam,'-V7','CV');
0372 else
0373     save(cvnam,'-V6','CV');
0374 end
0375 % Update handles structure
0376 guidata(hObject, handles);
0377 
0378 %--------------------------------------------------------------------------
0379 %------------------------- Subfunctions -----------------------------------
0380 %--------------------------------------------------------------------------
0381 function disp_CV(hObject,handles,dat,CV)
0382 
0383 cla(handles.axes1)
0384 cla(handles.axes2)
0385 cla(handles.axes3)
0386 
0387 %Plot the id_mat in the left part of the window
0388 set(handles.figure1,'CurrentAxes',handles.axes1)
0389 for i=1:6
0390     dat(:,i)=dat(:,i)./max(dat(:,i));
0391 end
0392 imagesc(dat);
0393 set(gca,'XTick',1:6)
0394 set(gca,'XTickLabel',{'Group','Subject','Modality','Condition','Block','Scans'},...
0395     'FontWeight','demi','FontSize',7);
0396 set(gca,'YTickLabel',{})
0397 colorbar('Location','WestOutside')
0398 set(get(gca,'Title'),'String','Feature set','FontWeight','bold',...
0399     'FontSize',10)
0400 
0401 %Plot the CV matrix in the right part of the window
0402 set(handles.figure1,'CurrentAxes',handles.axes2)
0403 xticksl=cell(1,size(CV,2));
0404 for i=1:size(CV,2)
0405     xticksl{i}=num2str(i);
0406 end
0407 clow1 = 0;
0408 clow2 = 0.5;
0409 chigh1 = 1;
0410 d1 = find(max(CV==0));
0411 d2 = find(min(CV==0));
0412 d3 = find(ismember(d1,d2));
0413 flag = 0;
0414 if ~isempty(d3)
0415     flag = 1; % empty columns  =  unused
0416 end
0417 
0418 %inverting unused and test for colour purposes
0419 if max(max(CV)-min(CV))>0.5
0420     indu=(CV==0);
0421     indt= (CV==2);
0422     indr = (CV==1);
0423     CV(indt)=clow1;
0424     CV(indu)=chigh1;
0425     CV(indr) = clow2;
0426 else
0427     indr=(CV==1);
0428     indt= (CV==2);
0429     CV(indt)=clow1;
0430     CV(indr)=clow2;
0431 end
0432 
0433 set(gca,'FontWeight','bold')
0434 xlabel('CV Folds','fontweight','demi')
0435 imagesc(CV,[clow1 chigh1]);
0436 set(gca,'XTick',1:i)
0437 set(gca,'YTickLabel',{})
0438 set(gca,'XTickLabel',xticksl,'FontWeight','demi','FontSize',8)
0439 colormap(gray)
0440 set(get(gca,'Title'),'String','Cross-Validation','FontWeight','bold',...
0441     'FontSize',10)
0442 
0443 %Plot the 'legend' corresponding to the CV matrix in the right bottom part
0444 set(handles.figure1,'CurrentAxes',handles.axes3)
0445 
0446 if max(max(CV)-min(CV))>0.5 || flag
0447     leg=[clow1; clow2; chigh1];
0448     imagesc(leg,[clow1 chigh1]);
0449     set(gca,'YTick',[1,2,3])
0450     set(gca,'YTickLabel',{'Test','Train','Unused'},'FontSize',8);
0451 else
0452     leg=[clow1; clow2];
0453     imagesc(leg,[clow1 chigh1]);
0454     set(gca,'YTick',[1,2])
0455     set(gca,'YTickLabel',{'Test','Train'},'Fontsize',8);
0456 end
0457 set(gca,'YAxisLocation','right')
0458 set(gca,'XTickLabel',{})
0459 
0460 % Update handles structure
0461 guidata(hObject, handles);

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