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: prt_ui_model.m 527 2012-05-16 12:59:08Z schrouff $
0030 
0031 % Edit the above text to modify the response to help prt_ui_kernel_construction
0032 
0033 % Last Modified by GUIDE v2.5 24-Mar-2012 11:44:44
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     if ispc
0136         set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
0137             'FontUnits','normalized','Units','normalized')
0138     else
0139         set(aa(i),'FontSize',ceil(FS*xf),'FontName',PF,...
0140             'Units','normalized')
0141     end
0142 end
0143 
0144 
0145 
0146 %Set defaults for some subfields and popup menus
0147 handles.def=prt_get_defaults('model');
0148 set(handles.usekern,'Value',1)
0149 handles.use_kernel=1;
0150 set(handles.pop_cv,'String',{'Custom'})
0151 set(handles.pop_cv,'Value',1)
0152 handles.cv.type='loso';
0153 handles.cv.mat_file=[];
0154 set(handles.pop_reg,'String',{'Classification','Regression'})
0155 set(handles.pop_reg,'Value',1)
0156 handles.type='classification';
0157 set(handles.butt_defclass,'ForegroundColor',handles.color.high)
0158 set(handles.pop_machine,'String',{'Binary support vector machine',...
0159         'Binary Gaussian Process Classification','Random Forest',...
0160         'Multiclass GPC'})
0161 set(handles.pop_machine,'Value',1)
0162 handles.machine.function='prt_machine_svm_bin';
0163 handles.machine.args=handles.def.svmargs;
0164 list={'Temporal Compression', ...
0165     'Sample averaging',... %(average samples for each subject/condition)
0166     'Mean centre features over subjects',...
0167     'Divide data vectors by their norm',...
0168     'Perform a GLM (fMRI only)'};
0169 handles.indop{1}=1:length(list);
0170 handles.indop{2}=0;
0171 set(handles.uns_list,'String',list)
0172 set(handles.sel_list,'String',{''})
0173 handles.operations = [];
0174 handles.namop=list;
0175 set(handles.uns_list,'Value',1)
0176 set(handles.sel_list,'Value',1)
0177 end
0178 % Update handles structure
0179 guidata(hObject, handles);
0180 
0181 % UIWAIT makes prt_ui_kernel_construction wait for user response (see UIRESUME)
0182 % uiwait(handles.figure1);
0183 
0184 
0185 % --- Outputs from this function are returned to the command line.
0186 function varargout = prt_ui_model_OutputFcn(hObject, eventdata, handles) 
0187 % varargout  cell array for returning output args (see VARARGOUT);
0188 % hObject    handle to figure
0189 % eventdata  reserved - to be defined in a future version of MATLAB
0190 % handles    structure with handles and user data (see GUIDATA)
0191 
0192 % Get default command line output from handles structure
0193 if isfield(handles,'output') && ~isempty(handles.output)
0194     varargout{1} = handles.output;
0195 else
0196     varargout{1}=[];
0197 end
0198 
0199 
0200 
0201 
0202 % --- Executes on button press in br_prt.
0203 function br_prt_Callback(hObject, eventdata, handles)
0204 % hObject    handle to br_prt (see GCBO)
0205 % eventdata  reserved - to be defined in a future version of MATLAB
0206 % handles    structure with handles and user data (see GUIDATA)
0207 fname=spm_select(1,'.mat','Select PRT.mat',[],pwd,'PRT.mat');
0208 if exist('PRT','var')
0209     clear PRT
0210 end
0211 PRT=prt_load(fname);
0212 if ~isempty(PRT)
0213     handles.dat=PRT;
0214     set(handles.edit_prt,'String',fname);
0215 else
0216     beep
0217     disp('Could not load file')
0218     return
0219 end
0220 
0221 if ~isfield(handles.dat,'fs')
0222     beep
0223     disp('No feature set found in the PRT.mat')
0224     disp('Please, prepare feature set before computing model')
0225     delete(handles.figure1)
0226     return
0227 end
0228 list={};
0229 for i=1:length(PRT.fs)
0230     if ~isempty(PRT.fs(i).fs_name)
0231         list=[list; {PRT.fs(i).fs_name}];
0232     end
0233 end
0234 set(handles.pop_featset,'String',list)
0235 set(handles.pop_featset,'Value',1)
0236 list=get(handles.pop_featset,'String');
0237 handles.fs(1).fs_name=list{1};
0238 handles.fs(1).indfs=1;
0239 
0240 % Update handles structure
0241 guidata(hObject, handles);
0242 
0243 
0244 
0245 function edit_prt_Callback(hObject, eventdata, handles)
0246 % hObject    handle to edit_prt (see GCBO)
0247 % eventdata  reserved - to be defined in a future version of MATLAB
0248 % handles    structure with handles and user data (see GUIDATA)
0249 
0250 % Hints: get(hObject,'String') returns contents of edit_prt as text
0251 %        str2double(get(hObject,'String')) returns contents of edit_prt as a double
0252 fname=get(handles.edit_prt,'String');
0253 if exist('PRT','var')
0254     clear PRT
0255 end
0256 PRT=prt_load(fname);
0257 if ~isempty(PRT)
0258     handles.dat=PRT;
0259     set(handles.edit_prt,'String',fname);
0260 else
0261     beep
0262     disp('Could not load file')
0263     return
0264 end
0265 
0266 if ~isfield(handles.dat,'fs')
0267     beep
0268     disp('No feature set found in the PRT.mat')
0269     disp('Please, prepare feature set before computing model')
0270     delete(handles.figure1)
0271     return
0272 end
0273 list={};
0274 for i=1:length(PRT.fs)
0275     if ~isempty(PRT.fs(i).fs_name)
0276         list=[list; {PRT.fs(i).fs_name}];
0277     end
0278 end
0279 set(handles.pop_featset,'String',list)
0280 set(handles.pop_featset,'Value',1)
0281 list=get(handles.pop_featset,'String');
0282 handles.fs(1).fs_name=list{1};
0283 handles.fs(1).indfs=1;
0284 
0285 % Update handles structure
0286 guidata(hObject, handles);
0287 
0288 
0289 % --- Executes during object creation, after setting all properties.
0290 function edit_prt_CreateFcn(hObject, eventdata, handles)
0291 % hObject    handle to edit_prt (see GCBO)
0292 % eventdata  reserved - to be defined in a future version of MATLAB
0293 % handles    empty - handles not created until after all CreateFcns called
0294 
0295 % Hint: edit controls usually have a white background on Windows.
0296 %       See ISPC and COMPUTER.
0297 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0298     set(hObject,'BackgroundColor','white');
0299 end
0300 
0301 function edit_modelname_Callback(hObject, eventdata, handles)
0302 % hObject    handle to edit_modelname (see GCBO)
0303 % eventdata  reserved - to be defined in a future version of MATLAB
0304 % handles    structure with handles and user data (see GUIDATA)
0305 
0306 % Hints: get(hObject,'String') returns contents of edit_modelname as text
0307 %        str2double(get(hObject,'String')) returns contents of edit_modelname as a double
0308 handles.model_name=deblank(get(handles.edit_modelname,'String'));
0309 if ~(prt_checkAlphaNumUnder(handles.model_name))
0310     beep
0311     disp('Model name should be entered in alphanumeric format only')
0312     disp('Please correct')
0313     set(handles.edit_modelname,'ForegroundColor',[1,0,0])
0314     return
0315 else
0316     set(handles.edit_modelname,'ForegroundColor',[0,0,0])
0317 end
0318 % Update handles structure
0319 guidata(hObject, handles);
0320 
0321 % --- Executes during object creation, after setting all properties.
0322 function edit_modelname_CreateFcn(hObject, eventdata, handles)
0323 % hObject    handle to edit_modelname (see GCBO)
0324 % eventdata  reserved - to be defined in a future version of MATLAB
0325 % handles    empty - handles not created until after all CreateFcns called
0326 
0327 % Hint: edit controls usually have a white background on Windows.
0328 %       See ISPC and COMPUTER.
0329 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0330     set(hObject,'BackgroundColor','white');
0331 end
0332 
0333 % --- Executes on selection change in pop_featset.
0334 function pop_featset_Callback(hObject, eventdata, handles)
0335 % hObject    handle to pop_featset (see GCBO)
0336 % eventdata  reserved - to be defined in a future version of MATLAB
0337 % handles    structure with handles and user data (see GUIDATA)
0338 
0339 % Hints: contents = get(hObject,'String') returns pop_featset contents as cell array
0340 %        contents{get(hObject,'Value')} returns selected item from pop_featset
0341 val=get(handles.pop_featset,'Value');
0342 if val==0
0343     warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0344     set(handles.pop_feaset,'Value',1)
0345     val=1;
0346 end
0347 list=get(handles.pop_featset,'String');
0348 handles.fs(1).fs_name=list{val};
0349 handles.fs(1).indfs=val;
0350 if length(handles.dat.fs(val).modality)>1
0351     list=get(handles.pop_cv,'String');
0352     list=[list;{'Leave One Run/Session Out'}];
0353     set(handles.pop_cv,'String',list)
0354     set(handles.pop_cv,'Value',1)
0355 end
0356 % Update handles structure
0357 guidata(hObject, handles);
0358 
0359 % --- Executes during object creation, after setting all properties.
0360 function pop_featset_CreateFcn(hObject, eventdata, handles)
0361 % hObject    handle to pop_featset (see GCBO)
0362 % eventdata  reserved - to be defined in a future version of MATLAB
0363 % handles    empty - handles not created until after all CreateFcns called
0364 
0365 % Hint: popupmenu controls usually have a white background on Windows.
0366 %       See ISPC and COMPUTER.
0367 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0368     set(hObject,'BackgroundColor','white');
0369 end
0370 
0371 
0372 % --- Executes on button press in usekern.
0373 function usekern_Callback(hObject, eventdata, handles)
0374 % hObject    handle to usekern (see GCBO)
0375 % eventdata  reserved - to be defined in a future version of MATLAB
0376 % handles    structure with handles and user data (see GUIDATA)
0377 
0378 % Hint: get(hObject,'Value') returns toggle state of usekern
0379 handles.use_kernel=get(handles.usekern,'Value');
0380 % Update handles structure
0381 guidata(hObject, handles);
0382 
0383 
0384 % --- Executes on selection change in pop_reg.
0385 function pop_reg_Callback(hObject, eventdata, handles)
0386 % hObject    handle to pop_reg (see GCBO)
0387 % eventdata  reserved - to be defined in a future version of MATLAB
0388 % handles    structure with handles and user data (see GUIDATA)
0389 
0390 % Hints: contents = get(hObject,'String') returns pop_reg contents as cell array
0391 %        contents{get(hObject,'Value')} returns selected item from pop_reg
0392 val=get(handles.pop_reg,'Value');
0393 if val==0
0394     warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0395     set(handles.pop_reg,'Value',1)
0396     val=1;
0397 end
0398 if val==1 %Classification
0399     handles.type='classification';
0400     %set the list of machines
0401     set(handles.pop_machine,'String',{'Binary support vector machine',...
0402         'Binary Gaussian Process Classification','Random Forest',...
0403         'Multiclass GPC'})
0404     set(handles.pop_machine,'Value',1)
0405     handles.machine.function='prt_machine_svm_bin';
0406     handles.machine.args=handles.def.svmargs;
0407     set(handles.butt_defclass,'String','Define classes')
0408 elseif val==2
0409     handles.type='regression';
0410     set(handles.butt_defclass,'String','Select subjects/scans')
0411     %set the list of machines
0412     set(handles.pop_machine,'String',{'Kernel Ridge Regression',...
0413         'Relevance Vector Regression','Gaussian Process Regression'})
0414     set(handles.pop_machine,'Value',1)
0415     handles.machine.function='prt_machine_krr';
0416     handles.machine.args=handles.def.krrargs;
0417 end
0418 set(handles.butt_defclass,'ForegroundColor',handles.color.high)
0419 % Update handles structure
0420 guidata(hObject, handles);
0421 
0422 % --- Executes during object creation, after setting all properties.
0423 function pop_reg_CreateFcn(hObject, eventdata, handles)
0424 % hObject    handle to pop_reg (see GCBO)
0425 % eventdata  reserved - to be defined in a future version of MATLAB
0426 % handles    empty - handles not created until after all CreateFcns called
0427 
0428 % Hint: popupmenu controls usually have a white background on Windows.
0429 %       See ISPC and COMPUTER.
0430 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0431     set(hObject,'BackgroundColor','white');
0432 end
0433 
0434 
0435 
0436 % --- Executes on button press in but_defclass.
0437 function butt_defclass_Callback(hObject, eventdata, handles)
0438 % hObject    handle to butt_def_class (see GCBO)
0439 % eventdata  reserved - to be defined in a future version of MATLAB
0440 % handles    structure with handles and user data (see GUIDATA)
0441 if strcmpi(handles.type,'classification')
0442     speccl=prt_ui_select_class('UserData',{handles.dat,handles.fs(1).indfs});
0443     handles.class=speccl.class;
0444     ns=zeros(length(speccl.class),1);
0445     for ii=1:length(speccl.class)
0446         for jj=1:length(speccl.class(ii).group)
0447             ns(ii)=ns(ii)+length(speccl.class(ii).group(jj).subj);
0448         end
0449     end
0450     if min(ns)>1
0451         list=get(handles.pop_cv,'String');
0452         list=[list;{'Leave One Subject Out'}];
0453         set(handles.pop_cv,'String',list)
0454         set(handles.pop_cv,'Value',1)
0455     end
0456     if (speccl.design)
0457         list=get(handles.pop_cv,'String');
0458         list=[list;{'Leave One Block Out'}];
0459         set(handles.pop_cv,'String',list)
0460         set(handles.pop_cv,'Value',1)
0461     end
0462     handles.loospg=speccl.loospg;
0463     list=get(handles.pop_cv,'String');
0464     list=[list;{'Leave One One Subject per Group Out'}];
0465     set(handles.pop_cv,'String',list)
0466     set(handles.pop_cv,'Value',1)
0467 else
0468     sel=prt_ui_select_reg('UserData',{handles.dat,handles.fs(1).indfs});
0469     handles.group=sel;
0470     if length(sel.subj)>1
0471         list=get(handles.pop_cv,'String');
0472         list=[list;{'Leave One Subject Out'}];
0473         set(handles.pop_cv,'String',list)
0474         set(handles.pop_cv,'Value',1)
0475     end
0476 end
0477 set(handles.butt_defclass,'ForegroundColor',[0 0 0])
0478 % Update handles structure
0479 guidata(hObject, handles);
0480 
0481 
0482 % --- Executes on selection change in pop_machine.
0483 function pop_machine_Callback(hObject, eventdata, handles)
0484 % hObject    handle to pop_machine (see GCBO)
0485 % eventdata  reserved - to be defined in a future version of MATLAB
0486 % handles    structure with handles and user data (see GUIDATA)
0487 
0488 % Hints: contents = get(hObject,'String') returns pop_machine contents as cell array
0489 %        contents{get(hObject,'Value')} returns selected item from pop_machine
0490 mach=get(handles.pop_machine,'String');
0491 val=get(handles.pop_machine,'Value');
0492 if val==0
0493     warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0494     set(handles.pop_machine,'Value',1)
0495     val=1;
0496 end
0497 if any(strfind(mach{val},'support'))
0498     handles.machine.function='prt_machine_svm_bin';
0499     handles.machine.args=handles.def.svmargs;
0500 elseif any(strfind(mach{val},'Binary Gaussian'))
0501     handles.machine.function='prt_machine_gpml';
0502     handles.machine.args=handles.def.gpcargs;
0503 elseif any(strfind(mach{val},'Multiclass GPC'))
0504     handles.machine.function='prt_machine_gpclap';
0505     handles.machine.args=handles.def.gpclapargs;
0506 elseif any(strfind(mach{val},'Ridge'))
0507     handles.machine.function='prt_machine_krr';
0508     handles.machine.args=handles.def.krrargs;
0509 elseif any(strfind(mach{val},'Relevance'))
0510     handles.machine.function='prt_machine_rvr';
0511     handles.machine.args=[];
0512 elseif any(strfind(mach{val},'Process Regression'))
0513     handles.machine.function='prt_machine_gpr';
0514     handles.machine.args=handles.def.gprargs;
0515 elseif any(strfind(mach{val},'Random'))
0516     handles.machine.function='prt_machine_RT_bin';
0517     handles.machine.args=handles.def.rtargs;    
0518 end
0519 % Update handles structure
0520 guidata(hObject, handles);
0521 
0522 
0523 % --- Executes during object creation, after setting all properties.
0524 function pop_machine_CreateFcn(hObject, eventdata, handles)
0525 % hObject    handle to pop_machine (see GCBO)
0526 % eventdata  reserved - to be defined in a future version of MATLAB
0527 % handles    empty - handles not created until after all CreateFcns called
0528 
0529 % Hint: popupmenu controls usually have a white background on Windows.
0530 %       See ISPC and COMPUTER.
0531 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0532     set(hObject,'BackgroundColor','white');
0533 end
0534 
0535 % --- Executes on selection change in pop_cv.
0536 function pop_cv_Callback(hObject, eventdata, handles)
0537 % hObject    handle to pop_cv (see GCBO)
0538 % eventdata  reserved - to be defined in a future version of MATLAB
0539 % handles    structure with handles and user data (see GUIDATA)
0540 
0541 % Hints: contents = get(hObject,'String') returns pop_cv contents as cell array
0542 %        contents{get(hObject,'Value')} returns selected item from pop_cv
0543 % assemble structure for performing cross-validation
0544 val=get(handles.pop_cv,'Value');
0545 mach=get(handles.pop_cv,'String');
0546 if val==0
0547     warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0548     set(handles.pop_cv,'Value',1)
0549     val=1;
0550 end
0551 if any(strfind(mach{val},'Subject Out'))
0552     handles.cv.type = 'loso';
0553 elseif any(strfind(mach{val},'Subject per Group'))
0554     if ~handles.loospg
0555         beep
0556         disp('Subjects are not balanced across classes')
0557         disp('All will not be used for training/testing')
0558     end
0559     handles.cv.type = 'losgo';
0560 elseif any(strfind(mach{val},'Block'))
0561     handles.cv.type = 'lobo';
0562 elseif any(strfind(mach{val},'Run'))        %currently implemented for MCKR only
0563     handles.cv.type = 'loro';
0564 else
0565     handles.cv.type     = 'custom';
0566     cvmatf=spm_select(1,'mat','Select .mat file corresponding to the custom cross-validation');
0567     handles.cv.mat_file = cvmatf;
0568 end
0569 % Update handles structure
0570 guidata(hObject, handles);
0571 
0572 % --- Executes during object creation, after setting all properties.
0573 function pop_cv_CreateFcn(hObject, eventdata, handles)
0574 % hObject    handle to pop_cv (see GCBO)
0575 % eventdata  reserved - to be defined in a future version of MATLAB
0576 % handles    empty - handles not created until after all CreateFcns called
0577 
0578 % Hint: popupmenu controls usually have a white background on Windows.
0579 %       See ISPC and COMPUTER.
0580 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0581     set(hObject,'BackgroundColor','white');
0582 end
0583 
0584 % --- Executes on selection change in uns_list.
0585 function uns_list_Callback(hObject, eventdata, handles)
0586 % hObject    handle to uns_list (see GCBO)
0587 % eventdata  reserved - to be defined in a future version of MATLAB
0588 % handles    structure with handles and user data (see GUIDATA)
0589 
0590 % Hints: contents = get(hObject,'String') returns uns_list contents as cell array
0591 %        contents{get(hObject,'Value')} returns selected item from uns_list
0592 val=get(handles.uns_list,'Value');
0593 if val==0
0594     warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0595     set(handles.uns_list,'Value',1)
0596     val=1;
0597 end
0598 % specify operations to apply to the data prior to prediction
0599 ind=handles.indop{1}(val);
0600 handles.operations=[handles.operations, ind];
0601 handles.indop{1}=setdiff(handles.indop{1},ind);
0602 if isempty(handles.indop{1})
0603     handles.indop{1}=0;
0604     set(handles.uns_list,'String',{''})
0605 else
0606     set(handles.uns_list,'String',{handles.namop{handles.indop{1}}})    
0607 end
0608 set(handles.uns_list,'Value',1)
0609 if handles.indop{2}==0
0610     handles.indop{2}=ind;
0611 else
0612     handles.indop{2}=[handles.indop{2},ind];
0613 end
0614 set(handles.sel_list,'String',{handles.namop{handles.indop{2}}})
0615 set(handles.sel_list,'Value',length(handles.indop{2}))
0616 % Update handles structure
0617 guidata(hObject, handles);
0618 
0619 % --- Executes during object creation, after setting all properties.
0620 function uns_list_CreateFcn(hObject, eventdata, handles)
0621 % hObject    handle to uns_list (see GCBO)
0622 % eventdata  reserved - to be defined in a future version of MATLAB
0623 % handles    empty - handles not created until after all CreateFcns called
0624 
0625 % Hint: listbox controls usually have a white background on Windows.
0626 %       See ISPC and COMPUTER.
0627 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0628     set(hObject,'BackgroundColor','white');
0629 end
0630 
0631 
0632 % --- Executes on selection change in sel_list.
0633 function sel_list_Callback(hObject, eventdata, handles)
0634 % hObject    handle to sel_list (see GCBO)
0635 % eventdata  reserved - to be defined in a future version of MATLAB
0636 % handles    structure with handles and user data (see GUIDATA)
0637 
0638 % Hints: contents = get(hObject,'String') returns sel_list contents as cell array
0639 %        contents{get(hObject,'Value')} returns selected item from sel_list
0640 val=get(handles.sel_list,'Value');
0641 if val==0
0642     warning('off','MATLAB:hg:uicontrol:ParameterValuesMustBeValid')
0643     set(handles.sel_list,'Value',1)
0644     val=1;
0645 end
0646 % specify operations to apply to the data prior to prediction
0647 ind=handles.indop{2}(val);
0648 handles.operations=setdiff(handles.operations, ind);
0649 handles.indop{2}=setdiff(handles.indop{2},ind);
0650 if isempty(handles.indop{2})
0651     handles.indop{2}=0;
0652     set(handles.sel_list,'String',{''})
0653 else
0654     set(handles.sel_list,'String',{handles.namop{handles.indop{2}}})    
0655 end
0656 set(handles.sel_list,'Value',1)
0657 if handles.indop{1}==0
0658     handles.indop{1}=ind;
0659 else
0660     handles.indop{1}=[handles.indop{1},ind];
0661 end
0662 set(handles.uns_list,'String',{handles.namop{handles.indop{1}}})
0663 set(handles.uns_list,'Value',length(handles.indop{1}))
0664 % Update handles structure
0665 guidata(hObject, handles);
0666 
0667 % --- Executes during object creation, after setting all properties.
0668 function sel_list_CreateFcn(hObject, eventdata, handles)
0669 % hObject    handle to sel_list (see GCBO)
0670 % eventdata  reserved - to be defined in a future version of MATLAB
0671 % handles    empty - handles not created until after all CreateFcns called
0672 
0673 % Hint: listbox controls usually have a white background on Windows.
0674 %       See ISPC and COMPUTER.
0675 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0676     set(hObject,'BackgroundColor','white');
0677 end
0678 
0679 
0680 
0681 % --- Executes on button press in buildbutt.
0682 function buildbutt_Callback(hObject, eventdata, handles)
0683 % hObject    handle to buildbutt (see GCBO)
0684 % eventdata  reserved - to be defined in a future version of MATLAB
0685 % handles    structure with handles and user data (see GUIDATA)
0686 
0687 %fill the input of the 'prt_model' button
0688 in.fname=get(handles.edit_prt,'String');
0689 if ~isfield(handles,'model_name')
0690     beep
0691     disp('Please, provide a model name')
0692     return
0693 end
0694 in.model_name=handles.model_name;
0695 in.type=handles.type;
0696 in.machine=handles.machine;
0697 in.use_kernel=handles.use_kernel;
0698 in.operations=handles.operations;
0699 in.fs(1).fs_name=handles.fs(1).fs_name;
0700 in.cv=handles.cv;
0701 %check that classes/subjects/scans were defined
0702 if strcmpi(in.type,'classification')
0703     if ~isfield(handles,'class')
0704         beep
0705         disp('No class selected for classification')
0706         disp('Please, define classes')
0707         return
0708     else
0709         for i=1:length(handles.class)
0710             ind=[];
0711             for g=1:length(handles.class(i).group)
0712                 if ~isempty(handles.class(i).group(g).gr_name)
0713                     ind=[ind,g];
0714                 end
0715             end
0716             handles.class(i).group=handles.class(i).group(ind);
0717         end
0718         in.class=handles.class;
0719     end
0720 else
0721     if ~isfield(handles,'group')
0722         beep
0723         disp('No subjects/scans selected for classification')
0724         disp('Please, select subjects/scans')
0725         return
0726     else
0727         ind=[];
0728         for g=1:length(handles.group)
0729             if ~isempty(handles.group(g).gr_name)
0730                 ind=[ind,g];
0731             end
0732         end
0733         handles.group=handles.group(ind);
0734         in.group=handles.group;
0735     end
0736 end
0737 
0738 %checks on the CV framework compared to the model entered
0739 if strcmpi(in.cv.type,'lobo')
0740     if ~isfield(in,'class')
0741         beep
0742         disp('Leave One Block Out cross-validation only allowed for classification')
0743         disp('Please correct')
0744         return
0745     else
0746         for c=1:length(in.class)
0747             for i=1:length(in.class(c).group)
0748                 if length(in.class(c).group(i).subj)>1
0749                     beep
0750                     disp('Leave One Block Out cross-validation only allowed for within-subject classification')
0751                     disp('Please correct')
0752                     return
0753                 end
0754             end
0755         end
0756     end
0757 end
0758 if ~isfield(in,'class')
0759     if ~strcmpi(in.cv.type,'loso')
0760         beep
0761         disp('Regression only allows a Leave One Subject Out cross-validation')
0762         disp('Please correct')
0763     end
0764 end
0765 PRT=prt_model(handles.dat,in);
0766 clear in
0767 in.fname      = get(handles.edit_prt,'String');
0768 in.model_name = handles.model_name;
0769 if exist('PRT','var')
0770     clear PRT
0771 end
0772 load(in.fname)
0773 mid = prt_init_model(PRT, in);
0774 % Special cross-validation for MCKR
0775 if strcmpi(PRT.model(mid).input.machine.function,'prt_machine_mckr')
0776     prt_cv_mckr(PRT,in);
0777 else
0778     prt_cv_model(PRT, in);
0779 end
0780 disp('Model specification and estimation complete.')
0781 disp('Done...')
0782 delete(handles.figure1)
0783 
0784 
0785 % --- Executes on button press in buildbutt.
0786 function specbutt_Callback(hObject, eventdata, handles)
0787 % hObject    handle to buildbutt (see GCBO)
0788 % eventdata  reserved - to be defined in a future version of MATLAB
0789 % handles    structure with handles and user data (see GUIDATA)
0790 
0791 %fill the input of the 'prt_model' button
0792 in.fname=get(handles.edit_prt,'String');
0793 if ~isfield(handles,'model_name')
0794     beep
0795     disp('Please enter a valid model name')
0796 end
0797 in.model_name=handles.model_name;
0798 in.type=handles.type;
0799 in.machine=handles.machine;
0800 in.use_kernel=handles.use_kernel;
0801 in.operations=handles.operations;
0802 in.fs(1).fs_name=handles.fs(1).fs_name;
0803 in.cv=handles.cv;
0804 %check that classes/subjects/scans were defined
0805 if strcmpi(in.type,'classification')
0806     if ~isfield(handles,'class')
0807         beep
0808         disp('No class selected for classification')
0809         disp('Please, define classes')
0810         return
0811     else
0812         for i=1:length(handles.class)
0813             ind=[];
0814             for g=1:length(handles.class(i).group)
0815                 if ~isempty(handles.class(i).group(g).gr_name)
0816                     ind=[ind,g];
0817                 end
0818             end
0819             handles.class(i).group=handles.class(i).group(ind);
0820         end
0821         in.class=handles.class;
0822     end
0823 else
0824     if ~isfield(handles,'group')
0825         beep
0826         disp('No subjects/scans selected for classification')
0827         disp('Please, select subjects/scans')
0828         return
0829     else
0830         ind=[];
0831         for g=1:length(handles.group)
0832             if ~isempty(handles.group(g).gr_name)
0833                 ind=[ind,g];
0834             end
0835         end
0836         handles.group=handles.group(ind);
0837         in.group=handles.group;
0838     end
0839 end
0840 
0841 %checks on the CV framework compared to the model entered
0842 if strcmpi(in.cv.type,'lobo')
0843     if ~isfield(in,'class')
0844         beep
0845         disp('Leave One Block Out cross-validation only allowed for classification')
0846         disp('Please correct')
0847         return
0848     else
0849         for c=1:length(in.class)
0850             for i=1:length(in.class(c).group)
0851                 if length(in.class(c).group(i).subj)>1
0852                     beep
0853                     disp('Leave One Block Out cross-validation only allowed for within-subject classification')
0854                     disp('Please correct')
0855                     return
0856                 end
0857             end
0858         end
0859     end
0860 end
0861 if ~isfield(in,'class')
0862     if ~strcmpi(in.cv.type,'loso')
0863         beep
0864         disp('Regression only allows a Leave One Subject Out cross-validation')
0865         disp('Please correct')
0866     end
0867 end
0868 
0869 prt_model(handles.dat,in);
0870 
0871 disp('Model specification complete.')
0872 disp('Done...')
0873 delete(handles.figure1)
0874

Generated on Sun 20-May-2012 13:24:48 by m2html © 2005