From 0e56d114d75ef6b65f1ab06aa0dcc74ee457adbd Mon Sep 17 00:00:00 2001 From: Tien Dung Nguyen Date: Thu, 21 Mar 2024 17:41:03 +0100 Subject: [PATCH] update unit test to avoid floating point errors --- .gitignore | 2 -- test_pipes/test_pac.m | 35 +++++++++++++++++++---------------- 2 files changed, 19 insertions(+), 18 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 567bad1..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.asv -.DS_Store diff --git a/test_pipes/test_pac.m b/test_pipes/test_pac.m index 994ff94..9ab4874 100644 --- a/test_pipes/test_pac.m +++ b/test_pipes/test_pac.m @@ -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]; @@ -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');