From a50bbef83e9234511d02f2216f26d4224f20e668 Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Sun, 15 Sep 2019 15:09:54 -0400 Subject: [PATCH 01/17] Removed print statement --- tests/utils/test_fmrisim.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/utils/test_fmrisim.py b/tests/utils/test_fmrisim.py index 7c442661a..d713f5f39 100644 --- a/tests/utils/test_fmrisim.py +++ b/tests/utils/test_fmrisim.py @@ -675,7 +675,6 @@ def test_generate_noise_spatial(): # Calculate the proportion of std relative to the mean std_proportion = np.nanstd(fwhm3) / np.nanmean(fwhm3) - print(fwhm3) assert std_proportion < 0.25, 'Variance is inconsistent across dim' From c82e57fa812755c17be4529d26bdbce5d8ceab5b Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Sun, 15 Sep 2019 15:11:47 -0400 Subject: [PATCH 02/17] Update to how drift is calculated and used. The new default for drift drops off power on the basis functions systematically. Drift is also scaled separately from the brain noise since that scale is based on a detrended version of drift --- brainiak/utils/fmrisim.py | 121 +++++++++++++++++++++++++++++++------- 1 file changed, 101 insertions(+), 20 deletions(-) diff --git a/brainiak/utils/fmrisim.py b/brainiak/utils/fmrisim.py index 5261f484c..741a82a30 100644 --- a/brainiak/utils/fmrisim.py +++ b/brainiak/utils/fmrisim.py @@ -90,6 +90,7 @@ from scipy import signal import scipy.ndimage as ndimage import copy +from scipy import optimize __all__ = [ "apply_signal", @@ -1521,7 +1522,7 @@ def _generate_noise_temporal_task(stimfunction_tr, def _generate_noise_temporal_drift(trs, tr_duration, - basis="discrete_cos", + basis="cos_power_drop", period=150, ): @@ -1542,10 +1543,17 @@ def _generate_noise_temporal_drift(trs, basis : str What is the basis function for the drift. Could be made of discrete cosines (for longer run durations, more basis functions are - created) or a sine wave. + created) that either have equal power ('discrete_cos') or the power + diminishes such that 99% of the power is below a specified frequency + ('cos_power_drop'). Alternatively, this drift could simply be a sine + wave ('sine') period : int - How many seconds is the period of oscillation of the drift + When the basis function is 'cos_power_drop' this is the period over + which no power of the drift exceeds (i.e. the power of the drift + asymptotes at this period). However for the other basis functions, + this is simply how many seconds is the period of oscillation of the + drift Returns ---------- @@ -1595,6 +1603,63 @@ def _generate_noise_temporal_drift(trs, phase = (timepoints / (trs - 1) * cycles * 2 * np.pi) + phaseshift noise_drift = np.sin(phase) + elif basis == 'cos_power_drop': + + # Specify when each + timepoints = np.linspace(0, trs - 1, trs) * tr_duration + + # Specify the other timing information + duration = trs * tr_duration + + # How bases do you have + basis_funcs = int(np.floor(2 * duration / period)) + + if basis_funcs == 0: + err_msg = 'Too few timepoints (' + str(trs) + ') to accurately ' \ + 'model drift' + logger.warning(err_msg) + basis_funcs = 1 + + noise_drift = np.zeros((timepoints.shape[0], basis_funcs)) + for basis_counter in list(range(1, basis_funcs + 1)): + # What steps do you want to take for this basis function + random_phase = np.random.rand() * np.pi * 2 + + timepoint_phase = (timepoints / duration * np.pi * basis_counter) + + # In radians, what is the value for each time point + timepoints_basis = timepoint_phase + random_phase + + # Store the drift from this basis func + noise_drift[:, basis_counter - 1] = np.cos(timepoints_basis) + + # Function to return the drop rate for the power of basis functions + def power_drop(r, L, F): + percent_retained = 0.99 # What is the percentage of drift retained + numerator = 1 - r ** (2 * L / F) + denominator = 1 - r ** (2 * L) + return abs((numerator / denominator) - percent_retained) + + # Solve for power reduction rate. + # This assumes that r is between 0 and 1 + # Takes the duration and period as arguments + sol = optimize.minimize_scalar(power_drop, + bounds=(0, 1), + method='Bounded', + args=(duration, period)) + + # Pull out the solution + r = sol.x + + # Weight the basis functions based on the power drop off + basis_weights = r ** np.arange(basis_funcs) + + # Weigh the basis functions + weighted_basis_funcs = np.multiply(noise_drift, basis_weights) + + # Average the drift + noise_drift = np.mean(weighted_basis_funcs, 1) + # Normalize so the sigma is 1 noise_drift = stats.zscore(noise_drift) @@ -2010,19 +2075,6 @@ def _generate_noise_temporal(stimfunction_tr, # Preset the volume noise_volume = np.zeros((dimensions[0], dimensions[1], dimensions[2], trs)) - # Generate the drift noise - if noise_dict['drift_sigma'] != 0: - # Calculate the drift time course - noise = _generate_noise_temporal_drift(trs, - tr_duration, - ) - # Create a volume with the drift properties - volume = np.ones(dimensions) - - # Combine the volume and noise - noise_volume += np.multiply.outer(volume, noise) * noise_dict[ - 'drift_sigma'] - # Generate the physiological noise if noise_dict['physiological_sigma'] != 0: @@ -2283,6 +2335,7 @@ def _noise_dict_update(noise_dict): def _fit_spatial(noise, noise_temporal, + drift_noise, mask, template, spatial_sd, @@ -2304,6 +2357,9 @@ def _fit_spatial(noise, noise_temporal : multidimensional array, float The temporal noise that was generated by _generate_temporal_noise + drift_noise : multidimensional array, float + The drift noise generated by _generate_noise_temporal_drift + tr_duration : float What is the duration, in seconds, of each TR? @@ -2398,7 +2454,8 @@ def _fit_spatial(noise, ) # Sum up the noise of the brain - noise = base + (noise_temporal * temporal_sd) + noise_system + noise = base + drift_noise + noise_system + noise += (noise_temporal * temporal_sd) # Add the brain specific noise # Reject negative values (only happens outside of the brain) noise[noise < 0] = 0 @@ -2421,6 +2478,7 @@ def _fit_temporal(noise, spatial_sd, temporal_proportion, temporal_sd, + drift_noise, noise_dict, fit_thresh, fit_delta, @@ -2464,6 +2522,9 @@ def _fit_temporal(noise, What is the standard deviation in time of the noise volume to be generated + drift_noise : multidimensional array, float + The drift noise generated by _generate_noise_temporal_drift + noise_dict : dict A dictionary specifying the types of noise in this experiment. The noise types interact in important ways. First, all noise types @@ -2579,7 +2640,8 @@ def _fit_temporal(noise, ) # Sum up the noise of the brain - noise = base + (noise_temporal * temporal_sd) + noise_system + noise = base + drift_noise + noise_system + noise += (noise_temporal * temporal_sd) # Add the brain specific noise # Reject negative values (only happens outside of the brain) noise[noise < 0] = 0 @@ -2735,7 +2797,7 @@ def generate_noise(dimensions, # What is the mean signal of the non masked voxels in this template? mean_signal = (base[mask > 0]).mean() - # Generate the noise + # Generate the temporal noise noise_temporal = _generate_noise_temporal(stimfunction_tr=stimfunction_tr, tr_duration=tr_duration, dimensions=dimensions, @@ -2744,6 +2806,22 @@ def generate_noise(dimensions, noise_dict=noise_dict, ) + # Generate the drift noise + if noise_dict['drift_sigma'] != 0: + # Calculate the drift time course + noise = _generate_noise_temporal_drift(len(stimfunction_tr), + tr_duration, + ) + # Create a volume with the drift properties + volume = np.ones(dimensions_tr) + + # Combine the volume and noise + drift_noise = np.multiply.outer(volume, noise) * noise_dict[ + 'drift_sigma'] + else: + # If there is no drift, then just make this zeros + drift_noise = np.zeros(dimensions_tr) + # Convert SFNR into the size of the standard deviation of temporal # variability temporal_sd = (mean_signal / noise_dict['sfnr']) @@ -2763,7 +2841,8 @@ def generate_noise(dimensions, ) # Sum up the noise of the brain - noise = base + (noise_temporal * temporal_sd) + noise_system + noise = base + drift_noise + noise_system + noise += (noise_temporal * temporal_sd) # Add the brain specific noise # Reject negative values (only happens outside of the brain) noise[noise < 0] = 0 @@ -2771,6 +2850,7 @@ def generate_noise(dimensions, # Fit the SNR noise, spatial_sd = _fit_spatial(noise, noise_temporal, + drift_noise, mask, template, spatial_sd, @@ -2790,6 +2870,7 @@ def generate_noise(dimensions, spatial_sd, temporal_proportion, temporal_sd, + drift_noise, noise_dict, fit_thresh, fit_delta, From 13db9401c6c0e1fc0097f3b04cfcb832518f8ba1 Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Sun, 15 Sep 2019 16:10:05 -0400 Subject: [PATCH 03/17] Update to how drift is calculated and used. The new default for drift drops off power on the basis functions systematically. Drift is also scaled separately from the brain noise since that scale is based on a detrended version of drift --- brainiak/utils/fmrisim.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brainiak/utils/fmrisim.py b/brainiak/utils/fmrisim.py index 741a82a30..4d0fc87a3 100644 --- a/brainiak/utils/fmrisim.py +++ b/brainiak/utils/fmrisim.py @@ -2813,13 +2813,13 @@ def generate_noise(dimensions, tr_duration, ) # Create a volume with the drift properties - volume = np.ones(dimensions_tr) + volume = np.ones(dimensions[:3]) # Combine the volume and noise drift_noise = np.multiply.outer(volume, noise) * noise_dict[ 'drift_sigma'] else: - # If there is no drift, then just make this zeros + # If there is no drift, then just make this zeros (in 4d) drift_noise = np.zeros(dimensions_tr) # Convert SFNR into the size of the standard deviation of temporal From 0dbf2427285d96d6977877a7637b91fb4ba9e632 Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Sat, 28 Sep 2019 15:36:54 -0400 Subject: [PATCH 04/17] Fixed a math error and made the simulated drift include the 1% of power out of range --- brainiak/utils/fmrisim.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brainiak/utils/fmrisim.py b/brainiak/utils/fmrisim.py index 4d0fc87a3..6a259302a 100644 --- a/brainiak/utils/fmrisim.py +++ b/brainiak/utils/fmrisim.py @@ -1612,7 +1612,7 @@ def _generate_noise_temporal_drift(trs, duration = trs * tr_duration # How bases do you have - basis_funcs = int(np.floor(2 * duration / period)) + basis_funcs = int(np.floor(2 * duration)) if basis_funcs == 0: err_msg = 'Too few timepoints (' + str(trs) + ') to accurately ' \ @@ -1636,8 +1636,8 @@ def _generate_noise_temporal_drift(trs, # Function to return the drop rate for the power of basis functions def power_drop(r, L, F): percent_retained = 0.99 # What is the percentage of drift retained - numerator = 1 - r ** (2 * L / F) - denominator = 1 - r ** (2 * L) + numerator = 1 - r ** (4 * L / F) + denominator = 1 - r ** (4 * L) return abs((numerator / denominator) - percent_retained) # Solve for power reduction rate. From 9c1342ba3d218e17b037701760e4aae12ced4a85 Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Sat, 28 Sep 2019 15:37:16 -0400 Subject: [PATCH 05/17] Add command explicitly calling cos_power_drop --- tests/utils/test_fmrisim.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/utils/test_fmrisim.py b/tests/utils/test_fmrisim.py index d713f5f39..59b36fb59 100644 --- a/tests/utils/test_fmrisim.py +++ b/tests/utils/test_fmrisim.py @@ -541,6 +541,13 @@ def test_generate_noise(): period, ) + # Check it gives a warning if the duration is too short + drift = sim._generate_noise_temporal_drift(300, + tr_duration, + 'cos_power_drop', + period, + ) + # Test physiological noise (using unrealistic parameters so that it's easy) timepoints = list(np.linspace(0, (trs - 1) * tr_duration, trs)) resp_freq = 0.2 From 79e74578c36a79b79d5ae73b1e02cb55cc4a00e5 Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Sat, 5 Oct 2019 16:08:28 -0400 Subject: [PATCH 06/17] Remove warning for short runs since this does not apply to this basis function --- brainiak/utils/fmrisim.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/brainiak/utils/fmrisim.py b/brainiak/utils/fmrisim.py index 6a259302a..696524fd6 100644 --- a/brainiak/utils/fmrisim.py +++ b/brainiak/utils/fmrisim.py @@ -1614,11 +1614,6 @@ def _generate_noise_temporal_drift(trs, # How bases do you have basis_funcs = int(np.floor(2 * duration)) - if basis_funcs == 0: - err_msg = 'Too few timepoints (' + str(trs) + ') to accurately ' \ - 'model drift' - logger.warning(err_msg) - basis_funcs = 1 noise_drift = np.zeros((timepoints.shape[0], basis_funcs)) for basis_counter in list(range(1, basis_funcs + 1)): From 3ace12fe8c121f9af1e823dfca47379e22b05c5d Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Sat, 5 Oct 2019 16:18:58 -0400 Subject: [PATCH 07/17] Remove warning for short runs since this does not apply to this basis function --- brainiak/utils/fmrisim.py | 1 - 1 file changed, 1 deletion(-) diff --git a/brainiak/utils/fmrisim.py b/brainiak/utils/fmrisim.py index 696524fd6..af7217d28 100644 --- a/brainiak/utils/fmrisim.py +++ b/brainiak/utils/fmrisim.py @@ -1614,7 +1614,6 @@ def _generate_noise_temporal_drift(trs, # How bases do you have basis_funcs = int(np.floor(2 * duration)) - noise_drift = np.zeros((timepoints.shape[0], basis_funcs)) for basis_counter in list(range(1, basis_funcs + 1)): # What steps do you want to take for this basis function From ab3297fbb5bc91181fe82bfce898d0f638fac55f Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Tue, 5 Nov 2019 14:37:42 -0500 Subject: [PATCH 08/17] Update for MCI's comments --- brainiak/utils/fmrisim.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/brainiak/utils/fmrisim.py b/brainiak/utils/fmrisim.py index af7217d28..1d2dea8ee 100644 --- a/brainiak/utils/fmrisim.py +++ b/brainiak/utils/fmrisim.py @@ -1605,13 +1605,13 @@ def _generate_noise_temporal_drift(trs, elif basis == 'cos_power_drop': - # Specify when each + # Make a vector counting each TR timepoints = np.linspace(0, trs - 1, trs) * tr_duration # Specify the other timing information duration = trs * tr_duration - # How bases do you have + # How bases do you have? basis_funcs = int(np.floor(2 * duration)) noise_drift = np.zeros((timepoints.shape[0], basis_funcs)) @@ -1627,12 +1627,21 @@ def _generate_noise_temporal_drift(trs, # Store the drift from this basis func noise_drift[:, basis_counter - 1] = np.cos(timepoints_basis) - # Function to return the drop rate for the power of basis functions def power_drop(r, L, F): + # Function to return the drop rate for the power of basis functions + # In other words, how much should the weight of each basis function + # reduce in order to make the power you retain be above a 0.99 + # r is the power reduction rate which should be between 0 and 1 + # L is the duration of the run in seconds + # F is period of the cycle in seconds + percent_retained = 0.99 # What is the percentage of drift retained - numerator = 1 - r ** (4 * L / F) - denominator = 1 - r ** (4 * L) - return abs((numerator / denominator) - percent_retained) + numerator = 1 - r ** (4 * L / F) # Power of this period + denominator = 1 - r ** (4 * L) # Power of all periods + + # Calculate the retained power + power_drop = abs((numerator / denominator) - percent_retained) + return power_drop # Solve for power reduction rate. # This assumes that r is between 0 and 1 From 5d229b3f872481c237a2d3becf29c2113adb4edc Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Tue, 5 Nov 2019 15:59:06 -0500 Subject: [PATCH 09/17] Update for MCI's comments --- brainiak/utils/fmrisim.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/brainiak/utils/fmrisim.py b/brainiak/utils/fmrisim.py index 1d2dea8ee..ddfa9973b 100644 --- a/brainiak/utils/fmrisim.py +++ b/brainiak/utils/fmrisim.py @@ -1628,19 +1628,19 @@ def _generate_noise_temporal_drift(trs, noise_drift[:, basis_counter - 1] = np.cos(timepoints_basis) def power_drop(r, L, F): - # Function to return the drop rate for the power of basis functions - # In other words, how much should the weight of each basis function - # reduce in order to make the power you retain be above a 0.99 - # r is the power reduction rate which should be between 0 and 1 - # L is the duration of the run in seconds - # F is period of the cycle in seconds - + # Function to return the drop rate for the power of basis functions + # In other words, how much should the weight of each basis function + # reduce in order to make the power you retain be above a 0.99 + # r is the power reduction rate which should be between 0 and 1 + # L is the duration of the run in seconds + # F is period of the cycle in seconds + percent_retained = 0.99 # What is the percentage of drift retained numerator = 1 - r ** (4 * L / F) # Power of this period denominator = 1 - r ** (4 * L) # Power of all periods - + # Calculate the retained power - power_drop = abs((numerator / denominator) - percent_retained) + power_drop = abs((numerator / denominator) - percent_retained) return power_drop # Solve for power reduction rate. From 192a305eb8921b63b005af2bcf6ae1c6ba4fb073 Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Tue, 3 Dec 2019 00:37:14 -0500 Subject: [PATCH 10/17] Added more detail to the power drop doc string --- brainiak/utils/fmrisim.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brainiak/utils/fmrisim.py b/brainiak/utils/fmrisim.py index ddfa9973b..cea3c3cce 100644 --- a/brainiak/utils/fmrisim.py +++ b/brainiak/utils/fmrisim.py @@ -1630,7 +1630,8 @@ def _generate_noise_temporal_drift(trs, def power_drop(r, L, F): # Function to return the drop rate for the power of basis functions # In other words, how much should the weight of each basis function - # reduce in order to make the power you retain be above a 0.99 + # reduce in order to make the power you retain of the period's + # frequency be 99% of the total power of the highest frequency # r is the power reduction rate which should be between 0 and 1 # L is the duration of the run in seconds # F is period of the cycle in seconds From 5ec1c6324118c65e40bde8acec8633324e18174a Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Thu, 5 Dec 2019 13:50:52 -0500 Subject: [PATCH 11/17] Change the maximum frequency to be equivalent to the TR number --- brainiak/utils/fmrisim.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/brainiak/utils/fmrisim.py b/brainiak/utils/fmrisim.py index cea3c3cce..811f54806 100644 --- a/brainiak/utils/fmrisim.py +++ b/brainiak/utils/fmrisim.py @@ -1611,8 +1611,8 @@ def _generate_noise_temporal_drift(trs, # Specify the other timing information duration = trs * tr_duration - # How bases do you have? - basis_funcs = int(np.floor(2 * duration)) + # How bases do you have? This is to adhere to Nyquist + basis_funcs = int(trs) noise_drift = np.zeros((timepoints.shape[0], basis_funcs)) for basis_counter in list(range(1, basis_funcs + 1)): @@ -1637,8 +1637,8 @@ def power_drop(r, L, F): # F is period of the cycle in seconds percent_retained = 0.99 # What is the percentage of drift retained - numerator = 1 - r ** (4 * L / F) # Power of this period - denominator = 1 - r ** (4 * L) # Power of all periods + numerator = 1 - r ** (2 * L / F) # Power of this period + denominator = 1 - r ** (2 * L) # Power of all periods # Calculate the retained power power_drop = abs((numerator / denominator) - percent_retained) From e21342d26764f245765378e59edb5f3c90985d40 Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Thu, 5 Dec 2019 18:36:09 -0500 Subject: [PATCH 12/17] Make power drop unitless and add documentation. Also add test for period length check --- brainiak/utils/fmrisim.py | 32 ++++++++++++++++++++++++++------ tests/utils/test_fmrisim.py | 8 ++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/brainiak/utils/fmrisim.py b/brainiak/utils/fmrisim.py index 811f54806..32dc8d195 100644 --- a/brainiak/utils/fmrisim.py +++ b/brainiak/utils/fmrisim.py @@ -1627,18 +1627,38 @@ def _generate_noise_temporal_drift(trs, # Store the drift from this basis func noise_drift[:, basis_counter - 1] = np.cos(timepoints_basis) - def power_drop(r, L, F): + def power_drop(r, L, F, tr_duration): # Function to return the drop rate for the power of basis functions # In other words, how much should the weight of each basis function # reduce in order to make the power you retain of the period's - # frequency be 99% of the total power of the highest frequency + # frequency be 99% of the total power of the highest frequency, as + # defined by the DCT. + # For an example where there are 20 time points, there will be 20 + # basis functions in the DCT. If the period of the signal you wish + # to simulate is such that 99% of the power should drop off after + # the equivalent of 5 of these basis functions, then the way this + # code works is it finds the rate at which power must drop off for + # all of the 20 basis functions such that by the 5th one, there is + # only 1% of the power remaining. # r is the power reduction rate which should be between 0 and 1 # L is the duration of the run in seconds - # F is period of the cycle in seconds + # F is period of the cycle in seconds It is assumed that this will + # be greater than the tr_duration, or else this will not work + # tr_duration is the duration of each TR in seconds - percent_retained = 0.99 # What is the percentage of drift retained + # Check the TR duration + if F < tr_duration: + msg = 'Period length %0.1f is less than TR duration %0.1f' % ( + (F, tr_duration)) + raise ValueError(msg) + + percent_retained = 0.99 # What is the percentage of power retained + + # Compare the power at the period frequency (in the numerator) with + # the power at the frequency of the DCT, AKA the highest possible + # frequency in the data (in the denominator) numerator = 1 - r ** (2 * L / F) # Power of this period - denominator = 1 - r ** (2 * L) # Power of all periods + denominator = 1 - r ** (2 * L / tr_duration) # Power of DCT freq. # Calculate the retained power power_drop = abs((numerator / denominator) - percent_retained) @@ -1650,7 +1670,7 @@ def power_drop(r, L, F): sol = optimize.minimize_scalar(power_drop, bounds=(0, 1), method='Bounded', - args=(duration, period)) + args=(duration, period, tr_duration)) # Pull out the solution r = sol.x diff --git a/tests/utils/test_fmrisim.py b/tests/utils/test_fmrisim.py index 59b36fb59..3074862ea 100644 --- a/tests/utils/test_fmrisim.py +++ b/tests/utils/test_fmrisim.py @@ -534,20 +534,24 @@ def test_generate_noise(): assert power[period_freq] > power[period_freq + 1], 'Power is low' assert power[period_freq] > power[period_freq - 1], 'Power is low' - # Check it gives a warning if the duration is too short + # Check it runs fine drift = sim._generate_noise_temporal_drift(50, tr_duration, 'discrete_cos', period, ) - # Check it gives a warning if the duration is too short + # Check it runs fine drift = sim._generate_noise_temporal_drift(300, tr_duration, 'cos_power_drop', period, ) + # Check that when the TR is greater than the period it errors + with pytest.raises(ValueError): + sim._generate_noise_temporal_drift(30, 10,'cos_power_drop', 5) + # Test physiological noise (using unrealistic parameters so that it's easy) timepoints = list(np.linspace(0, (trs - 1) * tr_duration, trs)) resp_freq = 0.2 From 3109a199fd3f0a85dc3420636c0e0e562dcc1d38 Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Fri, 6 Dec 2019 09:52:06 -0500 Subject: [PATCH 13/17] Fix pep8 issue --- brainiak/utils/fmrisim.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/brainiak/utils/fmrisim.py b/brainiak/utils/fmrisim.py index 32dc8d195..b849f4e52 100644 --- a/brainiak/utils/fmrisim.py +++ b/brainiak/utils/fmrisim.py @@ -1648,8 +1648,7 @@ def power_drop(r, L, F, tr_duration): # Check the TR duration if F < tr_duration: - msg = 'Period length %0.1f is less than TR duration %0.1f' % ( - (F, tr_duration)) + msg = 'Period %0.0f > TR duration %0.0f' % ((F, tr_duration)) raise ValueError(msg) percent_retained = 0.99 # What is the percentage of power retained From debb8b2239a7081adba1094b8d14c54ffacd96a4 Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Fri, 6 Dec 2019 13:49:09 -0500 Subject: [PATCH 14/17] Fix pep8 issue --- tests/utils/test_fmrisim.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils/test_fmrisim.py b/tests/utils/test_fmrisim.py index 2bd5e00a2..6b52986f6 100644 --- a/tests/utils/test_fmrisim.py +++ b/tests/utils/test_fmrisim.py @@ -548,9 +548,9 @@ def test_generate_noise(): period, ) - # Check that when the TR is greater than the period it errors + # Check that when the TR is greater than the period it errors with pytest.raises(ValueError): - sim._generate_noise_temporal_drift(30, 10,'cos_power_drop', 5) + sim._generate_noise_temporal_drift(30, 10, 'cos_power_drop', 5) # Test physiological noise (using unrealistic parameters so that it's easy) timepoints = list(np.linspace(0, (trs - 1) * tr_duration, trs)) From eb82c55e62aaf120127fe5335ff063a40c4156b0 Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Mon, 9 Dec 2019 17:31:52 -0500 Subject: [PATCH 15/17] Update of scikit-learn to 0.22 changed how randomizer worked, rendering this wrong. Dropped hard coding but maintained spirit of the test --- tests/fcma/test_mvpa_voxel_selection.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/fcma/test_mvpa_voxel_selection.py b/tests/fcma/test_mvpa_voxel_selection.py index d551ff5ee..486d33ec7 100644 --- a/tests/fcma/test_mvpa_voxel_selection.py +++ b/tests/fcma/test_mvpa_voxel_selection.py @@ -40,10 +40,10 @@ def test_mvpa_voxel_selection(): output = [] for tuple in results: if tuple[1] > 0: - output.append(int(8*tuple[1])) - expected_output = [6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, - 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 1] - assert np.allclose(output, expected_output, atol=1), \ + output.append(tuple[1]) + + # Check that the mean accuracy with noise is close to chance + assert np.allclose(np.mean(output), 0.5, atol=0.1), \ 'voxel selection via SVM does not provide correct results' From 88ee76eb8f1719edd533a76d5a0ecdb880fe1a8d Mon Sep 17 00:00:00 2001 From: CameronTEllis Date: Tue, 10 Dec 2019 20:01:17 -0500 Subject: [PATCH 16/17] Revert test --- tests/fcma/test_mvpa_voxel_selection.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/fcma/test_mvpa_voxel_selection.py b/tests/fcma/test_mvpa_voxel_selection.py index 486d33ec7..d908422da 100644 --- a/tests/fcma/test_mvpa_voxel_selection.py +++ b/tests/fcma/test_mvpa_voxel_selection.py @@ -40,10 +40,12 @@ def test_mvpa_voxel_selection(): output = [] for tuple in results: if tuple[1] > 0: - output.append(tuple[1]) + output.append(int(8*tuple[1])) + expected_output = [6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, + 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 1] # Check that the mean accuracy with noise is close to chance - assert np.allclose(np.mean(output), 0.5, atol=0.1), \ + assert np.allclose(output, expected_output, atol=1), \ 'voxel selection via SVM does not provide correct results' From 59346f17a3c15268f366b89602c64f4e8e7df7a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mihai=20Capot=C4=83?= Date: Wed, 11 Dec 2019 13:14:20 -0800 Subject: [PATCH 17/17] Finish reverting test_mvpa_voxel_selection --- tests/fcma/test_mvpa_voxel_selection.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/fcma/test_mvpa_voxel_selection.py b/tests/fcma/test_mvpa_voxel_selection.py index d908422da..d551ff5ee 100644 --- a/tests/fcma/test_mvpa_voxel_selection.py +++ b/tests/fcma/test_mvpa_voxel_selection.py @@ -43,8 +43,6 @@ def test_mvpa_voxel_selection(): output.append(int(8*tuple[1])) expected_output = [6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 1] - - # Check that the mean accuracy with noise is close to chance assert np.allclose(output, expected_output, atol=1), \ 'voxel selection via SVM does not provide correct results'