From 284e86dcefe73797b9a9d4096af6755852ffa4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mihai=20Capot=C4=83?= Date: Wed, 24 Oct 2018 11:16:05 -0700 Subject: [PATCH] syntax: Fix Python 3.6 string escape deprecation From Python 3.6 release notes: "A backslash-character pair that is not a valid escape sequence now generates a DeprecationWarning. Although this will eventually become a SyntaxError, that will not be for several Python releases." https://docs.python.org/3/whatsnew/3.6.html#deprecated-python-behavior This became a run-checks.sh error and was causing builds to fail in PR #387 starting with pycodestyle 2.4.0: https://pycodestyle.readthedocs.io/en/latest/developer.html --- brainiak/fcma/classifier.py | 20 ++++++++--------- brainiak/fcma/mvpa_voxelselector.py | 2 +- brainiak/fcma/preprocessing.py | 2 +- brainiak/funcalign/rsrm.py | 9 ++++---- brainiak/funcalign/sssrm.py | 4 ++-- brainiak/reprsimil/brsa.py | 34 ++++++++++++++--------------- brainiak/utils/utils.py | 16 +++++++------- 7 files changed, 44 insertions(+), 43 deletions(-) diff --git a/brainiak/fcma/classifier.py b/brainiak/fcma/classifier.py index 07230c507..bf226596e 100644 --- a/brainiak/fcma/classifier.py +++ b/brainiak/fcma/classifier.py @@ -69,25 +69,25 @@ class Classifier(BaseEstimator): ---------- training_data_: 2D numpy array in shape [num_samples, num_features] - training_data\_ is None except clf is SVM.SVC with precomputed kernel, + training_data\\_ is None except clf is SVM.SVC with precomputed kernel, in which case training data is needed to compute the similarity vector for each sample to be classified. However, if the test samples are also provided during the fit, the similarity vectors can be precomputed too - and then training_data\ is None + and then training_data\\_ is None test_raw_data_: a list of 2D array in shape [num_TRs, num_voxels] default None - test_raw_data\_ is set after a prediction is called, - if the new input data equals test_raw_data\_, - test_data\_ can be reused + test_raw_data\\_ is set after a prediction is called, + if the new input data equals test_raw_data\\_, + test_data\\_ can be reused test_data_: 2D numpy array in shape [num_samples, num_features] default None - test_data\_ is set after a prediction is called, + test_data\\_ is set after a prediction is called, so that the test data does not need to be regenerated in the subsequent operations, e.g. getting decision values of the prediction. - test_data\_ may also be set in the fit method + test_data\\_ may also be set in the fit method if sklearn.svm.SVC with precomputed kernel and the test samples are known. NOTE: the test samples will never be used to fit the model. @@ -103,7 +103,7 @@ class Classifier(BaseEstimator): The dimension of correlation data, normally is the product of the number of voxels of brain region 1 and the number of voxels of brain region 2. - num_features\_ must be consistent in both training and classification + num_features\\_ must be consistent in both training and classification num_samples_: int The number of samples @@ -597,10 +597,10 @@ def _is_equal_to_test_raw_data(self, X): def decision_function(self, X=None): """Output the decision value of the prediction. - if X is not equal to self.test_raw_data\_, i.e. predict is not called, + if X is not equal to self.test_raw_data\\_, i.e. predict is not called, first generate the test_data after getting the test_data, get the decision value via self.clf. - if X is None, test_data\_ is ready to be used + if X is None, test_data\\_ is ready to be used Parameters ---------- diff --git a/brainiak/fcma/mvpa_voxelselector.py b/brainiak/fcma/mvpa_voxelselector.py index a308f9e2d..3b9237489 100644 --- a/brainiak/fcma/mvpa_voxelselector.py +++ b/brainiak/fcma/mvpa_voxelselector.py @@ -65,7 +65,7 @@ class MVPAVoxelSelector: contains the labels of the epochs. It is generated by .io.prepare_searchlight_mvpa_data - num\_folds: int + num_folds: int the number of folds to be conducted in the cross validation sl: Searchlight diff --git a/brainiak/fcma/preprocessing.py b/brainiak/fcma/preprocessing.py index 8ef715af9..dd6a31b81 100644 --- a/brainiak/fcma/preprocessing.py +++ b/brainiak/fcma/preprocessing.py @@ -237,7 +237,7 @@ def generate_epochs_info(epoch_list): Parameters ---------- - epoch\_list: list of 3D (binary) array in shape [condition, nEpochs, nTRs] + epoch_list: list of 3D (binary) array in shape [condition, nEpochs, nTRs] Contains specification of epochs and conditions, assuming 1. all subjects have the same number of epochs; 2. len(epoch_list) equals the number of subjects; diff --git a/brainiak/funcalign/rsrm.py b/brainiak/funcalign/rsrm.py index 34efac464..959f8a4f5 100644 --- a/brainiak/funcalign/rsrm.py +++ b/brainiak/funcalign/rsrm.py @@ -52,8 +52,9 @@ class RSRM(BaseEstimator, TransformerMixin): The model is estimated solving the following optimization problem: - .. math:: \\min_{W_i, S_i, R}\\sum_i \\frac{1}{2}\|X_i - W_i R - S_i\|_F^2 - .. math:: + \\gamma\|S_i\|_1 + .. math:: + \\min_{W_i, S_i, R}\\sum_i \\frac{1}{2}\\|X_i - W_i R - S_i\\|_F^2 + .. math:: + \\gamma\\|S_i\\|_1 .. math:: s.t. \\qquad W_i^TW_i = I \\quad \\forall i=1 \\dots N The solution to this problem is obtained by applying a Block-Coordinate @@ -345,8 +346,8 @@ def _init_transforms(self, subjs, voxels, features, random_state): def _objective_function(X, W, R, S, gamma): """Evaluate the objective function. - .. math:: \sum_{i=1}^{N} 1/2 \| X_i - W_i R - S_i \|_F^2 - .. math:: + /\gamma * \|S_i\|_1 + .. math:: \\sum_{i=1}^{N} 1/2 \\| X_i - W_i R - S_i \\|_F^2 + .. math:: + /\\gamma * \\|S_i\\|_1 Parameters ---------- diff --git a/brainiak/funcalign/sssrm.py b/brainiak/funcalign/sssrm.py index 445ab7611..1efc4e9d4 100644 --- a/brainiak/funcalign/sssrm.py +++ b/brainiak/funcalign/sssrm.py @@ -642,8 +642,8 @@ def _objective_function_subject(self, data_align, data_sup, labels, w, s, """Compute the objective function for one subject. .. math:: (1-C)*Loss_{SRM}_i(W_i,S;X_i) - .. math:: + C/\gamma * Loss_{MLR_i}(\theta, bias; {(W_i^T*Z_i, y_i}) - .. math:: + R(\theta) + .. math:: + C/\\gamma * Loss_{MLR_i}(\\theta, bias; {(W_i^T*Z_i, y_i}) + .. math:: + R(\\theta) Parameters ---------- diff --git a/brainiak/reprsimil/brsa.py b/brainiak/reprsimil/brsa.py index c0cbd37d8..af1b8c9b6 100755 --- a/brainiak/reprsimil/brsa.py +++ b/brainiak/reprsimil/brsa.py @@ -311,7 +311,7 @@ class BRSA(BaseEstimator, TransformerMixin): A time course of constant 1 will be included to the nuisance regressor regardless of whether the user requests. If baseline_single is set to False, one such regressor is included - for each fMRI run, but a single component in beta0\_ will be + for each fMRI run, but a single component in beta0\\_ will be computed as the average of the weight maps corresponding to these regressors. This might cause underestimation of noise variance. If baseline_single is True, only one regressor of constant 1 will be @@ -455,15 +455,15 @@ class BRSA(BaseEstimator, TransformerMixin): The correlation matrix derived from the shared covariance matrix. This is the estimated similarity matrix between neural patterns to your task conditions. Notice that it is recommended that - you also check U\_, which is the covariance matrix underlying + you also check U\\_, which is the covariance matrix underlying this correlation matrix. In cases there is almost no response - to your task conditions, the diagonal values of U\_ would become - very small and C\_ might contain many correlation coefficients + to your task conditions, the diagonal values of U\\_ would become + very small and C\\_ might contain many correlation coefficients close to 1 or -1. This might not reflect true strong correlation or strong negative correlation, but a result of lack of task-related neural activity, design matrix that does not match true neural response, or not enough data. - It is also recommended to check nSNR\_ after mapping it back to + It is also recommended to check nSNR\\_ after mapping it back to the brain. A "reasonable" map should at least have higher values in gray matter in than white matter. nSNR_ : numpy array, shape=[voxels,]. @@ -497,10 +497,10 @@ class BRSA(BaseEstimator, TransformerMixin): The estimated time course that is shared across voxels but unrelated to the events of interest (design matrix). beta0_null_: numpy array, shape=[n_nureg + n_base, voxels] - The equivalent of beta0\_ in a null model which does not + The equivalent of beta0\\_ in a null model which does not include the design matrix and response pattern beta. X0_null_: numpy array, shape=[time_points, n_nureg + n_base] - The equivalent of X0\_ in a null model which does not + The equivalent of X0\\_ in a null model which does not include the design matrix and response pattern beta n_nureg_: int Number of nuisance regressor in addition to such @@ -2743,7 +2743,7 @@ class GBRSA(BRSA): you might want to start with specifying a lower rank and use metrics such as AIC or BIC to decide the optimal rank. The log likelihood for the fitted data can be retrieved through private attributes - _LL_train\_. Note that this log likelihood score is only used + _LL_train\\_. Note that this log likelihood score is only used here for selecting hyperparameters such as rank. For any formal model comparison, we recommend using score() function on left-out data. @@ -2795,7 +2795,7 @@ class GBRSA(BRSA): A time course of constant 1 will be included to the nuisance regressor for each participant. If baseline_single is set to False, one such regressor is included for each fMRI run, but at the end of - fitting, a single component in beta0\_ will be computed as the average + fitting, a single component in beta0\\_ will be computed as the average of the weight maps corresponding to these regressors. This might cause underestimation of noise variance. If baseline_single is True, only one regressor of constant 1 will be @@ -2907,21 +2907,21 @@ class GBRSA(BRSA): The correlation matrix derived from the shared covariance matrix. This is the estimated similarity matrix between neural patterns to your task conditions. Notice that it is recommended that - you also check U\_, which is the covariance matrix underlying + you also check U\\_, which is the covariance matrix underlying this correlation matrix. In cases there is almost no response - to your task conditions, the diagonal values of U\_ would become - very small and C\_ might contain many correlation coefficients + to your task conditions, the diagonal values of U\\_ would become + very small and C\\_ might contain many correlation coefficients close to 1 or -1. This might not reflect true strong correlation or strong negative correlation, but a result of lack of task-related neural activity, design matrix that does not match true neural response, or not enough data. - It is also recommended to check nSNR\_ after mapping it back to + It is also recommended to check nSNR\\_ after mapping it back to the brain. A "reasonable" map should at least have higher values in gray matter in than white matter. nSNR_ : list of numpy arrays, shape=[voxels,] for each subject in the list. The pseuso-SNR of all voxels. If SNR_prior='lognormal', - the geometric mean of nSNR\_ would be approximately 1. - If SNR_prior='unif', all nSNR\_ would be in the range of (0,1). + the geometric mean of nSNR\\_ would be approximately 1. + If SNR_prior='unif', all nSNR\\_ would be in the range of (0,1). If SNR_prior='exp' (default), the range of values would vary depending on the data and SNR_bins, but many should have low values with few voxels with high values. @@ -2949,11 +2949,11 @@ class GBRSA(BRSA): unrelated to the events of interest (design matrix). beta0_null_: list of numpy arrays, shape=[n_nureg + n_base, voxels] for each subject. - The equivalent of beta0\_ in a null model which does not + The equivalent of beta0\\_ in a null model which does not include the design matrix and response pattern beta X0_null_: list of numpy arrays, shape=[time_points, n_nureg + n_base] for each subject. - The equivalent of X0\_ in a null model which does not + The equivalent of X0\\_ in a null model which does not include the design matrix and response pattern beta n_nureg_: 1-d numpy array Number of nuisance regressor used to model the spatial noise diff --git a/brainiak/utils/utils.py b/brainiak/utils/utils.py index dbbf48faf..f4d7ab781 100644 --- a/brainiak/utils/utils.py +++ b/brainiak/utils/utils.py @@ -315,12 +315,12 @@ def read_afni(self, fname): int(split_by_at[1]) curr_idx += n_this_cond elif len(split_by_at) == 1 and \ - not re.search('\..', split_by_at[0]): + not re.search(r'\..', split_by_at[0]): # Just a number, and not the type like '1..4' self.column_types[curr_idx] = int(split_by_at[0]) curr_idx += 1 else: # must be a single stimulus condition - split_by_dots = re.split('\..', CG) + split_by_dots = re.split(r'\..', CG) n_this_cond = int(split_by_dots[1]) self.column_types[curr_idx:curr_idx + n_this_cond] = 1 curr_idx += n_this_cond @@ -346,7 +346,7 @@ def gen_design(stimtime_files, scan_duration, TR, style='FSL', 'undershoot_scale': 0.035}): """ Generate design matrix based on a list of names of stimulus timing files. The function will read each file, and generate - a numpy array of size [time_points \* condition], where + a numpy array of size [time_points \\* condition], where time_points equals duration / TR, and condition is the size of stimtime_filenames. Each column is the hypothetical fMRI response based on the stimulus timing in the corresponding file @@ -401,14 +401,14 @@ def gen_design(stimtime_files, scan_duration, TR, style='FSL', Each line has a few triplets in the format of stim_onsets*weight:duration (or simpler, see below), separated by spaces. - For example, 3.2\*2.0:1.5 means that one event starts at 3.2s, + For example, 3.2\\*2.0:1.5 means that one event starts at 3.2s, modulated by weight of 2.0 and lasts for 1.5s. If some run does not include a single event - of a condition (stimulus type), then you can put \*, + of a condition (stimulus type), then you can put \\*, or a negative number, or a very large number in that line. Either duration or weight can be neglected. In such cases, they will default to 1.0. - For example, 3.0, 3.0\*1.0, 3.0:1.0 and 3.0\*1.0:1.0 all + For example, 3.0, 3.0\\*1.0, 3.0:1.0 and 3.0\\*1.0:1.0 all means an event starting at 3.0s, lasting for 1.0s, with amplitude modulation of 1.0. @@ -489,7 +489,7 @@ def gen_design(stimtime_files, scan_duration, TR, style='FSL', def _read_stimtime_FSL(stimtime_files, n_C, n_S, scan_onoff): """ Utility called by gen_design. It reads in one or more stimulus timing file comforming to FSL style, - and return a list (size of [#run \* #condition]) + and return a list (size of [#run \\* #condition]) of dictionary including onsets, durations and weights of each event. Parameters @@ -557,7 +557,7 @@ def _read_stimtime_FSL(stimtime_files, n_C, n_S, scan_onoff): def _read_stimtime_AFNI(stimtime_files, n_C, n_S, scan_onoff): """ Utility called by gen_design. It reads in one or more stimulus timing file comforming to AFNI style, and return a list - (size of ``[number of runs \* number of conditions]``) + (size of ``[number of runs \\* number of conditions]``) of dictionary including onsets, durations and weights of each event. Parameters