Home > . > prt_ui_model.m

prt_ui_model

PURPOSE ^

PRT_UI_KERNEL_CONSTRUCTION M-file for prt_ui_kernel_construction.fig

SYNOPSIS ^

function varargout = prt_ui_model(varargin)

DESCRIPTION ^

 PRT_UI_KERNEL_CONSTRUCTION M-file for prt_ui_kernel_construction.fig

 PRT_UI_KERNEL_CONSTRUCTION, by itself, creates a new 
 PRT_UI_KERNEL_CONSTRUCTION or raises the existing singleton*.

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

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

 PRT_UI_KERNEL_CONSTRUCTION('Property','Value',...) creates a new 
 PRT_UI_KERNEL_CONSTRUCTION or raises the existing singleton*.  Starting 
 from the left, property value pairs are applied to the GUI before 
 prt_ui_kernel_construction_OpeningFcn gets called.  An unrecognized 
 property name or invalid value makes property application stop.  All 
 inputs are passed to prt_ui_kernel_construction_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_model(varargin)
0002 % PRT_UI_KERNEL_CONSTRUCTION M-file for prt_ui_kernel_construction.fig
0003 %
0004 % PRT_UI_KERNEL_CONSTRUCTION, by itself, creates a new
0005 % PRT_UI_KERNEL_CONSTRUCTION or raises the existing singleton*.
0006 %
0007 % H = PRT_UI_KERNEL_CONSTRUCTION returns the handle to a new
0008 % PRT_UI_KERNEL_CONSTRUCTION or the handle to the existing singleton*.
0009 %
0010 % PRT_UI_KERNEL_CONSTRUCTION('CALLBACK',hObject,eventData,handles,...)
0011 % calls the local function named CALLBACK in PRT_UI_KERNEL_CONSTRUCTION.M
0012 % with the given input arguments.
0013 %
0014 % PRT_UI_KERNEL_CONSTRUCTION('Property','Value',...) creates a new
0015 % PRT_UI_KERNEL_CONSTRUCTION or raises the existing singleton*.  Starting
0016 % from the left, property value pairs are applied to the GUI before
0017 % prt_ui_kernel_construction_OpeningFcn gets called.  An unrecognized
0018 % property name or invalid value makes property application stop.  All
0019 % inputs are passed to prt_ui_kernel_construction_OpeningFcn 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$
0030 
0031 % Edit the above text to modify the response to help prt_ui_kernel_construction
0032 
0033 % Last Modified by GUIDE v2.5 05-Nov-2014 15:07:40
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_model_OpeningFcn, ...
0040                    'gui_OutputFcn',  @prt_ui_model_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_kernel_construction is made visible.
0056 function prt_ui_model_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_kernel_construction (see VARARGIN)
0062 
0063 % Choose default command line output for prt_ui_kernel_construction
0064 handles.output = hObject;
0065 
0066 %if window already exists, just put it as the current figure
0067 Tag='modelwin';
0068 F = findall(allchild(0),'Flat','Tag',Tag);
0069 if length(F) > 1
0070     % Multiple Graphics windows - close all but most recent
0071     close(F(2:end))
0072     F = F(1);
0073     uistack(F,'top')
0074 elseif length(F)==1
0075     uistack(F,'top')
0076 else
0077     set(handles.figure1,'Tag',Tag)
0078     
0079     %build figure when it doesn't exist
0080 set(handles.figure1,'Name','PRoNTo :: Specify model')
0081 % Choose the color of the different backgrounds and figure parameters
0082 %set size of the window, taking screen resolution and platform into account
0083 S0= spm('WinSize','0',1);   %-Screen size (of the current monitor)
0084 if ispc
0085     PF='MS Sans Serif';
0086 else
0087     PF= spm_platform('fonts');     %-Font names (for this platform)
0088     PF=PF.helvetica;
0089 end
0090 tmp  = [S0(3)/1280 (S0(4))/800];
0091 ratio=min(tmp)*[1 1 1 1];
0092 FS = 1 + 0.85*(min(ratio)-1);  %factor to scale the fonts
0093 x=get(handles.figure1,'Position');
0094 set(handles.figure1,'DefaultTextFontSize',FS*12,...
0095     'DefaultUicontrolFontSize',FS*12,...
0096     'DefaultTextFontName',PF,...
0097     'DefaultAxesFontName',PF,...
0098     'DefaultUicontrolFontName',PF)
0099 set(handles.figure1,'Position',ratio.*x)
0100 % set(handles.figure1,'Units','normalized')
0101 set(handles.figure1,'Resize','on')
0102 
0103 color=prt_get_defaults('color');
0104 handles.color=color;
0105 set(handles.figure1,'Color',color.bg1)
0106 aa=get(handles.figure1,'children');
0107 for i=1:length(aa)
0108     if strcmpi(get(aa(i),'type'),'uipanel')
0109         set(aa(i),'BackgroundColor',color.bg2)
0110         bb=get(aa(i),'children');
0111         if ~isempty(bb)
0112             for j=1:length(bb)
0113                 if ~isempty(find(strcmpi(get(bb(j),'Style'),{'text',...
0114                         'radiobutton','checkbox'})))
0115                     set(bb(j),'BackgroundColor',color.bg2)
0116                 elseif ~isempty(find(strcmpi(get(bb(j),'Style'),'pushbutton')))
0117                     set(bb(j),'BackgroundColor',color.fr)
0118                 end
0119                 set(bb(j),'FontUnits','pixel')
0120                 xf=get(bb(j),'FontSize');
0121                 set(bb(j),'FontSize',ceil(FS*xf),'FontName',PF,...
0122                     'FontUnits','normalized','Units','normalized')
0123             end
0124         end
0125     elseif strcmpi(get(aa(i),'type'),'uicontrol')
0126         if ~isempty(find(strcmpi(get(aa(i),'Style'),{'text',...
0127                 'radiobutton','checkbox'})))
0128             set(aa(i),'BackgroundColor',color.bg1)
0129         elseif ~isempty(find(strcmpi(get(aa(i),'Style'),'pushbutton')))
0130             set(aa(i),'BackgroundColor',color.fr)
0131         end
0132     end
0133     set(aa(i),'FontUnits','pixel')
0134     xf=get(aa(i),'FontSize');
0135     set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
0136         'Units','normalized')
0137 end
0138 
0139 %Set defaults for some subfields and popup menus
0140 handles.def=prt_get_defaults('model');
0141 set(handles.kernel_methods,'Value',1)
0142 set(handles.kernel_methods,'Enable','off')
0143 handles.use_kernel=1;
0144 set(handles.pop_cv,'String',{'Custom'})
0145 set(handles.pop_cv,'Value',1)
0146 set(handles.pop_cv_nested,'String',{'Custom'})
0147 set(handles.pop_cv_nested,'Value',1)
0148 handles.cv.type='custom';
0149 handles.cv.mat_file=[];
0150 handles.cv.nested_mat_file=[];
0151 handles.cv.k = 0;
0152 set(handles.pop_reg,'String',{'Classification','Regression'})
0153 set(handles.pop_reg,'Value',1)
0154 handles.type='classification';
0155 set(handles.butt_defclass,'ForegroundColor',handles.color.high)
0156 set(handles.pop_machine,'String',{'Binary support vector machine',...
0157         'Binary Gaussian Process Classification',...
0158         'Multiclass GPC'})
0159 set(handles.pop_machine,'Value',1)
0160 handles.machine.function='prt_machine_svm_bin';
0161 handles.machine.args=handles.def.svmargs;
0162 list={'Sample averaging (within block)',...
0163     'Sample averaging (within subject/condition)',...
0164     'Mean centre features using training data',...
0165     'Divide data vectors by their norm',...
0166     'Perform a GLM (for covariates only)'};  %GLM for subjects only
0167 % list={'Sample averaging (within block)',...
0168 %     'Sample averaging (within subject/condition)',...
0169 %     'Mean centre features using training data',...
0170 %     'Normalize samples'};
0171 
0172 handles.indop{1}=1:length(list);
0173 handles.indop{2}=0;
0174 set(handles.uns_list,'String',list)
0175 set(handles.sel_list,'String',{''})
0176 handles.operations = [];
0177 handles.namop=list;
0178 set(handles.uns_list,'Value',1)
0179 set(handles.sel_list,'Value',1)
0180 handles.flagguicv=0;
0181 handles.flagguicv_nested=0;
0182 set(handles.flag_opt_param,'Value',0)
0183 set(handles.edit_param_range,'Enable','off')
0184 set(handles.pop_cv_nested,'Enable','off')
0185 handles.cv.nested = 0;
0186 handles.cv.nested_param = [];
0187 handles.cv.k_nested = 0;
0188 handles.cv.type_nested='';
0189 end
0190 % Update handles structure
0191 guidata(hObject, handles);
0192 
0193 % UIWAIT makes prt_ui_kernel_construction wait for user response (see UIRESUME)
0194 % uiwait(handles.figure1);
0195 
0196 
0197 % --- Outputs from this function are returned to the command line.
0198 function varargout = prt_ui_model_OutputFcn(hObject, eventdata, handles) 
0199 % varargout  cell array for returning output args (see VARARGOUT);
0200 % hObject    handle to figure
0201 % eventdata  reserved - to be defined in a future version of MATLAB
0202 % handles    structure with handles and user data (see GUIDATA)
0203 
0204 % Get default command line output from handles structure
0205 if isfield(handles,'output') && ~isempty(handles.output)
0206     varargout{1} = handles.output;
0207 else
0208     varargout{1}=[];
0209 end
0210 
0211 
0212 
0213 
0214 % --- Executes on button press in br_prt.
0215 function br_prt_Callback(hObject, eventdata, handles)
0216 % hObject    handle to br_prt (see GCBO)
0217 % eventdata  reserved - to be defined in a future version of MATLAB
0218 % handles    structure with handles and user data (see GUIDATA)
0219 fname=spm_select(1,'.mat','Select PRT.mat',[],pwd,'PRT.mat');
0220 if exist('PRT','var')
0221     clear PRT
0222 end
0223 PRT=prt_load(fname);
0224 if ~isempty(PRT)
0225     handles.dat=PRT;
0226     set(handles.edit_prt,'String',fname);
0227 else
0228     beep
0229     disp('Could not load file')
0230     return
0231 end
0232 
0233 if ~isfield(handles.dat,'fs')
0234     beep
0235     disp('No feature set found in the PRT.mat')
0236     disp('Please, prepare feature set before computing model')
0237     delete(handles.figure1)
0238     return
0239 end
0240 list={};
0241 for i=1:length(PRT.fs)
0242     if ~isempty(PRT.fs(i).fs_name)
0243         list=[list; {PRT.fs(i).fs_name}];
0244     end
0245 end
0246 set(handles.pop_featset,'String',list)
0247 set(handles.pop_featset,'Value',1)
0248 if length(handles.dat.fs(1).modality)>1
0249     list=get(handles.pop_cv,'String');
0250     list=[list;{'Leave One Run/Session Out'}];
0251     set(handles.pop_cv,'String',list)
0252     set(handles.pop_cv,'Value',length(list))
0253     handles.cv.type = 'loro';
0254     handles.multimod = 1;
0255 end
0256 if length(handles.dat.fs(1).modality)>2
0257     list=get(handles.pop_cv_nested,'String');
0258     list=[list;{'Leave One Run/Session Out'}];
0259     set(handles.pop_cv_nested,'String',list)
0260     set(handles.pop_cv_nested,'Value',length(list))
0261     handles.cv.type_nested='loro';
0262 end
0263 list=get(handles.pop_featset,'String');
0264 handles.fs(1).fs_name=list{1};
0265 handles.fs(1).indfs=1;
0266 if isfield(handles.dat.fs(1),'multkernel') && handles.dat.fs(1).multkernel %allowing for multi-kernel learning (
0267     handles.multimod = 1;
0268 else
0269     handles.multimod = 0;
0270 end
0271 if isfield(handles.dat.fs(1),'multkernelROI') && handles.dat.fs(1).multkernelROI %allowing for multi-kernel learning
0272     handles.multiroi = 1;
0273 else
0274     handles.multiroi = 0;
0275 end
0276 
0277 handles.use_kernel=get(handles.kernel_methods,'Value');
0278 if get(handles.pop_reg,'Value')==1 %for classification
0279     if handles.use_kernel
0280         list = {'Binary support vector machine',...
0281             'Binary Gaussian Process Classification',...
0282             'Multiclass GPC'};
0283         if handles.multimod || handles.multiroi
0284             list = [list,{'L1- Multi-Kernel Learning'}];
0285         end
0286         set(handles.pop_machine,'String',list)
0287         set(handles.pop_machine,'Value',1)
0288         handles.machine.function='prt_machine_svm_bin';
0289         handles.machine.args=handles.def.svmargs;
0290     end
0291 end
0292 
0293 % Update handles structure
0294 guidata(hObject, handles);
0295 
0296 
0297 
0298 function edit_prt_Callback(hObject, eventdata, handles)
0299 % hObject    handle to edit_prt (see GCBO)
0300 % eventdata  reserved - to be defined in a future version of MATLAB
0301 % handles    structure with handles and user data (see GUIDATA)
0302 
0303 % Hints: get(hObject,'String') returns contents of edit_prt as text
0304 %        str2double(get(hObject,'String')) returns contents of edit_prt as a double
0305 fname=get(handles.edit_prt,'String');
0306 if exist('PRT','var')
0307     clear PRT
0308 end
0309 PRT=prt_load(fname);
0310 if ~isempty(PRT)
0311     handles.dat=PRT;
0312     set(handles.edit_prt,'String',fname);
0313 else
0314     beep
0315     disp('Could not load file')
0316     return
0317 end
0318 
0319 if ~isfield(handles.dat,'fs')
0320     beep
0321     disp('No feature set found in the PRT.mat')
0322     disp('Please, prepare feature set before computing model')
0323     delete(handles.figure1)
0324     return
0325 end
0326 list={};
0327 for i=1:length(PRT.fs)
0328     if ~isempty(PRT.fs(i).fs_name)
0329         list=[list; {PRT.fs(i).fs_name}];
0330     end
0331 end
0332 set(handles.pop_featset,'String',list)
0333 set(handles.pop_featset,'Value',1)
0334 if length(handles.dat.fs(1).modality)>1
0335     list=get(handles.pop_cv,'String');
0336     list=[list;{'Leave One Run/Session Out'}];
0337     set(handles.pop_cv,'String',list)
0338     set(handles.pop_cv,'Value',length(list))
0339     handles.cv.type = 'loro';
0340     handles.multimod = 1;
0341 end
0342 if length(handles.dat.fs(1).modality)>2
0343     list=get(handles.pop_cv_nested,'String');
0344     list=[list;{'Leave One Run/Session Out'}];
0345     set(handles.pop_cv_nested,'String',list)
0346     set(handles.pop_cv_nested,'Value',length(list))
0347     handles.cv.type_nested = 'loro';
0348 end
0349 list=get(handles.pop_featset,'String');
0350 handles.fs(1).fs_name=list{1};
0351 handles.fs(1).indfs=1;
0352 if handles.dat.fs(1).multkernel %allowing for multi-kernel learning
0353     handles.multimod = 1;
0354 else
0355     handles.multimod = 0;
0356 end
0357 if handles.dat.fs(1).multkernelROI %allowing for multi-kernel learning
0358     handles.multiroi = 1;
0359 else
0360     handles.multiroi = 0;
0361 end
0362 handles.use_kernel=get(handles.kernel_methods,'Value');
0363 if get(handles.pop_reg,'Value')==1 %for classification
0364     if handles.use_kernel
0365         list = {'Binary support vector machine',...
0366             'Binary Gaussian Process Classification',...
0367             'Multiclass GPC'};
0368         if handles.multimod || handles.multiroi
0369             list = [list,{'L1- Multi-Kernel Learning'}];
0370         end
0371         set(handles.pop_machine,'String',list)
0372         set(handles.pop_machine,'Value',1)
0373         handles.machine.function='prt_machine_svm_bin';
0374         handles.machine.args=handles.def.svmargs;
0375     end
0376 end
0377 
0378 % Update handles structure
0379 guidata(hObject, handles);
0380 
0381 
0382 % --- Executes during object creation, after setting all properties.
0383 function edit_prt_CreateFcn(hObject, eventdata, handles)
0384 % hObject    handle to edit_prt (see GCBO)
0385 % eventdata  reserved - to be defined in a future version of MATLAB
0386 % handles    empty - handles not created until after all CreateFcns called
0387 
0388 % Hint: edit controls usually have a white background on Windows.
0389 %       See ISPC and COMPUTER.
0390 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0391     set(hObject,'BackgroundColor','white');
0392 end
0393 
0394 function edit_modelname_Callback(hObject, eventdata, handles)
0395 % hObject    handle to edit_modelname (see GCBO)
0396 % eventdata  reserved - to be defined in a future version of MATLAB
0397 % handles    structure with handles and user data (see GUIDATA)
0398 
0399 % Hints: get(hObject,'String') returns contents of edit_modelname as text
0400 %        str2double(get(hObject,'String')) returns contents of edit_modelname as a double
0401 handles.model_name=deblank(get(handles.edit_modelname,'String'));
0402 if ~(prt_checkAlphaNumUnder(handles.model_name))
0403     beep
0404     disp('Model name should be entered in alphanumeric format only')
0405     disp('Please correct')
0406     set(handles.edit_modelname,'ForegroundColor',[1,0,0])
0407     return
0408 else
0409     set(handles.edit_modelname,'ForegroundColor',[0,0,0])
0410 end
0411 % Update handles structure
0412 guidata(hObject, handles);
0413 
0414 % --- Executes during object creation, after setting all properties.
0415 function edit_modelname_CreateFcn(hObject, eventdata, handles)
0416 % hObject    handle to edit_modelname (see GCBO)
0417 % eventdata  reserved - to be defined in a future version of MATLAB
0418 % handles    empty - handles not created until after all CreateFcns called
0419 
0420 % Hint: edit controls usually have a white background on Windows.
0421 %       See ISPC and COMPUTER.
0422 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0423     set(hObject,'BackgroundColor','white');
0424 end
0425 
0426 % --- Executes on selection change in pop_featset.
0427 function pop_featset_Callback(hObject, eventdata, handles)
0428 % hObject    handle to pop_featset (see GCBO)
0429 % eventdata  reserved - to be defined in a future version of MATLAB
0430 % handles    structure with handles and user data (see GUIDATA)
0431 
0432 % Hints: contents = get(hObject,'String') returns pop_featset contents as cell array
0433 %        contents{get(hObject,'Value')} returns selected item from pop_featset
0434 val=get(handles.pop_featset,'Value');
0435 if val==0
0436     warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0437     set(handles.pop_feaset,'Value',1)
0438     val=1;
0439 end
0440 list=get(handles.pop_featset,'String');
0441 handles.fs(1).fs_name=list{val};
0442 handles.fs(1).indfs=val;
0443 list=get(handles.pop_cv,'String');
0444 if length(handles.dat.fs(val).modality)>1 %LOO Run if not in list
0445     if ~any(strcmpi(list,'Leave One Run/Session Out'))
0446         list=[list;{'Leave One Run/Session Out'}];
0447         set(handles.pop_cv,'String',list)
0448         set(handles.pop_cv,'Value',length(list))
0449         handles.cv.type = 'loro';
0450         handles.multimod = 1;
0451     end
0452 else                                    %delete LOO Run if not available for the selected feature set
0453     if any(strcmpi(list,'Leave One Run/Session Out'))
0454         idlist = find(strcmpi(list,'Leave One Run/Session Out'));
0455         tidl = 1:length(list);
0456         idtk = setdiff(tidl,idlist);
0457         set(handles.pop_cv,'String',list(idtk))
0458         set(handles.pop_cv,'Value',1)
0459         handles.cv.type = 'custom';
0460         handles.multimod = 0;
0461     end
0462 end
0463 if length(handles.dat.fs(val).modality)>2
0464     list=get(handles.pop_cv_nested,'String');
0465     if ~any(strcmpi(list,'Leave One Run/Session Out'))
0466         list=[list;{'Leave One Run/Session Out'}];
0467         set(handles.pop_cv_nested,'String',list)
0468         set(handles.pop_cv_nested,'Value',length(list))
0469         handles.cv.type_nested='loro';
0470     end
0471 end
0472 % Add multi-kernel learning if flag to 1
0473 if isfield(handles.dat.fs(val),'multkernel')&& handles.dat.fs(val).multkernel %allowing for multi-kernel learning
0474     handles.multimod = 1;
0475 else
0476     handles.multimod = 0;
0477 end
0478 if isfield(handles.dat.fs(val),'multkernelROI')&& handles.dat.fs(val).multkernelROI %allowing for multi-kernel learning
0479     handles.multiroi = 1;
0480 else
0481     handles.multiroi = 0;
0482 end
0483 handles.use_kernel=get(handles.kernel_methods,'Value');
0484 if get(handles.pop_reg,'Value')==1 %for classification
0485     if handles.use_kernel
0486         list = {'Binary support vector machine',...
0487             'Binary Gaussian Process Classification',...
0488             'Multiclass GPC'};
0489         if handles.multimod || handles.multiroi
0490             list = [list,{'L1- Multi-Kernel Learning'}];
0491         end
0492         set(handles.pop_machine,'String',list)
0493         set(handles.pop_machine,'Value',1)
0494         handles.machine.function='prt_machine_svm_bin';
0495         handles.machine.args=handles.def.svmargs;
0496     end
0497 end
0498 % Update handles structure
0499 guidata(hObject, handles);
0500 
0501 % --- Executes during object creation, after setting all properties.
0502 function pop_featset_CreateFcn(hObject, eventdata, handles)
0503 % hObject    handle to pop_featset (see GCBO)
0504 % eventdata  reserved - to be defined in a future version of MATLAB
0505 % handles    empty - handles not created until after all CreateFcns called
0506 
0507 % Hint: popupmenu controls usually have a white background on Windows.
0508 %       See ISPC and COMPUTER.
0509 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0510     set(hObject,'BackgroundColor','white');
0511 end
0512 
0513 % --- Executes on button press in kernel_methods.
0514 function kernel_methods_Callback(hObject, eventdata, handles)
0515 % hObject    handle to kernel_methods (see GCBO)
0516 % eventdata  reserved - to be defined in a future version of MATLAB
0517 % handles    structure with handles and user data (see GUIDATA)
0518 
0519 % Hint: get(hObject,'Value') returns toggle state of kernel_methods
0520 handles.use_kernel=get(handles.kernel_methods,'Value');
0521 if get(handles.pop_reg,'Value')==1 %for classification
0522     if ~handles.use_kernel
0523         set(handles.pop_machine,'String',{'Random Forest'})
0524         set(handles.pop_machine,'Value',1)
0525         handles.machine.function='prt_machine_RT_bin';
0526         handles.machine.args=handles.def.rtargs;
0527     else
0528         list = {'Binary support vector machine',...
0529             'Binary Gaussian Process Classification',...
0530             'Multiclass GPC'};
0531         if handles.multimod || handles.multiroi
0532             list = [list,{'L1- Multi-Kernel Learning'}];
0533         end
0534         set(handles.pop_machine,'String',list)
0535         set(handles.pop_machine,'Value',1)
0536         handles.machine.function='prt_machine_svm_bin';
0537         handles.machine.args=handles.def.svmargs;
0538     end
0539 end
0540 % Update handles structure
0541 guidata(hObject, handles);
0542 
0543 
0544 % --- Executes on selection change in pop_reg.
0545 function pop_reg_Callback(hObject, eventdata, handles)
0546 % hObject    handle to pop_reg (see GCBO)
0547 % eventdata  reserved - to be defined in a future version of MATLAB
0548 % handles    structure with handles and user data (see GUIDATA)
0549 
0550 % Hints: contents = get(hObject,'String') returns pop_reg contents as cell array
0551 %        contents{get(hObject,'Value')} returns selected item from pop_reg
0552 val=get(handles.pop_reg,'Value');
0553 if val==0
0554     warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0555     set(handles.pop_reg,'Value',1)
0556     val=1;
0557 end
0558 if val==1 %Classification
0559     handles.type='classification';
0560     nk=get(handles.kernel_methods,'Value');
0561     if nk==1
0562         %set the list of machines
0563         list = {'Binary support vector machine',...
0564             'Binary Gaussian Process Classification',...
0565             'Multiclass GPC'};
0566         if handles.multimod || handles.multiroi
0567             list = [list,{'L1- Multi-Kernel Learning'}];
0568         end
0569         set(handles.pop_machine,'String',list)
0570         set(handles.pop_machine,'Value',1)
0571         handles.machine.function='prt_machine_svm_bin';
0572         handles.machine.args=handles.def.svmargs;
0573     else
0574         %set the list of machines
0575         set(handles.pop_machine,'String',{'Random Forest'})
0576         set(handles.pop_machine,'Value',1)
0577         handles.machine.function='prt_machine_RT_bin';
0578         handles.machine.args=handles.def.rtargs;  
0579     end
0580     set(handles.butt_defclass,'String','Define classes')
0581 elseif val==2
0582     handles.type='regression';
0583     set(handles.butt_defclass,'String','Select subjects/scans')
0584     %set the list of machines
0585     set(handles.pop_machine,'String',{'Kernel Ridge Regression',...
0586         'Relevance Vector Regression','Gaussian Process Regression', 'Multi-Kernel Regression'})
0587     set(handles.pop_machine,'Value',1)
0588     handles.machine.function='prt_machine_krr';
0589     handles.machine.args=handles.def.krrargs;
0590 end
0591 set(handles.butt_defclass,'ForegroundColor',handles.color.high)
0592 % Update handles structure
0593 guidata(hObject, handles);
0594 
0595 % --- Executes during object creation, after setting all properties.
0596 function pop_reg_CreateFcn(hObject, eventdata, handles)
0597 % hObject    handle to pop_reg (see GCBO)
0598 % eventdata  reserved - to be defined in a future version of MATLAB
0599 % handles    empty - handles not created until after all CreateFcns called
0600 
0601 % Hint: popupmenu controls usually have a white background on Windows.
0602 %       See ISPC and COMPUTER.
0603 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0604     set(hObject,'BackgroundColor','white');
0605 end
0606 
0607 
0608 
0609 % --- Executes on button press in but_defclass.
0610 function butt_defclass_Callback(hObject, eventdata, handles)
0611 % hObject    handle to butt_def_class (see GCBO)
0612 % eventdata  reserved - to be defined in a future version of MATLAB
0613 % handles    structure with handles and user data (see GUIDATA)
0614 if strcmpi(handles.type,'classification')
0615     speccl=prt_ui_select_class('UserData',{handles.dat,handles.fs(1).indfs});
0616     handles.design=speccl.design;
0617 %     handles.listnames=speccl.condm;
0618     handles.legs=speccl.legends;
0619     if isempty(speccl)
0620         beep
0621         disp('No class specified')
0622         return
0623     end
0624     handles.class=speccl.class;
0625     ns=zeros(length(speccl.class),1);
0626     ng1=1;
0627     ng2=1;
0628     for ii=1:length(speccl.class)
0629         for jj=1:length(speccl.class(ii).group)
0630             ns(ii)=ns(ii)+length(speccl.class(ii).group(jj).subj);
0631         end
0632         if jj==1
0633             if ii==1
0634                 gname=speccl.class(ii).group(jj).gr_name;
0635             else
0636                 if strcmpi(gname,speccl.class(ii).group(jj).gr_name)
0637                     ng2=ng2+1;
0638                 end
0639             end
0640         else
0641             ng1=0;
0642         end
0643     end
0644     
0645     % Options for the outter CV
0646     ng2=floor(ng2/length(speccl.class));
0647     list=get(handles.pop_cv,'String');
0648     if (speccl.design) && max(ns)==1
0649         if ~any(ismember(list, 'Leave One Block Out'))
0650             list=[list;{'Leave One Block Out'}];
0651         end
0652         if ~any(ismember(list, 'k-folds CV on Block'))
0653             list=[list;{'k-folds CV on Block'}];
0654         end
0655         set(handles.pop_cv,'String',list)
0656         set(handles.pop_cv,'Value',length(list)-1)
0657         handles.cv.type     = 'lobo';
0658         handles.cv.type_nested='lobo';
0659     end
0660     handles.loospg=speccl.loospg;
0661     if min(ns)>1
0662         if ~any(ismember(list, 'Leave One Subject Out'))
0663             list=[list;{'Leave One Subject Out'}];
0664         end
0665         if ~any(ismember(list, 'k-folds CV on Subject Out'))
0666             list=[list;{'k-folds CV on Subject Out'}];
0667         end
0668         set(handles.pop_cv,'String',list)
0669         set(handles.pop_cv,'Value',length(list)-1)
0670         handles.cv.type     = 'loso';
0671         handles.cv.type_nested='loso';
0672         if ~ng1 || ~ng2
0673             list=get(handles.pop_cv,'String');
0674             if ~any(ismember(list, 'Leave One Subject per Group Out'))
0675                 list=[list;{'Leave One Subject per Group Out'}];
0676             end
0677             if ~any(ismember(list, 'k-folds CV on Subject per Group'))
0678                 list=[list;{'k-folds CV on Subject per Group'}];
0679             end
0680             set(handles.pop_cv,'String',list)
0681         end
0682     end
0683     
0684     
0685     % Options for the inner CV
0686     % TODO: This should be checked to see if it's correct
0687     %       It's practically copy/paste from above (code for the outter CV)
0688     %       some special restrictions might be applied for the inner CV
0689     list = setdiff(list,'Custom'); %No custom for inner CV
0690     if isempty(list)
0691         list={''};
0692     end
0693     set(handles.pop_cv_nested,'String',list);
0694     val = get(handles.pop_cv,'Value');
0695     set(handles.pop_cv_nested,'Value',max(1,val-1)); 
0696     
0697   
0698 else %Regression
0699     d1=prt_ui_select_reg('UserData',{handles.dat,handles.fs(1).indfs});
0700     sel=d1.group;
0701     handles.legs=d1.legends;
0702     if isempty(sel)
0703         beep
0704         disp('No subject selected for regression')
0705         return
0706     end
0707     handles.group=sel;
0708     n=0;
0709     for i=1:length(sel)
0710         n=n+length(sel(i).subj);
0711     end
0712     list=get(handles.pop_cv,'String');
0713     if n>1
0714         if ~any(ismember(list, 'Leave One Subject Out'))
0715             list=[list;{'Leave One Subject Out'}];
0716         end
0717         if ~any(ismember(list, 'k-folds CV on Subject Out'))
0718             list=[list;{'k-folds CV on Subject Out'}];
0719         end
0720         set(handles.pop_cv,'String',list)
0721         set(handles.pop_cv,'Value',length(list)-1)
0722         handles.cv.type     = 'loso';
0723         handles.cv.type_nested='loso';
0724         list = setdiff(list,'Custom'); %No custom for inner CV
0725         if isempty(list)
0726             list={''};
0727         end
0728         set(handles.pop_cv_nested,'String',list);
0729         val = get(handles.pop_cv,'Value');
0730         set(handles.pop_cv_nested,'Value',max(1,val-1)); 
0731     end
0732 end
0733 set(handles.butt_defclass,'ForegroundColor',[0 0 0])
0734 % Update handles structure
0735 guidata(hObject, handles);
0736 
0737 
0738 % --- Executes on selection change in pop_machine.
0739 function pop_machine_Callback(hObject, eventdata, handles)
0740 % hObject    handle to pop_machine (see GCBO)
0741 % eventdata  reserved - to be defined in a future version of MATLAB
0742 % handles    structure with handles and user data (see GUIDATA)
0743 
0744 % Hints: contents = get(hObject,'String') returns pop_machine contents as cell array
0745 %        contents{get(hObject,'Value')} returns selected item from pop_machine
0746 mach=get(handles.pop_machine,'String');
0747 val=get(handles.pop_machine,'Value');
0748 if val==0
0749     warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0750     set(handles.pop_machine,'Value',1)
0751     val=1;
0752 end
0753 if any(strfind(mach{val},'support'))
0754     handles.machine.function='prt_machine_svm_bin';
0755     handles.machine.args=handles.def.svmargs;
0756 elseif any(strfind(mach{val},'Binary Gaussian'))
0757     handles.machine.function='prt_machine_gpml';
0758     handles.machine.args=handles.def.gpcargs;
0759 elseif any(strfind(mach{val},'Multiclass GPC'))
0760     handles.machine.function='prt_machine_gpclap';
0761     handles.machine.args=handles.def.gpclapargs;
0762 elseif any(strfind(mach{val},'Ridge'))
0763     handles.machine.function='prt_machine_krr';
0764     handles.machine.args=handles.def.krrargs;
0765 elseif any(strfind(mach{val},'Relevance'))
0766     handles.machine.function='prt_machine_rvr';
0767     handles.machine.args=[];
0768 elseif any(strfind(mach{val},'Process Regression'))
0769     handles.machine.function='prt_machine_gpr';
0770     handles.machine.args=handles.def.gprargs;
0771 elseif any(strfind(mach{val},'Random'))
0772     handles.machine.function='prt_machine_RT_bin';
0773     handles.machine.args=handles.def.rtargs;    
0774 elseif any(strfind(mach{val},'L1- Multi-Kernel'))
0775     handles.machine.function='prt_machine_sMKL_cla';
0776     handles.machine.args=handles.def.l1MKLargs;
0777 elseif any(strfind(mach{val},'Multi-Kernel Regression'))
0778     handles.machine.function='prt_machine_sMKL_reg';
0779     handles.machine.args=handles.def.l1MKLargs; %TODO: Check if this is correct
0780 end
0781 % Update handles structure
0782 guidata(hObject, handles);
0783 
0784 
0785 % --- Executes during object creation, after setting all properties.
0786 function pop_machine_CreateFcn(hObject, eventdata, handles)
0787 % hObject    handle to pop_machine (see GCBO)
0788 % eventdata  reserved - to be defined in a future version of MATLAB
0789 % handles    empty - handles not created until after all CreateFcns called
0790 
0791 % Hint: popupmenu controls usually have a white background on Windows.
0792 %       See ISPC and COMPUTER.
0793 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0794     set(hObject,'BackgroundColor','white');
0795 end
0796 
0797 % --- Executes on button press in flag_opt_param.
0798 function flag_opt_param_Callback(hObject, eventdata, handles)
0799 % hObject    handle to flag_opt_param (see GCBO)
0800 % eventdata  reserved - to be defined in a future version of MATLAB
0801 % handles    structure with handles and user data (see GUIDATA)
0802 
0803 % Hint: get(hObject,'Value') returns toggle state of flag_opt_param
0804 v = get(handles.flag_opt_param,'Value');
0805 if v
0806     switch handles.machine.function
0807         case {'prt_machine_svm_bin','prt_machine_sMKL_cla','prt_machine_krr','prt_machine_sMKL_reg'}
0808             set(handles.edit_param_range,'Enable','on')
0809             set(handles.pop_cv_nested,'Enable','on')
0810             handles.cv.nested = 1;
0811         otherwise
0812             set(handles.edit_param_range,'Enable','off')
0813             set(handles.pop_cv_nested,'Enable','off')
0814             handles.cv.nested = 0;
0815             handles.cv.nested_param = [];
0816             beep
0817             disp('No hyper-parameter can be optimized for this machine')
0818     end
0819 else
0820     handles.cv.nested = 0;
0821     handles.cv.nested_param = [];
0822     set(handles.edit_param_range,'Enable','off')
0823     set(handles.pop_cv_nested,'Enable','off')
0824 end
0825 
0826 % Update handles structure
0827 guidata(hObject, handles);
0828 
0829 
0830 function edit_param_range_Callback(hObject, eventdata, handles)
0831 % hObject    handle to edit7 (see GCBO)
0832 % eventdata  reserved - to be defined in a future version of MATLAB
0833 % handles    structure with handles and user data (see GUIDATA)
0834 
0835 % Hints: get(hObject,'String') returns contents of edit7 as text
0836 %        str2double(get(hObject,'String')) returns contents of edit7 as a double
0837 vp = get(handles.edit_param_range,'String');
0838 try
0839     p = eval(vp);
0840 catch
0841     beep
0842     disp('Parameter range cannot be evaluated, please enter as min:step:max')
0843 end
0844 if isnumeric(p)
0845     handles.cv.nested_param = p;
0846 else
0847     beep
0848     disp('Parameter range is not numeric, please enter as min:step:max')
0849 end
0850 % Update handles structure
0851 guidata(hObject, handles);
0852 
0853 % --- Executes during object creation, after setting all properties.
0854 function edit_param_range_CreateFcn(hObject, eventdata, handles)
0855 % hObject    handle to edit7 (see GCBO)
0856 % eventdata  reserved - to be defined in a future version of MATLAB
0857 % handles    empty - handles not created until after all CreateFcns called
0858 
0859 % Hint: edit controls usually have a white background on Windows.
0860 %       See ISPC and COMPUTER.
0861 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0862     set(hObject,'BackgroundColor','white');
0863 end
0864 
0865 
0866 % --- Executes on selection change in pop_cv.
0867 function pop_cv_Callback(hObject, eventdata, handles)
0868 % hObject    handle to pop_cv (see GCBO)
0869 % eventdata  reserved - to be defined in a future version of MATLAB
0870 % handles    structure with handles and user data (see GUIDATA)
0871 
0872 % Hints: contents = get(hObject,'String') returns pop_cv contents as cell array
0873 %        contents{get(hObject,'Value')} returns selected item from pop_cv
0874 % assemble structure for performing cross-validation
0875 val=get(handles.pop_cv,'Value');
0876 mach=get(handles.pop_cv,'String');
0877 handles.cv.k=0; %by default, Leave-One-Out options
0878 if val==0
0879     warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0880     set(handles.pop_cv,'Value',1)
0881     val=1;
0882 end
0883 if any(strfind(mach{val},'Subject Out'))
0884     handles.cv.type = 'loso';
0885 elseif any(strfind(mach{val},'Subject per Group'))
0886     if ~handles.loospg
0887         beep
0888         disp('Warning: Subjects are not balanced across classes!')
0889     end
0890     handles.cv.type = 'losgo';
0891 elseif any(strfind(mach{val},'Block'))
0892     handles.cv.type = 'lobo';
0893 elseif any(strfind(mach{val},'Run'))        %currently implemented for MCKR only
0894     handles.cv.type = 'loro';
0895 else
0896     handles.cv.type     = 'custom';
0897     %fill the input of the 'prt_model' button
0898     in.fname=get(handles.edit_prt,'String');
0899     if ~isfield(handles,'model_name')
0900         beep
0901         disp('Please enter a valid model name')
0902         return
0903     end
0904     in.model_name=handles.model_name;
0905     in.type=handles.type;
0906     in.machine=handles.machine;
0907     in.use_kernel=handles.use_kernel;
0908     in.operations=handles.operations;
0909     in.fs(1).fs_name=handles.fs(1).fs_name;
0910     in.cv=handles.cv;
0911     %check that classes/subjects/scans were defined
0912     if strcmpi(in.type,'classification')
0913         if ~isfield(handles,'class')
0914             beep
0915             disp('No class selected for classification')
0916             disp('Please, define classes')
0917             return
0918         else
0919             for i=1:length(handles.class)
0920                 ind=[];
0921                 for g=1:length(handles.class(i).group)
0922                     if ~isempty(handles.class(i).group(g).gr_name)
0923                         ind=[ind,g];
0924                     end
0925                 end
0926                 handles.class(i).group=handles.class(i).group(ind);
0927             end
0928             in.class=handles.class;
0929         end
0930     else
0931         if ~isfield(handles,'group')
0932             beep
0933             disp('No subjects/scans selected for classification')
0934             disp('Please, select subjects/scans')
0935             return
0936         else
0937             ind=[];
0938             for g=1:length(handles.group)
0939                 if ~isempty(handles.group(g).gr_name)
0940                     ind=[ind,g];
0941                 end
0942             end
0943             handles.group=handles.group(ind);
0944             in.group=handles.group;
0945         end
0946     end
0947     handles.in=in;
0948     prt_ui_specify_CV_basis(handles);
0949     handles.flagguicv=1;
0950 end
0951 if any(strfind(mach{val},'k-fold'))
0952     kt=prt_text_input('Title','Specify k, the number of folds');
0953     handles.cv.k=str2num(kt);
0954 end
0955 % Update handles structure
0956 guidata(hObject, handles);
0957 
0958 % --- Executes during object creation, after setting all properties.
0959 function pop_cv_CreateFcn(hObject, eventdata, handles)
0960 % hObject    handle to pop_cv (see GCBO)
0961 % eventdata  reserved - to be defined in a future version of MATLAB
0962 % handles    empty - handles not created until after all CreateFcns called
0963 
0964 % Hint: popupmenu controls usually have a white background on Windows.
0965 %       See ISPC and COMPUTER.
0966 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0967     set(hObject,'BackgroundColor','white');
0968 end
0969 
0970 % --- Executes on selection change in uns_list.
0971 function uns_list_Callback(hObject, eventdata, handles)
0972 % hObject    handle to uns_list (see GCBO)
0973 % eventdata  reserved - to be defined in a future version of MATLAB
0974 % handles    structure with handles and user data (see GUIDATA)
0975 
0976 % Hints: contents = get(hObject,'String') returns uns_list contents as cell array
0977 %        contents{get(hObject,'Value')} returns selected item from uns_list
0978 val=get(handles.uns_list,'Value');
0979 if val==0
0980     warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0981     set(handles.uns_list,'Value',1)
0982     val=1;
0983 end
0984 % specify operations to apply to the data prior to prediction
0985 ind=handles.indop{1}(val);
0986 handles.operations=[handles.operations, ind];
0987 handles.indop{1}=setdiff(handles.indop{1},ind);
0988 if isempty(handles.indop{1})
0989     handles.indop{1}=0;
0990     set(handles.uns_list,'String',{''})
0991 else
0992     set(handles.uns_list,'String',{handles.namop{handles.indop{1}}})    
0993 end
0994 set(handles.uns_list,'Value',1)
0995 if handles.indop{2}==0
0996     handles.indop{2}=ind;
0997 else
0998     handles.indop{2}=[handles.indop{2},ind];
0999 end
1000 set(handles.sel_list,'String',{handles.namop{handles.indop{2}}})
1001 set(handles.sel_list,'Value',length(handles.indop{2}))
1002 % Update handles structure
1003 guidata(hObject, handles);
1004 
1005 % --- Executes during object creation, after setting all properties.
1006 function uns_list_CreateFcn(hObject, eventdata, handles)
1007 % hObject    handle to uns_list (see GCBO)
1008 % eventdata  reserved - to be defined in a future version of MATLAB
1009 % handles    empty - handles not created until after all CreateFcns called
1010 
1011 % Hint: listbox controls usually have a white background on Windows.
1012 %       See ISPC and COMPUTER.
1013 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1014     set(hObject,'BackgroundColor','white');
1015 end
1016 
1017 
1018 % --- Executes on selection change in sel_list.
1019 function sel_list_Callback(hObject, eventdata, handles)
1020 % hObject    handle to sel_list (see GCBO)
1021 % eventdata  reserved - to be defined in a future version of MATLAB
1022 % handles    structure with handles and user data (see GUIDATA)
1023 
1024 % Hints: contents = get(hObject,'String') returns sel_list contents as cell array
1025 %        contents{get(hObject,'Value')} returns selected item from sel_list
1026 val=get(handles.sel_list,'Value');
1027 if val==0
1028     warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
1029     set(handles.sel_list,'Value',1)
1030     val=1;
1031 end
1032 % specify operations to apply to the data prior to prediction
1033 ind=handles.indop{2}(val);
1034 handles.operations=setdiff(handles.operations, ind);
1035 handles.indop{2}=setdiff(handles.indop{2},ind);
1036 if isempty(handles.indop{2})
1037     handles.indop{2}=0;
1038     set(handles.sel_list,'String',{''})
1039 else
1040     set(handles.sel_list,'String',{handles.namop{handles.indop{2}}})    
1041 end
1042 set(handles.sel_list,'Value',1)
1043 if handles.indop{1}==0
1044     handles.indop{1}=ind;
1045 else
1046     handles.indop{1}=[handles.indop{1},ind];
1047 end
1048 set(handles.uns_list,'String',{handles.namop{handles.indop{1}}})
1049 set(handles.uns_list,'Value',length(handles.indop{1}))
1050 % Update handles structure
1051 guidata(hObject, handles);
1052 
1053 % --- Executes during object creation, after setting all properties.
1054 function sel_list_CreateFcn(hObject, eventdata, handles)
1055 % hObject    handle to sel_list (see GCBO)
1056 % eventdata  reserved - to be defined in a future version of MATLAB
1057 % handles    empty - handles not created until after all CreateFcns called
1058 
1059 % Hint: listbox controls usually have a white background on Windows.
1060 %       See ISPC and COMPUTER.
1061 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1062     set(hObject,'BackgroundColor','white');
1063 end
1064 
1065 
1066 
1067 % --- Executes on button press in buildbutt.
1068 function buildbutt_Callback(hObject, eventdata, handles)
1069 % hObject    handle to buildbutt (see GCBO)
1070 % eventdata  reserved - to be defined in a future version of MATLAB
1071 % handles    structure with handles and user data (see GUIDATA)
1072 
1073 %fill the input of the 'prt_model' button
1074 in.fname=get(handles.edit_prt,'String');
1075 if ~isfield(handles,'model_name')
1076     beep
1077     disp('Please, provide a model name')
1078     return
1079 end
1080 if handles.flagguicv
1081     %reload prt since the new CV has been saved in it
1082     fname=get(handles.edit_prt,'String');
1083     load(fname) % no need for prt_load here
1084     handles.dat = PRT;   
1085 end
1086 in.model_name=handles.model_name;
1087 in.type=handles.type;
1088 in.machine=handles.machine;
1089 in.use_kernel=handles.use_kernel;
1090 in.operations=handles.operations;
1091 in.fs(1).fs_name=handles.fs(1).fs_name;
1092 in.cv=handles.cv;
1093 %check that classes/subjects/scans were defined
1094 if strcmpi(in.type,'classification')
1095     if ~isfield(handles,'class')
1096         beep
1097         disp('No class selected for classification')
1098         disp('Please, define classes')
1099         return
1100     else
1101         for i=1:length(handles.class)
1102             ind=[];
1103             for g=1:length(handles.class(i).group)
1104                 if ~isempty(handles.class(i).group(g).gr_name)
1105                     ind=[ind,g];
1106                 end
1107             end
1108             handles.class(i).group=handles.class(i).group(ind);
1109         end
1110         in.class=handles.class;
1111     end
1112 else
1113     if ~isfield(handles,'group')
1114         beep
1115         disp('No subjects/scans selected for classification')
1116         disp('Please, select subjects/scans')
1117         return
1118     else
1119         ind=[];
1120         for g=1:length(handles.group)
1121             if ~isempty(handles.group(g).gr_name)
1122                 ind=[ind,g];
1123             end
1124         end
1125         handles.group=handles.group(ind);
1126         in.group=handles.group;
1127     end
1128 end
1129 
1130 %checks on the CV framework compared to the model entered
1131 if strcmpi(in.cv.type,'lobo')
1132     if ~isfield(in,'class')
1133         beep
1134         disp('Leave One Block Out cross-validation only allowed for classification')
1135         disp('Please correct')
1136         return
1137     else
1138         for c=1:length(in.class)
1139             for i=1:length(in.class(c).group)
1140                 if length(in.class(c).group(i).subj)>1
1141                     beep
1142                     disp('Leave One Block Out cross-validation only allowed for within-subject classification')
1143                     disp('Please correct')
1144                     return
1145                 end
1146             end
1147         end
1148     end
1149 end
1150 if ~isfield(in,'class')
1151     if ~strcmpi(in.cv.type,'loso')
1152         beep
1153         disp('Regression only allows a Leave (One) Subject Out cross-validation')
1154         disp('Please correct')
1155     end
1156 end
1157 PRT=prt_model(handles.dat,in);
1158 clear in
1159 in.fname      = get(handles.edit_prt,'String');
1160 in.model_name = handles.model_name;
1161 if exist('PRT','var')
1162     clear PRT
1163 end
1164 load(in.fname)
1165 mid = prt_init_model(PRT, in);
1166 % Special cross-validation for MCKR
1167 if strcmpi(PRT.model(mid).input.machine.function,'prt_machine_mckr')
1168     prt_cv_mckr(PRT,in);
1169 else
1170     prt_cv_model(PRT, in);
1171 end
1172 disp('Model specification and estimation complete.')
1173 disp('Done...')
1174 delete(handles.figure1)
1175 
1176 
1177 % --- Executes on button press in buildbutt.
1178 function specbutt_Callback(hObject, eventdata, handles)
1179 % hObject    handle to buildbutt (see GCBO)
1180 % eventdata  reserved - to be defined in a future version of MATLAB
1181 % handles    structure with handles and user data (see GUIDATA)
1182 
1183 %fill the input of the 'prt_model' button
1184 in.fname=get(handles.edit_prt,'String');
1185 if ~isfield(handles,'model_name')
1186     beep
1187     disp('Please enter a valid model name')
1188 end
1189 if handles.flagguicv
1190     %reload prt since the new CV has been saved in it
1191     fname=get(handles.edit_prt,'String');
1192     load(fname) % no need for prt_load here
1193     handles.dat = PRT;   
1194 end
1195 in.model_name=handles.model_name;
1196 in.type=handles.type;
1197 in.machine=handles.machine;
1198 in.use_kernel=handles.use_kernel;
1199 in.operations=handles.operations;
1200 in.fs(1).fs_name=handles.fs(1).fs_name;
1201 in.cv=handles.cv;
1202 %check that classes/subjects/scans were defined
1203 if strcmpi(in.type,'classification')
1204     if ~isfield(handles,'class')
1205         beep
1206         disp('No class selected for classification')
1207         disp('Please, define classes')
1208         return
1209     else
1210         for i=1:length(handles.class)
1211             ind=[];
1212             for g=1:length(handles.class(i).group)
1213                 if ~isempty(handles.class(i).group(g).gr_name)
1214                     ind=[ind,g];
1215                 end
1216             end
1217             handles.class(i).group=handles.class(i).group(ind);
1218         end
1219         in.class=handles.class;
1220     end
1221 else
1222     if ~isfield(handles,'group')
1223         beep
1224         disp('No subjects/scans selected for classification')
1225         disp('Please, select subjects/scans')
1226         return
1227     else
1228         ind=[];
1229         for g=1:length(handles.group)
1230             if ~isempty(handles.group(g).gr_name)
1231                 ind=[ind,g];
1232             end
1233         end
1234         handles.group=handles.group(ind);
1235         in.group=handles.group;
1236     end
1237 end
1238 
1239 %checks on the CV framework compared to the model entered
1240 if strcmpi(in.cv.type,'lobo')
1241     if ~isfield(in,'class')
1242         beep
1243         disp('Leave One Block Out cross-validation only allowed for classification')
1244         disp('Please correct')
1245         return
1246     else
1247         for c=1:length(in.class)
1248             for i=1:length(in.class(c).group)
1249                 if length(in.class(c).group(i).subj)>1
1250                     beep
1251                     disp('Leave One Block Out cross-validation only allowed for within-subject classification')
1252                     disp('Please correct')
1253                     return
1254                 end
1255             end
1256         end
1257     end
1258 end
1259 if ~isfield(in,'class')
1260     if ~strcmpi(in.cv.type,'loso')
1261         beep
1262         disp('Regression only allows a Leave One Subject Out cross-validation')
1263         disp('Please correct')
1264     end
1265 end
1266 
1267 prt_model(handles.dat,in);
1268 
1269 disp('Model specification complete.')
1270 disp('Done...')
1271 delete(handles.figure1)
1272 
1273 
1274 % --- Executes on selection change in pop_cv_nested.
1275 function pop_cv_nested_Callback(hObject, eventdata, handles)
1276 % hObject    handle to pop_cv_nested (see GCBO)
1277 % eventdata  reserved - to be defined in a future version of MATLAB
1278 % handles    structure with handles and user data (see GUIDATA)
1279 
1280 % Hints: contents = cellstr(get(hObject,'String')) returns pop_cv_nested contents as cell array
1281 %        contents{get(hObject,'Value')} returns selected item from pop_cv_nested
1282 val=get(handles.pop_cv_nested,'Value');
1283 mach=get(handles.pop_cv_nested,'String');
1284 handles.cv.k_nested=0; %by default, Leave-One-Out options
1285 if val==0
1286     warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
1287     set(handles.pop_cv_nested,'Value',1)
1288     val=1;
1289 end
1290 if any(strfind(mach{val},'Subject Out'))
1291     handles.cv.type_nested = 'loso';
1292 elseif any(strfind(mach{val},'Subject per Group'))
1293     if ~handles.loospg
1294         beep
1295         disp('Warning: Subjects are not balanced across classes!')
1296     end
1297     handles.cv.type_nested = 'losgo';
1298 elseif any(strfind(mach{val},'Block'))
1299     handles.cv.type_nested = 'lobo';
1300 elseif any(strfind(mach{val},'Run'))        %currently implemented for MCKR only
1301     handles.cv.type_nested = 'loro';
1302 else
1303     beep
1304     disp('CV type not supported for inner CV')
1305     return
1306 end
1307 if any(strfind(mach{val},'k-fold'))
1308     kt=prt_text_input('Title','Specify k, the number of folds');
1309     handles.cv.k_nested=str2num(kt);
1310 end
1311 % Update handles structure
1312 guidata(hObject, handles);
1313 
1314 % --- Executes during object creation, after setting all properties.
1315 function pop_cv_nested_CreateFcn(hObject, eventdata, handles)
1316 % hObject    handle to pop_cv_nested (see GCBO)
1317 % eventdata  reserved - to be defined in a future version of MATLAB
1318 % handles    empty - handles not created until after all CreateFcns called
1319 
1320 % Hint: popupmenu controls usually have a white background on Windows.
1321 %       See ISPC and COMPUTER.
1322 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1323     set(hObject,'BackgroundColor','white');
1324 end

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