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
0270
0271
0272
0273
0274
0275
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
0286 reg_group.val = {gr_name, subj_nums};
0287
0288
0289
0290
0291 machine_func = cfg_files;
0292 machine_func.tag = 'machine_func';
0293 machine_func.name = 'Function';
0294 machine_func.ufilter = '^*.m';
0295 machine_func.num = [1 1];
0296 machine_func.help = {'Choose a function that will perform prediction.'};
0297
0298
0299
0300
0301 machine_args = cfg_entry;
0302 machine_args.tag = 'machine_args';
0303 machine_args.name = 'Arguments';
0304 machine_args.help = {['Arguments for prediction machine.']};
0305 machine_args.strtype = 's';
0306 machine_args.num = [1 Inf];
0307
0308
0309
0310
0311 custom_machine = cfg_branch;
0312 custom_machine.tag = 'custom_machine';
0313 custom_machine.name = 'Custom machine';
0314 custom_machine.help = {'Choose another prediction machine'};
0315 custom_machine.val = {machine_func, machine_args};
0316
0317
0318
0319
0320 svm_args = cfg_entry;
0321 svm_args.tag = 'svm_args';
0322 svm_args.name = 'Arguments';
0323 svm_args.help = {['Arguments for prt_machine_svm_bin. You should use '...
0324 '-t 4 if you selected ''use kernels'' option, and ' ...
0325 '-t 0 otherwise. See libSVM documentation for details.']};
0326 svm_args.strtype = 's';
0327 svm_args.val = {'-s 0 -t 4 -c 1'};
0328 svm_args.num = [1 Inf];
0329
0330
0331
0332
0333 svm = cfg_branch;
0334 svm.tag = 'svm';
0335 svm.name = 'SVM Classification';
0336 svm.help = {'Binary support vector machine.'};
0337 svm.val = {svm_args};
0338
0339
0340
0341
0342 gpc_args = cfg_entry;
0343 gpc_args.tag = 'gpc_args';
0344 gpc_args.name = 'Arguments';
0345 gpc_args.help = {['Arguments for prt_machine_gpml']};
0346 gpc_args.strtype = 's';
0347 gpc_args.val = {def.model.gpcargs};
0348 gpc_args.num = [1 Inf];
0349
0350
0351
0352
0353 gpc = cfg_branch;
0354 gpc.tag = 'gpc';
0355 gpc.name = 'Gaussian Process Classification';
0356 gpc.help = {'Gaussian Process Classification'};
0357 gpc.val = {gpc_args};
0358
0359
0360
0361
0362 gpclap_args = cfg_entry;
0363 gpclap_args.tag = 'gpclap_args';
0364 gpclap_args.name = 'Arguments';
0365 gpclap_args.help = {['Arguments for prt_machine_gpclap']};
0366 gpclap_args.strtype = 's';
0367 gpclap_args.val = {def.model.gpclapargs};
0368 gpclap_args.num = [1 Inf];
0369
0370
0371
0372
0373 gpclap = cfg_branch;
0374 gpclap.tag = 'gpclap';
0375 gpclap.name = 'Multiclass GPC';
0376 gpclap.help = {'Multiclass GPC'};
0377 gpclap.val = {gpclap_args};
0378
0379
0380
0381
0382 gpr_args = cfg_entry;
0383 gpr_args.tag = 'gpr_args';
0384 gpr_args.name = 'Arguments';
0385 gpr_args.help = {['Arguments for prt_machine_gpr']};
0386 gpr_args.strtype = 's';
0387 gpr_args.val = {def.model.gprargs};
0388 gpr_args.num = [1 Inf];
0389
0390
0391
0392
0393 gpr = cfg_branch;
0394 gpr.tag = 'gpr';
0395 gpr.name = 'Gaussian Process Regression';
0396 gpr.help = {'Gaussian Process Regression'};
0397 gpr.val = {gpr_args};
0398
0399
0400
0401
0402 krr_args = cfg_entry;
0403 krr_args.tag = 'krr_args';
0404 krr_args.name = 'Regularization';
0405 krr_args.help = {['Regularization for prt_machine_krr.']};
0406 krr_args.strtype = 'e';
0407 krr_args.val = {1};
0408 krr_args.num = [1 Inf];
0409
0410
0411
0412
0413 krr = cfg_branch;
0414 krr.tag = 'krr';
0415 krr.name = 'Kernel Ridge Regression';
0416 krr.help = {'Kernel Ridge Regression.'};
0417 krr.val = {krr_args};
0418
0419
0420
0421
0422 rvr = cfg_branch;
0423 rvr.tag = 'rvr';
0424 rvr.name = 'Relevance Vector Regression';
0425 rvr.help = {'Relevance Vector Regression. Tipping, Michael E.; Smola, Alex (2001).' ...
0426 '"Sparse Bayesian Learning and the Relevance Vector Machine". Journal of Machine Learning Research 1: 211?244.'};
0427
0428
0429
0430
0431 rt_args = cfg_entry;
0432 rt_args.tag = 'rt_args';
0433 rt_args.name = 'Ntrees';
0434 rt_args.help = {['Number of trees in the forest.']};
0435 rt_args.strtype = 'e';
0436 rt_args.val = {601};
0437 rt_args.num = [1 1];
0438
0439
0440
0441
0442 rt = cfg_branch;
0443 rt.tag = 'rt';
0444 rt.name = 'Random Forest';
0445 rt.help = {'Random Forest. Breiman, Leo (2001)."Random Forests". ' ...
0446 'Machine Learning 45:5-32. This is a wrapper around ' ...
0447 'Peter Geurt''s implementation in his Regression Tree ' ...
0448 ' package.' };
0449 rt.val = {rt_args};
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465 machine_cl = cfg_choice;
0466 machine_cl.tag = 'machine_cl';
0467 machine_cl.name = 'Machine';
0468 machine_cl.values = {svm,gpc,gpclap,rt,custom_machine};
0469 machine_cl.val = {svm};
0470 machine_cl.help = {...
0471 ['Choose a prediction machine for this model']};
0472
0473
0474
0475
0476 machine_rg = cfg_choice;
0477 machine_rg.tag = 'machine_rg';
0478 machine_rg.name = 'Machine';
0479 machine_rg.values = {krr,rvr,gpr,custom_machine};
0480 machine_rg.val = {krr};
0481 machine_rg.help = {...
0482 ['Choose a prediction machine for this model']};
0483
0484
0485
0486
0487 reggroups = cfg_repeat;
0488 reggroups.tag = 'reggroups';
0489 reggroups.name = 'Groups';
0490 reggroups.help = {['Add one group to this regression model. Click ''new'' '...
0491 'or ''repeat'' to add another group.']};
0492 reggroups.num = [1 Inf];
0493 reggroups.values = {reg_group};
0494
0495
0496
0497
0498 regression = cfg_branch;
0499 regression.tag = 'regression';
0500 regression.name = 'Regression';
0501 regression.help = {'Add group data and machine for regression.'};
0502 regression.val = {reggroups, machine_rg};
0503
0504
0505
0506
0507 classes = cfg_repeat;
0508 classes.tag = 'classes';
0509 classes.name = 'Classes';
0510 classes.help = {['Specify which elements belong to this class. Click ''new'' '...
0511 'or ''repeat'' to add another class.']};
0512 classes.num = [1 Inf];
0513 classes.values = {class};
0514
0515
0516
0517
0518 classification = cfg_branch;
0519 classification.tag = 'classification';
0520 classification.name = 'Classification';
0521 classification.help = {'Specify classes and machine for classification.'};
0522 classification.val = {classes, machine_cl};
0523
0524
0525
0526
0527 model_type = cfg_choice;
0528 model_type.tag = 'model_type';
0529 model_type.name = 'Model Type ';
0530 model_type.values = {classification, regression};
0531 model_type.help = {'Select which kind of predictive model is to be used.'};
0532
0533
0534
0535
0536 cv_loso = cfg_const;
0537 cv_loso.tag = 'cv_loso';
0538 cv_loso.name = 'Leave one subject out';
0539 cv_loso.val = {1};
0540 cv_loso.help = {'Leave a single subject out each cross-validation iteration'};
0541
0542
0543
0544
0545 cv_losgo = cfg_const;
0546 cv_losgo.tag = 'cv_losgo';
0547 cv_losgo.name = 'Leave one subject per group out';
0548 cv_losgo.val = {1};
0549 cv_losgo.help = {...
0550 ['Leave out a single subject from each group at a time. ', ...
0551 'Appropriate for repeated measures or paired samples designs.']};
0552
0553
0554
0555
0556 cv_lobo = cfg_const;
0557 cv_lobo.tag = 'cv_lobo';
0558 cv_lobo.name = 'Leave one block out';
0559 cv_lobo.val = {1};
0560 cv_lobo.help = {...
0561 ['Leave out a single block or event from each subject each iteration. ', ...
0562 'Appropriate for single subject designs.']};
0563
0564
0565
0566
0567
0568 cv_loro = cfg_const;
0569 cv_loro.tag = 'cv_loro';
0570 cv_loro.name = 'Leave one run/session out';
0571 cv_loro.val = {1};
0572 cv_loro.help = {...
0573 ['Leave out a single run (modality) from each subject each iteration. ', ...
0574 'Appropriate for single subject designs with multiple runs/sessions.']};
0575
0576
0577
0578
0579 cv_custom = cfg_files;
0580 cv_custom.tag = 'cv_custom';
0581 cv_custom.name = 'Custom';
0582 cv_custom.filter = 'mat';
0583 cv_custom.ufilter = '.*';
0584 cv_custom.num = [1 1];
0585 cv_custom.help = {...
0586 ['Load a cross-validation matrix. Note that an interface ',...
0587 'will be provided for this functionality in a later release']};
0588
0589
0590
0591
0592 cv_type = cfg_choice;
0593 cv_type.tag = 'cv_type';
0594 cv_type.name = 'Cross-validation type';
0595 cv_type.values = {cv_loso, cv_losgo, cv_lobo, cv_loro,cv_custom};
0596 cv_type.val = {cv_loso};
0597 cv_type.help = {'Choose the type of cross-validation to be used'};
0598
0599
0600
0601
0602 include_allscans = cfg_menu;
0603 include_allscans.tag = 'include_allscans';
0604 include_allscans.name = 'Include all scans';
0605 include_allscans.labels = {
0606 'Yes'
0607 'No'
0608 }';
0609 include_allscans.values = {1 0};
0610 include_allscans.val = {0};
0611 include_allscans.help = {[...
0612 'This option can be used to pass all the scans for each subject to ',...
0613 'the learning machine, regardless of whether they are directly ',...
0614 'involved in the classification or regression problem. For example, ',...
0615 'this can be used to estimate a GLM from the whole timeseries ',...
0616 'for each subject prior to prediction. This would allow the resulting ',...
0617 'regression coefficient images to be used as samples.']};
0618
0619
0620
0621
0622 no_op = cfg_const;
0623 no_op.tag = 'no_op';
0624 no_op.name = 'No operations';
0625 no_op.val = {1};
0626 no_op.help = {['No design specified. This option can be used '...
0627 'for modalities (e.g. structural scans) that do not '...
0628 'have an experimental design or for an fMRI design',...
0629 'where you want to include all scans in the timeseries']};
0630
0631
0632
0633
0634 data_op = cfg_menu;
0635 data_op.tag = 'data_op';
0636 data_op.name = 'Operation';
0637 data_op.help = {'Select an operation to apply.'};
0638 data_op.labels = {
0639 'Done'
0640 'Sample averaging (within block)'
0641 'Sample averaging (within subject/condition)'
0642 'Mean centre features using training data'
0643 'Divide data vectors by their norm'
0644 'Perform a GLM (fMRI only)'
0645 }';
0646 data_op.values = {0 1 2 3 4 5};
0647 data_op.val = {0};
0648
0649
0650
0651
0652 data_op_mc = cfg_menu;
0653 data_op_mc.tag = 'data_op_mc';
0654 data_op_mc.name = 'Mean centre features';
0655 data_op_mc.help = {'Select an operation to apply.'};
0656 data_op_mc.labels = {
0657 'Yes'
0658 'No'
0659 }';
0660 data_op_mc.values = {0 1};
0661 data_op_mc.val = {0};
0662
0663
0664
0665
0666 other_ops = cfg_repeat;
0667 other_ops.tag = 'other_ops';
0668 other_ops.name = 'Select Operations';
0669 other_ops.help = {...
0670 ['Add zero or more operations to be applied to the data before the ',...
0671 'prediction machine is called. These are executed within the ',...
0672 'cross-validation loop (i.e. they respect training/test independence) ',...
0673 'and will be executed in the order specified. ']};
0674 other_ops.num = [1 Inf];
0675 other_ops.values = {data_op};
0676
0677
0678
0679
0680 use_other_ops = cfg_choice;
0681 use_other_ops.tag = 'use_other_ops';
0682 use_other_ops.name = 'Other Operations';
0683 use_other_ops.values = {no_op, other_ops };
0684 use_other_ops.val = {no_op};
0685 use_other_ops.help = {'Include other operations?'};
0686
0687
0688
0689
0690 sel_ops = cfg_branch;
0691 sel_ops.tag = 'sel_ops';
0692 sel_ops.name = 'Data operations';
0693 sel_ops.help = {...
0694 ['Specify operations to apply']};
0695 sel_ops.val = {data_op_mc use_other_ops};
0696
0697
0698
0699
0700
0701 data_ops = cfg_choice;
0702 data_ops.tag = 'data_ops';
0703 data_ops.name = 'Data Operations';
0704 data_ops.values = {data_op_mc, sel_ops};
0705 data_ops.val = {no_op};
0706 data_ops.help = {...
0707 ['This branch controls operations that can be applied to the data ',...
0708 'before the data is passed to the classifier. Add zero or more ',...
0709 'operations to be applied. These will be executed in the order ',...
0710 'specified. ']};
0711
0712
0713
0714
0715 model = cfg_exbranch;
0716 model.tag = 'model';
0717 model.name = 'Specify model';
0718 model.val = {infile, ...
0719 model_name, ...
0720 use_kernel, ...
0721 fsets, ...
0722 model_type, ...
0723 cv_type,...
0724 include_allscans,...
0725 sel_ops};
0726 model.help = {'Construct model according to design specified'};
0727 model.prog = @prt_run_model;
0728 model.vout = @vout_data;
0729
0730
0731
0732
0733 function cdep = vout_data(job)
0734
0735
0736 cdep(1) = cfg_dep;
0737 cdep(1).sname = 'PRT.mat file';
0738 cdep(1).src_output = substruct('.','files');
0739 cdep(1).tgt_spec = cfg_findspec({{'filter','mat','strtype','e'}});
0740
0741