Question about TDT toolbox and SVM_weights

hi all,
I employed the TDT tool box to calculate the SVM_weights as following:

clear variables
if isempty(which(‘decoding.m’))
error(‘Please add TDT to the matlab path’)
end

clear cfg
data_path=‘K:\Risk’;
base_dir=‘K:\Risk’;
cfg = decoding_defaults;
cfg.plot_design = 0;
cfg.analysis = ‘roi’;
cfg.results.dir = fullfile(base_dir, ‘MVPA_weight’);% Specify where the results should be saved
cfg.files.mask = fullfile(base_dir,‘mask.nii’);
x1 = cellstr(spm_select(‘FPList’,[data_path,‘cer’],’^sub..nii’));
y1 = cellstr(spm_select(‘FPList’,[data_path,‘risk’],’^sub.
.nii’));
scan = [x1;y1];

cfg.files.name = scan;
cfg.files.label = [ones(133,1);-1*ones(133,1)];
cfg.files.chunk = [(1:133)’;(1:133)’];

cfg.scale.method = ‘z’;
cfg.scale.estimation = ‘all’;
cfg.scale.check_datatrans_ok = true;

cfg.results.overwrite = 1;
cfg.results.output = {‘accuracy’};

cfg.design = make_design_cv(cfg);

results = decoding(cfg);

cfg.results.output = {‘SVM_pattern’}; % if you really want the weights, use ‘SVM_weights’

cfg.design = make_design_alldata(cfg); % overwrite the existing design
cfg.design.nonindependence = ‘ok’; % set non-independence to be ok

results = decoding(cfg); % re-run decoding analysis

but the matlab report an error as following:

Error using warningv (line 70)
Error: The expression left of the equal sign is not a valid target for assignment.

Error transres_SVM_weights_plusbias (line 222)
warningv(‘transres_SVM_weights_plusbias:check_sign_libsvm_labels_1_-1’,
‘Please verify that the sign of the returned weights. libsvm returned labels 1
and -1. This is an exception from an exception. While in general libsvm flips
the sign of the weights (for an unkown reason) when the first passed label is
smaller than the second, for some reason that we dont know it does sort the
labels 1 and -1 in a different way and independent of the order the labels are
given to it, but it does not flip the weight, i.e. as if the first label were
smaller than the second (which it is not, 1 is not smaller than -1). No idea
if anyone knows why that is the case. The last version we checked that
exhibited that strange behaviour is libsvm3.17. If you use a different verion,
check the sign of the output’)

Error transres_SVM_weights (line 37)
output_plus_weights = transres_SVM_weights_plusbias(decoding_out, chancelevel, cfg, data);

Error transres_SVM_pattern (line 49)
w = transres_SVM_weights(decoding_out, chancelevel, cfg, data);

Error decoding_transform_results (line 260)
output = feval(fhandle,decoding_out,chancelevel,cfg,data);

Error decoding_generate_output (line 35)
output = decoding_transform_results(curr_output,decoding_out,chancelevel,cfg,data);

Error decoding (line 568)
results = decoding_generate_output(cfg,results,decoding_out,i_decoding,curr_decoding,current_data);

Error MVPA_weight (line 41)
results = decoding(cfg); % re-run decoding analysis

Hi Yanqing,

I think @Kai added a warning message at some point that is really really long. This cannot be coded as a field name for warningv, which then throws an error. I’ll ask Kai to fix this as soon as possible. In the meantime, navigate to transres_SVM_weights_plusbias.m and comment out the warning message.

Best,
Martin

Hi Yanqing,

Thanks for the bug report. I think the problem is not the length of the warning message, but that it contains a minus (-). So instead of commenting the line, you can replace the ‘-’ by e.g. ‘neg’ (for “negative”) in

Error transres_SVM_weights_plusbias (line 222)
warningv(‘transres_SVM_weights_plusbias:check_sign_libsvm_labels_1_-1’,
to
warningv(‘transres_SVM_weights_plusbias:check_sign_libsvm_labels_1_neg1’,

I just fixed this for future versions.

In addition, please

  1. check that the sign (i.e. the class assignments) of the output are correct and not inverted (which is what the warning message should warn you about)

  2. check if you really want the pattern (as in your current code)
    cfg.results.output = {‘SVM_pattern’}; % if you really want the weights, use ‘SVM_weights’
    or the weights, which would be
    cfg.results.output = {‘SVM_weights’};

See Haufe, Meinecke, Görgen et al for details.

Happy Decoding,
Kai

Thanks for your reply.

Hi Martin,
I’ve a suggestion, could you add more information about support vector regression analysis in template folder?