Skip to content

Commit

Permalink
update unit test to avoid floating point errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyen-td committed Mar 21, 2024
1 parent 99e95fb commit 0e56d11
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .gitignore

This file was deleted.

35 changes: 19 additions & 16 deletions test_pipes/test_pac.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@

EEG1 = pop_roi_connect(EEG, 'methods', {'PAC', 'MIM', 'COH'}, 'fcomb', fcomb); % test all 3 connectivity functions (data2spwctrgc, data2strgcmim, roi_pac)
tic
EEG2 = pop_roi_connect(EEG, 'methods', {'PAC'}, 'fcomb', fcomb, 'conn_stats', 'on', 'nshuf', 3, 'poolsize', 12); % compute only b_anti, b_anti_norm
EEG2 = pop_roi_connect(EEG, 'methods', {'PAC'}, 'fcomb', fcomb, 'conn_stats', 'on', 'nshuf', 3, 'poolsize', 2); % compute only b_anti, b_anti_norm
toc
EEG3 = pop_roi_connect(EEG, 'methods', {'PAC'}, 'fcomb', fcomb, 'bs_outopts', 1); % compute only b_anti, b_anti_norm
EEG3 = pop_roi_connect(EEG, 'methods', {'PAC'}, 'fcomb', fcomb, 'bs_outopts', 5);

if ~isequal(squeeze(EEG2.roi.PAC.b_orig(:, :, 1)), EEG3.roi.PAC.b_orig)
% test if first shuffle equals the true value
tolerance = 1e-7;
if ~all(ismembertol(EEG1.roi.PAC.b_orig, squeeze(EEG2.roi.PAC.b_orig(:, :, 1)), tolerance), 'all')
error 'The first shuffle in the surrogate connectivity array is not the true matrix.'
end

if ~isequal(squeeze(EEG2.roi.PAC.b_anti(:, :, 1)), EEG3.roi.PAC.b_anti)
if ~all(ismembertol(EEG1.roi.PAC.b_anti, squeeze(EEG2.roi.PAC.b_anti(:, :, 1)), tolerance), 'all')
error 'The first shuffle in the surrogate connectivity array is not the true matrix.'
end


%% Test bispectrum for frequency band inputs
low = [4 8];
high = [48 50];
Expand All @@ -58,27 +59,29 @@
EEG4 = pop_roi_connect(EEG, 'methods', {'PAC', 'MIM', 'COH'}, 'fcomb', fcomb); % test all 3 connectivity functions (data2spwctrgc, data2strgcmim, roi_pac)toc
toc
tic
EEG5 = pop_roi_connect(EEG, 'methods', {'PAC'}, 'fcomb', fcomb, 'conn_stats', 'off', 'nshuf', 3, 'bs_outopts', 1);
EEG5 = pop_roi_connect(EEG, 'methods', {'PAC'}, 'fcomb', fcomb, 'conn_stats', 'off', 'nshuf', 3, 'bs_outopts', 5);
toc

if ~isequal(squeeze(EEG5.roi.PAC.b_anti(:, :, 1)), EEG4.roi.PAC.b_anti)
% test if first shuffle equals the true value
tolerance = 1e-7;
if ~all(ismembertol(EEG4.roi.PAC.b_anti, squeeze(EEG5.roi.PAC.b_anti(:, :, 1)), tolerance), 'all')
error 'The first shuffle in the surrogate connectivity array is not the true matrix.'
end

%% Test PAC plotting
% Test for single frequency inputs
pop_roi_connectplot(EEG3, 'measure', 'pac', 'plotmatrix', 'on');
pop_roi_connectplot(EEG3, 'measure', 'pac_anti', 'plotmatrix', 'on');
pop_roi_connectplot(EEG1, 'measure', 'PAC', 'plotmatrix', 'on');
pop_roi_connectplot(EEG1, 'measure', 'PAC_anti', 'plotmatrix', 'on');

% Provoke errors by plotting bispectral tensors that do not exist
pop_roi_connectplot(EEG3, 'measure', 'pac_anti', 'plotmatrix', 'on'); % bs_outopts 4 means only original bispectra are computed, so cannot plot anti
pop_roi_connectplot(EEG3, 'measure', 'pac', 'plotmatrix', 'on'); % bs_outopts 5 means only antisymm. bispectra are computed, so cannot plot normal bispectrum
pop_roi_connectplot(EEG3, 'measure', 'PAC_anti', 'plotmatrix', 'on'); % bs_outopts 4 means only original bispectra are computed, so cannot plot anti
pop_roi_connectplot(EEG3, 'measure', 'PAC', 'plotmatrix', 'on'); % bs_outopts 5 means only antisymm. bispectra are computed, so cannot plot normal bispectrum

% Test for frequency bands
pop_roi_connectplot(EEG5, 'measure', 'pac', 'plotmatrix', 'on');
pop_roi_connectplot(EEG5, 'measure', 'pac_anti', 'plotmatrix', 'on');
pop_roi_connectplot(EEG4, 'measure', 'PAC', 'plotmatrix', 'on');
pop_roi_connectplot(EEG4, 'measure', 'PAC_anti', 'plotmatrix', 'on');

% plot MIM and COH as a sanity check
pop_roi_connectplot(EEG1, 'measure', 'mim', 'plotmatrix', 'on');
pop_roi_connectplot(EEG1, 'measure', 'coh', 'plotmatrix', 'on');
% plot MIM and aCOH as a sanity check
pop_roi_connectplot(EEG1, 'measure', 'MIM', 'plotmatrix', 'on');
pop_roi_connectplot(EEG1, 'measure', 'aCOH', 'plotmatrix', 'on');

0 comments on commit 0e56d11

Please sign in to comment.