0001 function model = prt_cfg_model
0002
0003
0004
0005
0006
0007
0008
0009
0010 def = prt_get_defaults;
0011
0012
0013
0014
0015 infile = cfg_files;
0016 infile.tag = 'infile';
0017 infile.name = 'Load PRT.mat';
0018 infile.ufilter = 'PRT.mat';
0019 infile.num = [1 1];
0020 infile.help = {'Select data/design structure file (PRT.mat).'};
0021
0022
0023
0024
0025 model_name = cfg_entry;
0026 model_name.tag = 'model_name';
0027 model_name.name = 'Model name';
0028 model_name.help = {'Name for model'};
0029 model_name.strtype = 's';
0030 model_name.num = [1 Inf];
0031
0032
0033
0034
0035 use_kernel = cfg_menu;
0036 use_kernel.tag = 'use_kernel';
0037 use_kernel.name = 'Use kernels';
0038 use_kernel.help = {...
0039 ['Are the data for this model in the form of kernels/basis functions? ', ...
0040 'If ''No'' is selected, it is assumed the data are in the form of ',...
0041 'feature matrices']};
0042 use_kernel.labels = {
0043 'Yes'
0044 'No'
0045 }';
0046 use_kernel.values = {1 0};
0047 use_kernel.val = {1};
0048
0049
0050
0051
0052 all_features = cfg_const;
0053 all_features.tag = 'all_features';
0054 all_features.name = 'All Features';
0055 all_features.val = {1};
0056 all_features.help = {...
0057 'Include all features from all modalities in this feature set'};
0058
0059
0060
0061
0062 fs_name = cfg_entry;
0063 fs_name.tag = 'fs_name';
0064 fs_name.name = 'Name';
0065 fs_name.help = {'Name of a feature set. Must match design specification'};
0066 fs_name.strtype = 's';
0067 fs_name.num = [1 Inf];
0068
0069
0070
0071
0072 mod_name = cfg_entry;
0073 mod_name.tag = 'mod_name';
0074 mod_name.name = 'Modality name';
0075 mod_name.help = {'Name of modality. Example: ''BOLD''. Must match design specification'};
0076 mod_name.strtype = 's';
0077 mod_name.num = [1 Inf];
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 fsets = cfg_entry;
0092 fsets.tag = 'fsets';
0093 fsets.name = 'Feature sets';
0094 fsets.help = {['Enter the name of a feature set to include in this model. ',...
0095 'This can be kernel or a feature matrix. ', ...
0096 ]};
0097 fsets.num = [1 Inf];
0098
0099 fsets.strtype = 's';
0100
0101
0102
0103
0104
0105 gr_name = cfg_entry;
0106 gr_name.tag = 'gr_name';
0107 gr_name.name = 'Group name';
0108 gr_name.help = {'Name of the group to include. Must exist in PRT.mat'};
0109 gr_name.strtype = 's';
0110 gr_name.num = [1 Inf];
0111
0112
0113
0114
0115 all_cond = cfg_const;
0116 all_cond.tag = 'all_cond';
0117 all_cond.name = 'All Conditions';
0118 all_cond.val = {1};
0119 all_cond.help = {'Include all conditions in this model'};
0120
0121
0122
0123
0124 cond_name = cfg_entry;
0125 cond_name.tag = 'cond_name';
0126 cond_name.name = 'Name';
0127 cond_name.help = {'Name of condition to include.'};
0128 cond_name.strtype = 's';
0129 cond_name.num = [1 Inf];
0130
0131
0132
0133
0134 conds = cfg_branch;
0135 conds.tag = 'conds';
0136 conds.name = 'Condition';
0137 conds.help = {'Specify condition:.'};
0138 conds.val = {cond_name};
0139
0140
0141
0142
0143 sel_cond = cfg_repeat;
0144 sel_cond.tag = 'sel_cond';
0145 sel_cond.name = 'Specify Conditions';
0146 sel_cond.help = {'Specify the name of conditions to be included '};
0147 sel_cond.values = {conds};
0148
0149
0150
0151
0152 all_scans = cfg_const;
0153 all_scans.tag = 'all_scans';
0154 all_scans.name = 'All scans';
0155 all_scans.val = {1};
0156 all_scans.help = {['No design specified. This option can be used '...
0157 'for modalities (e.g. structural scans) that do not '...
0158 'have an experimental design or for an fMRI design',...
0159 'where you want to include all scans in the timeseries']};
0160
0161
0162
0163
0164 conditions = cfg_choice;
0165 conditions.tag = 'conditions';
0166 conditions.name = 'Conditions / Scans';
0167 conditions.values = {sel_cond, all_cond, all_scans};
0168 conditions.help = {...
0169 ['Which task conditions do you want to include? '...
0170 'Select conditions: select specific conditions from the timeseries. ', ...
0171 'All conditions: include all conditions extracted from the timeseries. ', ...
0172 'All scans: include all scans for each subject. This may be used for ', ...
0173 'modalities with only one scan per subject (e.g. PET), ', ...
0174 'if you want to include all scans from an fMRI timeseries (assumes you ',...
0175 'have not already detrended the timeseries and extracted task components)']};
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205 subj_nums = cfg_entry;
0206 subj_nums.tag = 'subj_nums';
0207 subj_nums.name = 'Subjects';
0208 subj_nums.help = {
0209 ['Subject numbers to be included in this class. Note that individual ',...
0210 'numbers (e.g. 1), or a range of numbers ',...
0211 '(e.g. 3:5) can be entered'] };
0212 subj_nums.strtype = 'e';
0213 subj_nums.num = [Inf 1];
0214
0215
0216
0217
0218 group = cfg_branch;
0219 group.tag = 'group';
0220 group.name = 'Group';
0221 group.help = {'Specify data and design for the group.'};
0222 group.val = {gr_name, subj_nums, conditions};
0223
0224
0225
0226
0227 class_name = cfg_entry;
0228 class_name.tag = 'class_name';
0229 class_name.name = 'Name';
0230 class_name.help = {'Name for this class, e.g. ''controls'' '};
0231 class_name.strtype = 's';
0232 class_name.num = [1 Inf];
0233
0234
0235
0236
0237 groups = cfg_repeat;
0238 groups.tag = 'groups';
0239 groups.name = 'Groups';
0240 groups.help = {['Add one group to this class. Click ''new'' '...
0241 'or ''repeat'' to add another group.']};
0242 groups.num = [1 Inf];
0243 groups.values = {group};
0244
0245
0246
0247
0248 class = cfg_branch;
0249 class.tag = 'class';
0250 class.name = 'Class';
0251 class.help = {...
0252 ['Specify which groups, modalities, subjects and conditions should ',...
0253 'be included in this class']};
0254 class.val = {class_name, groups};
0255
0256
0257
0258
0259 reg_targets = cfg_entry;
0260 reg_targets.tag = 'reg_targets';
0261 reg_targets.name = 'Regression targets';
0262 reg_targets.help = {['Specify continuous valued target variables']};
0263 reg_targets.strtype = 'e';
0264 reg_targets.num = [Inf 1];
0265
0266
0267
0268
0269 mod_name2 = cfg_entry;
0270 mod_name2.tag = 'mod_name2';
0271 mod_name2.name = 'Modality name';
0272 mod_name2.help = {'Name of modality. We only allow one modality for regression model per group at this moment' ...
0273 'Example: ''BOLD''. Must match design specification'};
0274 mod_name2.strtype = 's';
0275 mod_name2.num = [1 Inf];
0276
0277
0278
0279
0280 reg_group = cfg_branch;
0281 reg_group.tag = 'reg_group';
0282 reg_group.name = 'Group';
0283 reg_group.help = {'Specify data and design for the group.'};
0284
0285 reg_group.val = {gr_name, subj_nums,mod_name2 };
0286
0287
0288
0289
0290 machine_func = cfg_files;
0291 machine_func.tag = 'machine_func';
0292 machine_func.name = 'Function';
0293 machine_func.ufilter = '^*.m';
0294 machine_func.num = [1 1];
0295 machine_func.help = {'Choose a function that will perform prediction.'};
0296
0297
0298
0299
0300 machine_args = cfg_entry;
0301 machine_args.tag = 'machine_args';
0302 machine_args.name = 'Arguments';
0303 machine_args.help = {['Arguments for prediction machine.']};
0304 machine_args.strtype = 's';
0305 machine_args.num = [1 Inf];
0306
0307
0308
0309
0310 custom_machine = cfg_branch;
0311 custom_machine.tag = 'custom_machine';
0312 custom_machine.name = 'Custom machine';
0313 custom_machine.help = {'Choose another prediction machine'};
0314 custom_machine.val = {machine_func, machine_args};
0315
0316
0317
0318
0319 svm_args = cfg_entry;
0320 svm_args.tag = 'svm_args';
0321 svm_args.name = 'Arguments';
0322 svm_args.help = {['Arguments for prt_machine_svm_bin. You should use '...
0323 '-t 4 if you selected ''use kernels'' option, and ' ...
0324 '-t 0 otherwise. See libSVM documentation for details.']};
0325 svm_args.strtype = 's';
0326 svm_args.val = {'-s 0 -t 4 -c 1'};
0327 svm_args.num = [1 Inf];
0328
0329
0330
0331
0332 svm = cfg_branch;
0333 svm.tag = 'svm';
0334 svm.name = 'SVM Classification';
0335 svm.help = {'Binary support vector machine.'};
0336 svm.val = {svm_args};
0337
0338
0339
0340
0341 gpc_args = cfg_entry;
0342 gpc_args.tag = 'gpc_args';
0343 gpc_args.name = 'Arguments';
0344 gpc_args.help = {['Arguments for prt_machine_gpml']};
0345 gpc_args.strtype = 's';
0346 gpc_args.val = {def.model.gpcargs};
0347 gpc_args.num = [1 Inf];
0348
0349
0350
0351
0352 gpc = cfg_branch;
0353 gpc.tag = 'gpc';
0354 gpc.name = 'Gaussian Process Classification';
0355 gpc.help = {'Gaussian Process Classification'};
0356 gpc.val = {gpc_args};
0357
0358
0359
0360
0361 gpclap_args = cfg_entry;
0362 gpclap_args.tag = 'gpclap_args';
0363 gpclap_args.name = 'Arguments';
0364 gpclap_args.help = {['Arguments for prt_machine_gpclap']};
0365 gpclap_args.strtype = 's';
0366 gpclap_args.val = {def.model.gpclapargs};
0367 gpclap_args.num = [1 Inf];
0368
0369
0370
0371
0372 gpclap = cfg_branch;
0373 gpclap.tag = 'gpclap';
0374 gpclap.name = 'Multiclass GPC';
0375 gpclap.help = {'Multiclass GPC'};
0376 gpclap.val = {gpclap_args};
0377
0378
0379
0380
0381 gpr_args = cfg_entry;
0382 gpr_args.tag = 'gpr_args';
0383 gpr_args.name = 'Arguments';
0384 gpr_args.help = {['Arguments for prt_machine_gpr']};
0385 gpr_args.strtype = 's';
0386 gpr_args.val = {def.model.gprargs};
0387 gpr_args.num = [1 Inf];
0388
0389
0390
0391
0392 gpr = cfg_branch;
0393 gpr.tag = 'gpr';
0394 gpr.name = 'Gaussian Process Regression';
0395 gpr.help = {'Gaussian Process Regression'};
0396 gpr.val = {gpr_args};
0397
0398
0399
0400
0401 krr_args = cfg_entry;
0402 krr_args.tag = 'krr_args';
0403 krr_args.name = 'Regularization';
0404 krr_args.help = {['Regularization for prt_machine_krr.']};
0405 krr_args.strtype = 'e';
0406 krr_args.val = {1};
0407 krr_args.num = [1 Inf];
0408
0409
0410
0411
0412 krr = cfg_branch;
0413 krr.tag = 'krr';
0414 krr.name = 'Kernel Ridge Regression';
0415 krr.help = {'Kernel Ridge Regression.'};
0416 krr.val = {krr_args};
0417
0418
0419
0420
0421 rvr = cfg_branch;
0422 rvr.tag = 'rvr';
0423 rvr.name = 'Relevance Vector Regression';
0424 rvr.help = {'Relevance Vector Regression. Tipping, Michael E.; Smola, Alex (2001).' ...
0425 '"Sparse Bayesian Learning and the Relevance Vector Machine". Journal of Machine Learning Research 1: 211?244.'};
0426
0427
0428
0429
0430 rt_args = cfg_entry;
0431 rt_args.tag = 'rt_args';
0432 rt_args.name = 'Ntrees';
0433 rt_args.help = {['Number of trees in the forest.']};
0434 rt_args.strtype = 'e';
0435 rt_args.val = {601};
0436 rt_args.num = [1 1];
0437
0438
0439
0440
0441 rt = cfg_branch;
0442 rt.tag = 'rt';
0443 rt.name = 'Random Forest';
0444 rt.help = {'Random Forest. Breiman, Leo (2001)."Random Forests". ' ...
0445 'Machine Learning 45:5-32. This is a wrapper around ' ...
0446 'Peter Geurt''s implementation in his Regression Tree ' ...
0447 ' package.' };
0448 rt.val = {rt_args};
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464 machine_cl = cfg_choice;
0465 machine_cl.tag = 'machine_cl';
0466 machine_cl.name = 'Machine';
0467 machine_cl.values = {svm,gpc,gpclap,rt,custom_machine};
0468 machine_cl.val = {svm};
0469 machine_cl.help = {...
0470 ['Choose a prediction machine for this model']};
0471
0472
0473
0474
0475 machine_rg = cfg_choice;
0476 machine_rg.tag = 'machine_rg';
0477 machine_rg.name = 'Machine';
0478 machine_rg.values = {krr,rvr,gpr,custom_machine};
0479 machine_rg.val = {krr};
0480 machine_rg.help = {...
0481 ['Choose a prediction machine for this model']};
0482
0483
0484
0485
0486 reggroups = cfg_repeat;
0487 reggroups.tag = 'reggroups';
0488 reggroups.name = 'Groups';
0489 reggroups.help = {['Add one group to this regression model. Click ''new'' '...
0490 'or ''repeat'' to add another group.']};
0491 reggroups.num = [1 Inf];
0492 reggroups.values = {reg_group};
0493
0494
0495
0496
0497 regression = cfg_branch;
0498 regression.tag = 'regression';
0499 regression.name = 'Regression';
0500 regression.help = {'Add group data and machine for regression.'};
0501 regression.val = {reggroups, machine_rg};
0502
0503
0504
0505
0506 classes = cfg_repeat;
0507 classes.tag = 'classes';
0508 classes.name = 'Classes';
0509 classes.help = {['Specify which elements belong to this class. Click ''new'' '...
0510 'or ''repeat'' to add another class.']};
0511 classes.num = [1 Inf];
0512 classes.values = {class};
0513
0514
0515
0516
0517 classification = cfg_branch;
0518 classification.tag = 'classification';
0519 classification.name = 'Classification';
0520 classification.help = {'Specify classes and machine for classification.'};
0521 classification.val = {classes, machine_cl};
0522
0523
0524
0525
0526 model_type = cfg_choice;
0527 model_type.tag = 'model_type';
0528 model_type.name = 'Model Type ';
0529 model_type.values = {classification, regression};
0530 model_type.help = {'Select which kind of predictive model is to be used.'};
0531
0532
0533
0534
0535 cv_loso = cfg_const;
0536 cv_loso.tag = 'cv_loso';
0537 cv_loso.name = 'Leave one subject out';
0538 cv_loso.val = {1};
0539 cv_loso.help = {'Leave a single subject out each cross-validation iteration'};
0540
0541
0542
0543
0544 cv_losgo = cfg_const;
0545 cv_losgo.tag = 'cv_losgo';
0546 cv_losgo.name = 'Leave one subject per group out';
0547 cv_losgo.val = {1};
0548 cv_losgo.help = {...
0549 ['Leave out a single subject from each group at a time. ', ...
0550 'Appropriate for repeated measures or paired samples designs.']};
0551
0552
0553
0554
0555 cv_lobo = cfg_const;
0556 cv_lobo.tag = 'cv_lobo';
0557 cv_lobo.name = 'Leave one block out';
0558 cv_lobo.val = {1};
0559 cv_lobo.help = {...
0560 ['Leave out a single block or event from each subject each iteration. ', ...
0561 'Appropriate for single subject designs.']};
0562
0563
0564
0565
0566
0567 cv_loro = cfg_const;
0568 cv_loro.tag = 'cv_loro';
0569 cv_loro.name = 'Leave one run/session out';
0570 cv_loro.val = {1};
0571 cv_loro.help = {...
0572 ['Leave out a single run (modality) from each subject each iteration. ', ...
0573 'Appropriate for single subject designs with multiple runs/sessions.']};
0574
0575
0576
0577
0578 cv_custom = cfg_files;
0579 cv_custom.tag = 'cv_custom';
0580 cv_custom.name = 'Custom';
0581 cv_custom.filter = 'mat';
0582 cv_custom.ufilter = '.*';
0583 cv_custom.num = [1 1];
0584 cv_custom.help = {...
0585 ['Load a cross-validation matrix. Note that an interface ',...
0586 'will be provided for this functionality in a later release']};
0587
0588
0589
0590
0591 cv_type = cfg_choice;
0592 cv_type.tag = 'cv_type';
0593 cv_type.name = 'Cross-validation type';
0594 cv_type.values = {cv_loso, cv_losgo, cv_lobo, cv_loro,cv_custom};
0595 cv_type.val = {cv_loso};
0596 cv_type.help = {'Choose the type of cross-validation to be used'};
0597
0598
0599
0600
0601 include_allscans = cfg_menu;
0602 include_allscans.tag = 'include_allscans';
0603 include_allscans.name = 'Include all scans';
0604 include_allscans.labels = {
0605 'Yes'
0606 'No'
0607 }';
0608 include_allscans.values = {1 0};
0609 include_allscans.val = {0};
0610 include_allscans.help = {[...
0611 'This option can be used to pass all the scans for each subject to ',...
0612 'the learning machine, regardless of whether they are directly ',...
0613 'involved in the classification or regression problem. For example, ',...
0614 'this can be used to estimate a GLM from the whole timeseries ',...
0615 'for each subject prior to prediction. This would allow the resulting ',...
0616 'regression coefficient images to be used as samples.']};
0617
0618
0619
0620
0621 no_op = cfg_const;
0622 no_op.tag = 'no_op';
0623 no_op.name = 'No operations';
0624 no_op.val = {1};
0625 no_op.help = {['No design specified. This option can be used '...
0626 'for modalities (e.g. structural scans) that do not '...
0627 'have an experimental design or for an fMRI design',...
0628 'where you want to include all scans in the timeseries']};
0629
0630
0631
0632
0633 data_op = cfg_menu;
0634 data_op.tag = 'data_op';
0635 data_op.name = 'Operation';
0636 data_op.help = {'Select an operation to apply.'};
0637 data_op.labels = {
0638 'Done'
0639 'Sample averaging (within block)'
0640 'Sample averaging (within subject/condition)'
0641 'Mean centre features using training data'
0642 'Divide data vectors by their norm'
0643 'Perform a GLM (fMRI only)'
0644 }';
0645 data_op.values = {0 1 2 3 4 5};
0646 data_op.val = {0};
0647
0648
0649
0650
0651 data_op_mc = cfg_menu;
0652 data_op_mc.tag = 'data_op_mc';
0653 data_op_mc.name = 'Mean centre features';
0654 data_op_mc.help = {'Select an operation to apply.'};
0655 data_op_mc.labels = {
0656 'Yes'
0657 'No'
0658 }';
0659 data_op_mc.values = {0 1};
0660 data_op_mc.val = {0};
0661
0662
0663
0664
0665 other_ops = cfg_repeat;
0666 other_ops.tag = 'other_ops';
0667 other_ops.name = 'Select Operations';
0668 other_ops.help = {...
0669 ['Add zero or more operations to be applied to the data before the ',...
0670 'prediction machine is called. These are executed within the ',...
0671 'cross-validation loop (i.e. they respect training/test independence) ',...
0672 'and will be executed in the order specified. ']};
0673 other_ops.num = [1 Inf];
0674 other_ops.values = {data_op};
0675
0676
0677
0678
0679 use_other_ops = cfg_choice;
0680 use_other_ops.tag = 'use_other_ops';
0681 use_other_ops.name = 'Other Operations';
0682 use_other_ops.values = {no_op, other_ops };
0683 use_other_ops.val = {no_op};
0684 use_other_ops.help = {'Include other operations?'};
0685
0686
0687
0688
0689 sel_ops = cfg_branch;
0690 sel_ops.tag = 'sel_ops';
0691 sel_ops.name = 'Data operations';
0692 sel_ops.help = {...
0693 ['Specify operations to apply']};
0694 sel_ops.val = {data_op_mc use_other_ops};
0695
0696
0697
0698
0699
0700 data_ops = cfg_choice;
0701 data_ops.tag = 'data_ops';
0702 data_ops.name = 'Data Operations';
0703 data_ops.values = {data_op_mc, sel_ops};
0704 data_ops.val = {no_op};
0705 data_ops.help = {...
0706 ['This branch controls operations that can be applied to the data ',...
0707 'before the data is passed to the classifier. Add zero or more ',...
0708 'operations to be applied. These will be executed in the order ',...
0709 'specified. ']};
0710
0711
0712
0713
0714 model = cfg_exbranch;
0715 model.tag = 'model';
0716 model.name = 'Specify model';
0717 model.val = {infile, ...
0718 model_name, ...
0719 use_kernel, ...
0720 fsets, ...
0721 model_type, ...
0722 cv_type,...
0723 include_allscans,...
0724 sel_ops};
0725 model.help = {'Construct model according to design specified'};
0726 model.prog = @prt_run_model;
0727 model.vout = @vout_data;
0728
0729
0730
0731
0732 function cdep = vout_data(job)
0733
0734
0735 cdep(1) = cfg_dep;
0736 cdep(1).sname = 'PRT.mat file';
0737 cdep(1).src_output = substruct('.','files');
0738 cdep(1).tgt_spec = cfg_findspec({{'filter','mat','strtype','e'}});
0739
0740