Skip to content

Commit

Permalink
inverse solutions - add checks in hasfilter (fieldtrip#2233)
Browse files Browse the repository at this point in the history
* add checks in hasfilter

- added check that the user did not specify leadfield options in case the input already contains the leadfield
- added check that the user did not specify inverse solution parameters in case the input already contains the filter
  • Loading branch information
mcpiastra authored Nov 16, 2024
1 parent 6ca8c97 commit 55a158a
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions inverse/ft_inverse_dics.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,15 @@
end

if hasfilter
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
% check that the options for the inversion are not specified
assert(all(cellfun(@isempty, invopt(2:2:end))), 'the options for computing the inverse solution must all be empty/default');
ft_info('using precomputed filters\n');
sourcemodel.filter = sourcemodel.filter(originside);
elseif hasleadfield
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
ft_info('using precomputed leadfields\n');
sourcemodel.leadfield = sourcemodel.leadfield(originside);
else
Expand Down
8 changes: 8 additions & 0 deletions inverse/ft_inverse_harmony.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,17 @@
end

if hasfilter
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
% check that inverse options are not specified
assert(isempty(noisecov), 'the options for computing the iverse must all be empty/default');
assert(isempty(lambda), 'the options for computing the inverse must all be empty/default');
assert(isempty(noiselambda), 'the options for computing the inverse must all be empty/default');
ft_info('using precomputed filters\n');
sourcemodel.filter = sourcemodel.filter(originside);
elseif hasleadfield
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
ft_info('using precomputed leadfields\n');
sourcemodel.leadfield = sourcemodel.leadfield(originside);
else
Expand Down
6 changes: 6 additions & 0 deletions inverse/ft_inverse_lcmv.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,15 @@
end

if hasfilter
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
% check that the options for the inversion are not specified
assert(all(cellfun(@isempty, invopt(2:2:end))), 'the options for computing the inverse solution must all be empty/default');
ft_info('using precomputed filters\n');
sourcemodel.filter = sourcemodel.filter(originside);
elseif hasleadfield
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
ft_info('using precomputed leadfields\n');
sourcemodel.leadfield = sourcemodel.leadfield(originside);
else
Expand Down
9 changes: 9 additions & 0 deletions inverse/ft_inverse_mne.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,18 @@

% compute leadfield
if hasfilter
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
% check that inverse parameters are not specified
assert(isempty(noisecov), 'the options for computing the filter must all be empty/default');
assert(isempty(sourcecov), 'the options for computing the filter must all be empty/default');
assert(isempty(lambda), 'the options for computing the filter must all be empty/default');
assert(isempty(noiselambda), 'the options for computing the filter must all be empty/default');
ft_info('using precomputed filters\n');
sourcemodel.filter = sourcemodel.filter(originside);
elseif hasleadfield
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
% using the computed leadfields
ft_info('using precomputed leadfields\n');
sourcemodel.leadfield = sourcemodel.leadfield(originside);
Expand Down
2 changes: 2 additions & 0 deletions inverse/ft_inverse_music.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
end

if hasleadfield
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
ft_info('using precomputed leadfields\n');
sourcemodel.leadfield = sourcemodel.leadfield(originside);
else
Expand Down
6 changes: 6 additions & 0 deletions inverse/ft_inverse_pcc.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,15 @@
end

if hasfilter
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
% check that the options for the inversion are not specified
assert(all(cellfun(@isempty, invopt(2:2:end))), 'the options for computing the inverse solution must all be empty/default');
ft_info('using precomputed filters\n');
sourcemodel.filter = sourcemodel.filter(originside);
elseif hasleadfield
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
ft_info('using precomputed leadfields\n');
sourcemodel.leadfield = sourcemodel.leadfield(originside);
else
Expand Down
2 changes: 2 additions & 0 deletions inverse/ft_inverse_rv.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
end

if hasleadfield
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
ft_info('using precomputed leadfields\n');
sourcemodel.leadfield = sourcemodel.leadfield(originside);
else
Expand Down
6 changes: 6 additions & 0 deletions inverse/ft_inverse_sam.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,15 @@
end

if hasfilter
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
% check that the options for the inversion are not specified
assert(all(cellfun(@isempty, invopt(2:2:end))), 'the options for computing the inverse solution must all be empty/default');
ft_info('using precomputed filters\n');
sourcemodel.filter = sourcemodel.filter(sourcemodel.inside);
elseif hasleadfield
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
ft_info('using precomputed leadfields\n');
sourcemodel.leadfield = sourcemodel.leadfield(sourcemodel.inside);

Expand Down
8 changes: 8 additions & 0 deletions inverse/ft_inverse_sloreta.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,17 @@
end

if hasfilter
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
% check that lambda is not specified
assert(isempty(lambda), 'the options for computing the filter must all be empty/default');
ft_info('using precomputed filters\n');
ft_info('using precomputed filters\n');
sourcemodel.filter = sourcemodel.filter(originside);
elseif hasleadfield
% check that the options normalize/reducerank/etc are not specified
assert(all(cellfun(@isempty, leadfieldopt(2:2:end))), 'the options for computing the leadfield must all be empty/default');
ft_info('using precomputed filters\n');
ft_info('using precomputed leadfields\n');
sourcemodel.leadfield = sourcemodel.leadfield(originside);
else
Expand Down

0 comments on commit 55a158a

Please sign in to comment.