0001 function varargout = prt_ui_model(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
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
0053
0054
0055
0056 function prt_ui_model_OpeningFcn(hObject, eventdata, handles, varargin)
0057
0058
0059
0060
0061
0062
0063
0064 handles.output = hObject;
0065
0066
0067 Tag='modelwin';
0068 F = findall(allchild(0),'Flat','Tag',Tag);
0069 if length(F) > 1
0070
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
0080 set(handles.figure1,'Name','PRoNTo :: Specify model')
0081
0082
0083 S0= spm('WinSize','0',1);
0084 if ispc
0085 PF='MS Sans Serif';
0086 else
0087 PF= spm_platform('fonts');
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);
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
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
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)'};
0167
0168
0169
0170
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
0191 guidata(hObject, handles);
0192
0193
0194
0195
0196
0197
0198 function varargout = prt_ui_model_OutputFcn(hObject, eventdata, handles)
0199
0200
0201
0202
0203
0204
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
0215 function br_prt_Callback(hObject, eventdata, handles)
0216
0217
0218
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
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
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
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
0294 guidata(hObject, handles);
0295
0296
0297
0298 function edit_prt_Callback(hObject, eventdata, handles)
0299
0300
0301
0302
0303
0304
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
0353 handles.multimod = 1;
0354 else
0355 handles.multimod = 0;
0356 end
0357 if handles.dat.fs(1).multkernelROI
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
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
0379 guidata(hObject, handles);
0380
0381
0382
0383 function edit_prt_CreateFcn(hObject, eventdata, handles)
0384
0385
0386
0387
0388
0389
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
0396
0397
0398
0399
0400
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
0412 guidata(hObject, handles);
0413
0414
0415 function edit_modelname_CreateFcn(hObject, eventdata, handles)
0416
0417
0418
0419
0420
0421
0422 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0423 set(hObject,'BackgroundColor','white');
0424 end
0425
0426
0427 function pop_featset_Callback(hObject, eventdata, handles)
0428
0429
0430
0431
0432
0433
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
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
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
0473 if isfield(handles.dat.fs(val),'multkernel')&& handles.dat.fs(val).multkernel
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
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
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
0499 guidata(hObject, handles);
0500
0501
0502 function pop_featset_CreateFcn(hObject, eventdata, handles)
0503
0504
0505
0506
0507
0508
0509 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0510 set(hObject,'BackgroundColor','white');
0511 end
0512
0513
0514 function kernel_methods_Callback(hObject, eventdata, handles)
0515
0516
0517
0518
0519
0520 handles.use_kernel=get(handles.kernel_methods,'Value');
0521 if get(handles.pop_reg,'Value')==1
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
0541 guidata(hObject, handles);
0542
0543
0544
0545 function pop_reg_Callback(hObject, eventdata, handles)
0546
0547
0548
0549
0550
0551
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
0559 handles.type='classification';
0560 nk=get(handles.kernel_methods,'Value');
0561 if nk==1
0562
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
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
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
0593 guidata(hObject, handles);
0594
0595
0596 function pop_reg_CreateFcn(hObject, eventdata, handles)
0597
0598
0599
0600
0601
0602
0603 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0604 set(hObject,'BackgroundColor','white');
0605 end
0606
0607
0608
0609
0610 function butt_defclass_Callback(hObject, eventdata, handles)
0611
0612
0613
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
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
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
0686
0687
0688
0689 list = setdiff(list,'Custom');
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
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');
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
0735 guidata(hObject, handles);
0736
0737
0738
0739 function pop_machine_Callback(hObject, eventdata, handles)
0740
0741
0742
0743
0744
0745
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;
0780 end
0781
0782 guidata(hObject, handles);
0783
0784
0785
0786 function pop_machine_CreateFcn(hObject, eventdata, handles)
0787
0788
0789
0790
0791
0792
0793 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0794 set(hObject,'BackgroundColor','white');
0795 end
0796
0797
0798 function flag_opt_param_Callback(hObject, eventdata, handles)
0799
0800
0801
0802
0803
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
0827 guidata(hObject, handles);
0828
0829
0830 function edit_param_range_Callback(hObject, eventdata, handles)
0831
0832
0833
0834
0835
0836
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
0851 guidata(hObject, handles);
0852
0853
0854 function edit_param_range_CreateFcn(hObject, eventdata, handles)
0855
0856
0857
0858
0859
0860
0861 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0862 set(hObject,'BackgroundColor','white');
0863 end
0864
0865
0866
0867 function pop_cv_Callback(hObject, eventdata, handles)
0868
0869
0870
0871
0872
0873
0874
0875 val=get(handles.pop_cv,'Value');
0876 mach=get(handles.pop_cv,'String');
0877 handles.cv.k=0;
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'))
0894 handles.cv.type = 'loro';
0895 else
0896 handles.cv.type = 'custom';
0897
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
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
0956 guidata(hObject, handles);
0957
0958
0959 function pop_cv_CreateFcn(hObject, eventdata, handles)
0960
0961
0962
0963
0964
0965
0966 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0967 set(hObject,'BackgroundColor','white');
0968 end
0969
0970
0971 function uns_list_Callback(hObject, eventdata, handles)
0972
0973
0974
0975
0976
0977
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
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
1003 guidata(hObject, handles);
1004
1005
1006 function uns_list_CreateFcn(hObject, eventdata, handles)
1007
1008
1009
1010
1011
1012
1013 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1014 set(hObject,'BackgroundColor','white');
1015 end
1016
1017
1018
1019 function sel_list_Callback(hObject, eventdata, handles)
1020
1021
1022
1023
1024
1025
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
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
1051 guidata(hObject, handles);
1052
1053
1054 function sel_list_CreateFcn(hObject, eventdata, handles)
1055
1056
1057
1058
1059
1060
1061 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1062 set(hObject,'BackgroundColor','white');
1063 end
1064
1065
1066
1067
1068 function buildbutt_Callback(hObject, eventdata, handles)
1069
1070
1071
1072
1073
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
1082 fname=get(handles.edit_prt,'String');
1083 load(fname)
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
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
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
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
1178 function specbutt_Callback(hObject, eventdata, handles)
1179
1180
1181
1182
1183
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
1191 fname=get(handles.edit_prt,'String');
1192 load(fname)
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
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
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
1275 function pop_cv_nested_Callback(hObject, eventdata, handles)
1276
1277
1278
1279
1280
1281
1282 val=get(handles.pop_cv_nested,'Value');
1283 mach=get(handles.pop_cv_nested,'String');
1284 handles.cv.k_nested=0;
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'))
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
1312 guidata(hObject, handles);
1313
1314
1315 function pop_cv_nested_CreateFcn(hObject, eventdata, handles)
1316
1317
1318
1319
1320
1321
1322 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1323 set(hObject,'BackgroundColor','white');
1324 end