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

Generated on Mon 03-Sep-2012 18:07:18 by m2html © 2005