From e4ab872dd2f40983e1bce96904fe22624c3afe71 Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:12:26 -0400 Subject: [PATCH 01/21] a Changes to be committed: new file: brainiak/brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt new file mode 100644 index 000000000..e69de29bb From 06c869a431109610e47d20dcf8e151373aabf5bd Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:20:44 -0400 Subject: [PATCH 02/21] deleted: brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt deleted file mode 100644 index e69de29bb..000000000 From ea7b002323214d7be758de4b398f723d24cc9dc9 Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:12:26 -0400 Subject: [PATCH 03/21] a Changes to be committed: new file: brainiak/brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt new file mode 100644 index 000000000..e69de29bb From ad3af51edc4e1193894525fa88c7531e45b068a4 Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:20:44 -0400 Subject: [PATCH 04/21] deleted: brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt deleted file mode 100644 index e69de29bb..000000000 From 66277e6e91dc6bc7d94845d17cdcb2aeb0cacd1f Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:12:26 -0400 Subject: [PATCH 05/21] a Changes to be committed: new file: brainiak/brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt new file mode 100644 index 000000000..e69de29bb From 1b6127ae18d5c9206fa9f314050ce8eaec487f44 Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:20:44 -0400 Subject: [PATCH 06/21] deleted: brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt deleted file mode 100644 index e69de29bb..000000000 From 4b1a794d0ca848d49ef0736c1656539c6793077d Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:12:26 -0400 Subject: [PATCH 07/21] a Changes to be committed: new file: brainiak/brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt new file mode 100644 index 000000000..e69de29bb From 2ded8dbee5c1eabd5130bf03c48b497f7184147d Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:20:44 -0400 Subject: [PATCH 08/21] deleted: brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt deleted file mode 100644 index e69de29bb..000000000 From 66ebf5f0da4d6dabd87a6f18f9b9c4057aee5180 Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:12:26 -0400 Subject: [PATCH 09/21] a Changes to be committed: new file: brainiak/brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt new file mode 100644 index 000000000..e69de29bb From 6a243448aa23d0562dc5136e2d5454ff0a268366 Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:20:44 -0400 Subject: [PATCH 10/21] deleted: brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt deleted file mode 100644 index e69de29bb..000000000 From 746f66e274006cc3847cc7d50d41fbb6def808e2 Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:12:26 -0400 Subject: [PATCH 11/21] a Changes to be committed: new file: brainiak/brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt new file mode 100644 index 000000000..e69de29bb From 9fad12b0f263dccf38f359c2d2698e926173a2dc Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:20:44 -0400 Subject: [PATCH 12/21] deleted: brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt deleted file mode 100644 index e69de29bb..000000000 From 92a199b893f22da0c4fce8970848d04ee03365ab Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:12:26 -0400 Subject: [PATCH 13/21] a Changes to be committed: new file: brainiak/brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt new file mode 100644 index 000000000..e69de29bb From 5265476bf8b323a2fbe57fad839271cd2aa5705c Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:20:44 -0400 Subject: [PATCH 14/21] deleted: brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt deleted file mode 100644 index e69de29bb..000000000 From 3acf09fb455222ab13280bc13200b03fe1945bb1 Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:12:26 -0400 Subject: [PATCH 15/21] a Changes to be committed: new file: brainiak/brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt new file mode 100644 index 000000000..e69de29bb From bc49c16ebc4e689025803d1c81305f7ded026671 Mon Sep 17 00:00:00 2001 From: lcnature Date: Fri, 2 Sep 2016 10:20:44 -0400 Subject: [PATCH 16/21] deleted: brsa/test.txt --- brainiak/brsa/test.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 brainiak/brsa/test.txt diff --git a/brainiak/brsa/test.txt b/brainiak/brsa/test.txt deleted file mode 100644 index e69de29bb..000000000 From 76e631e7c095013ab1784bb43537572521f95da1 Mon Sep 17 00:00:00 2001 From: Mingbo Cai Date: Fri, 16 Feb 2018 01:37:58 -0500 Subject: [PATCH 17/21] add notes in the documentation for the different assumption in BRSA from traditional RSA on what counts as signal. Also corrected the mismatch between documentation and actual implementation of the default optimizer. L-BFGS-B appears to require less memory and fits faster in each iteration than BFGS. But it is possible that more iterations are needed because Hessian is approximated, so the default max number of iteration is increased --- brainiak/reprsimil/brsa.py | 38 ++++++-- examples/reprsimil/bayesian_rsa_example.ipynb | 93 ++++++++++++++----- tests/reprsimil/test_brsa.py | 2 +- 3 files changed, 103 insertions(+), 30 deletions(-) diff --git a/brainiak/reprsimil/brsa.py b/brainiak/reprsimil/brsa.py index a26c19b35..049190ce4 100755 --- a/brainiak/reprsimil/brsa.py +++ b/brainiak/reprsimil/brsa.py @@ -238,6 +238,22 @@ class BRSA(BaseEstimator, TransformerMixin): \\epsilon_i \\sim AR(1) + Please note that the model assumes that the covariance matrix U which + all \\beta_i follow is zero-meaned. This assumption does not imply + there must be both positive and negative responses across voxels. + However, it means that Bayesian RSA treats the task-evoked activity + against baseline BOLD level as signal, while in other RSA tools + the deviation of task-evoked activity in each voxel from the average + task-evoked activity level across voxels may be considered as signal + of interest. Due to this assumption in BRSA, relatively high degree + of similarity may be expected when the activity patterns of two + task conditions both include strong sensory driven signals regardless + of their specific stimuli. When two task conditions elicit exactly + the same activity patterns but only differ in their global magnitudes, + under the assumption in BRSA, their similarity is 1; under the assumption + that only deviation of pattern from average patterns is signal of interest, + their similarity should be -1. + Parameters ---------- n_iter : int. Default: 50 @@ -387,12 +403,12 @@ class BRSA(BaseEstimator, TransformerMixin): without introducing the GP prior before fitting with it, if GP_space or GP_inten is requested. This initial fitting is to give the parameters a good starting point. - optimizer: str or callable. Default: 'BFGS' + optimizer: str or callable. Default: 'L-BFGS-B' The optimizer to use for minimizing cost function which scipy.optimize.minimize can accept. We use 'L-BFGS-B' as a default. Users can try other strings corresponding to optimizer provided by scipy.optimize.minimize, - or a custom optimizer, such as 'L-BFGS-B' or 'CG'. + or a custom optimizer, such as 'BFGS' or 'CG'. Note that BRSA fits a lot of parameters. So a chosen optimizer should accept gradient (Jacobian) of the cost function. Otherwise the fitting is likely to be unbarely slow. We do not calculate @@ -499,14 +515,14 @@ class BRSA(BaseEstimator, TransformerMixin): """ def __init__( - self, n_iter=50, rank=None, + self, n_iter=80, rank=None, auto_nuisance=True, n_nureg=None, nureg_zscore=True, nureg_method='PCA', baseline_single=False, GP_space=False, GP_inten=False, space_smooth_range=None, inten_smooth_range=None, tau_range=5.0, tau2_prior=prior_GP_var_inv_gamma, - eta=0.0001, init_iter=20, optimizer='BFGS', + eta=0.0001, init_iter=20, optimizer='L-BFGS-B', random_state=None, anneal_speed=10, tol=1e-4, minimize_options={'gtol': 1e-4, 'disp': False, 'maxiter': 6}): @@ -2711,6 +2727,10 @@ class GBRSA(BRSA): See also `.BRSA`. + Please note that the model assumes that the covariance matrix U which + all \\beta_i follow is zero-meaned. For more details of its implication, + see documentation of `.BRSA` + Parameters ---------- n_iter : int. Default: 50 @@ -2837,12 +2857,12 @@ class GBRSA(BRSA): This only takes effect for fitting the marginalized version. If set to 20, discrete numbers of {-0.95, -0.85, ..., 0.95} will be used to numerically integrate rho from -1 to 1. - optimizer: str or callable. Default: 'BFGS' + optimizer: str or callable. Default: 'L-BFGS-B' The optimizer to use for minimizing cost function which scipy.optimize.minimize can accept. We use 'L-BFGS-B' as a default. Users can try other strings corresponding to optimizer provided by scipy.optimize.minimize, - or a custom optimizer, such as 'L-BFGS-B' or 'CG'. + or a custom optimizer, such as 'BFGS' or 'CG'. Note that BRSA fits a lot of parameters. So a chosen optimizer should accept gradient (Jacobian) of the cost function. Otherwise the fitting is likely to be unbarely slow. We do not calculate @@ -2945,11 +2965,11 @@ class GBRSA(BRSA): """ def __init__( - self, n_iter=50, rank=None, + self, n_iter=80, rank=None, auto_nuisance=True, n_nureg=None, nureg_zscore=True, nureg_method='PCA', baseline_single=False, logS_range=1.0, SNR_prior='exp', - SNR_bins=21, rho_bins=20, tol=1e-4, optimizer='BFGS', + SNR_bins=21, rho_bins=20, tol=1e-4, optimizer='L-BFGS-B', minimize_options={'gtol': 1e-4, 'disp': False, 'maxiter': 20}, random_state=None, anneal_speed=10): @@ -3817,6 +3837,8 @@ def _raw_loglike_grids(self, L, s2XTAcorrX, YTAcorrY_diag, # In the equation of the log likelihood, this "denominator" # term is in fact divided by 2. But we absorb that into the # log fixted term. + print('YTAcorrY_diag', YTAcorrY_diag) + print('s2YTAcorrXL_LAMBDA_LTXTAcorrY', s2YTAcorrXL_LAMBDA_LTXTAcorrY) LL_raw = -half_log_det_X0TAX0[:, None] \ - half_log_det_LAMBDA_i[:, None] \ - (n_T - n_X0 - 2) / 2 * np.log(denominator) \ diff --git a/examples/reprsimil/bayesian_rsa_example.ipynb b/examples/reprsimil/bayesian_rsa_example.ipynb index a0c1f6b60..cf94f1d9a 100644 --- a/examples/reprsimil/bayesian_rsa_example.ipynb +++ b/examples/reprsimil/bayesian_rsa_example.ipynb @@ -9,6 +9,15 @@ "### The group_brsa_example.ipynb in the same directory demonstrates how to use GBRSA to estimate shared representational structure from multiple participants." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Please note that the model assumes that the covariance matrix U which all $\\beta_i$ follow is zero-meaned. This assumption does not imply there must be both positive and negative responses across voxels.\n", + "However, it means that Bayesian RSA treats the task-evoked activity against baseline BOLD level as signal, while in other RSA tools the deviation of task-evoked activity in each voxel from the average task-evoked activity level across voxels may be considered as signal of interest.\n", + "Due to this assumption in (G)BRSA, relatively high degree of similarity may be expected when the activity patterns of two task conditions share a strong sensory driven components. When two task conditions elicit exactly the same activity pattern but only differ in their global magnitudes, under the assumption in (G)BRSA, their similarity is 1; under the assumption that only deviation of pattern from average patterns is signal of interest (which is currently not supported by (G)BRSA), their similarity would be -1 because the deviations of the two patterns from their average pattern are exactly opposite." + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -21,7 +30,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "%matplotlib inline\n", @@ -46,7 +57,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "logging.basicConfig(\n", @@ -84,7 +97,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "design = utils.ReadDesign(fname=\"example_design.1D\")\n", @@ -130,7 +145,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "noise_bot = 0.5\n", @@ -212,7 +229,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "# import nibabel\n", @@ -236,7 +255,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "# ideal covariance matrix\n", @@ -279,7 +300,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "L_full = np.linalg.cholesky(ideal_cov) \n", @@ -392,7 +415,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "scan_onsets = np.int32(np.linspace(0, design.n_TR,num=n_run + 1)[: -1])\n", @@ -412,7 +437,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "\n", @@ -439,7 +466,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "fig = plt.figure(num=None, figsize=(4, 4), dpi=100)\n", @@ -475,7 +504,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "regressor = np.insert(design.design_task,\n", @@ -516,7 +547,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "fig = plt.figure(num=None, figsize=(5, 5), dpi=100)\n", @@ -540,7 +573,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "RMS_BRSA = np.mean((brsa.C_ - ideal_corr)**2)**0.5\n", @@ -572,7 +607,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "\n", @@ -603,7 +640,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "plt.scatter(betas_simulated, brsa.beta_)\n", @@ -635,7 +674,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "u, s, v = np.linalg.svd(noise + inten)\n", @@ -693,7 +734,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "noise_new = np.zeros([n_T, n_V])\n", @@ -756,7 +799,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "[score, score_null] = brsa.score(X=Y_new, design=design.design_task, scan_onsets=scan_onsets)\n", @@ -802,7 +847,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "\n", @@ -821,7 +868,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "plt.pcolor(np.reshape(gbrsa.nSNR_, (ROI_edge, ROI_edge*2)))\n", @@ -886,7 +935,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "# \"Decoding\"\n", diff --git a/tests/reprsimil/test_brsa.py b/tests/reprsimil/test_brsa.py index a34e2a188..21ec2877e 100755 --- a/tests/reprsimil/test_brsa.py +++ b/tests/reprsimil/test_brsa.py @@ -178,7 +178,7 @@ def test_fit(): rank = n_C - 1 n_nureg = 1 brsa = BRSA(rank=rank, n_nureg=n_nureg, tol=2e-3, - n_iter=4, init_iter=4, auto_nuisance=True) + n_iter=20, init_iter=4, auto_nuisance=True) brsa.fit(X=Y, design=design.design_task, scan_onsets=scan_onsets) # u_b = brsa.U_ u_i = ideal_cov From 2c9dcce1892dd2056533f031ad588f3f1759d334 Mon Sep 17 00:00:00 2001 From: Mingbo Cai Date: Fri, 16 Feb 2018 08:12:54 -0500 Subject: [PATCH 18/21] cleared printing lines --- brainiak/reprsimil/brsa.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/brainiak/reprsimil/brsa.py b/brainiak/reprsimil/brsa.py index 049190ce4..a978a1cae 100755 --- a/brainiak/reprsimil/brsa.py +++ b/brainiak/reprsimil/brsa.py @@ -3837,8 +3837,6 @@ def _raw_loglike_grids(self, L, s2XTAcorrX, YTAcorrY_diag, # In the equation of the log likelihood, this "denominator" # term is in fact divided by 2. But we absorb that into the # log fixted term. - print('YTAcorrY_diag', YTAcorrY_diag) - print('s2YTAcorrXL_LAMBDA_LTXTAcorrY', s2YTAcorrXL_LAMBDA_LTXTAcorrY) LL_raw = -half_log_det_X0TAX0[:, None] \ - half_log_det_LAMBDA_i[:, None] \ - (n_T - n_X0 - 2) / 2 * np.log(denominator) \ From fac727dfa0d568490a9ce993f8cc6a64a4d1eb5b Mon Sep 17 00:00:00 2001 From: Mingbo Cai Date: Tue, 20 Feb 2018 15:22:26 -0500 Subject: [PATCH 19/21] removed all description of default parameters, added newsfragments, reduced number of iteration in test code and increased that in brsa module. --- brainiak/reprsimil/brsa.py | 88 +++++++++--------- examples/reprsimil/bayesian_rsa_example.ipynb | 90 +++++-------------- examples/reprsimil/group_brsa_example.ipynb | 17 +++- tests/reprsimil/test_brsa.py | 2 +- 4 files changed, 81 insertions(+), 116 deletions(-) diff --git a/brainiak/reprsimil/brsa.py b/brainiak/reprsimil/brsa.py index a978a1cae..8aedef66f 100755 --- a/brainiak/reprsimil/brsa.py +++ b/brainiak/reprsimil/brsa.py @@ -166,7 +166,7 @@ def Ncomp_SVHT_MG_DLD_approx(X, zscore=True): X: 2-D numpy array of size [n_T, n_V] The data to estimate the optimal rank for selecting principal components. - zscore: Boolean, default: True + zscore: Boolean Whether to z-score the data before calculating number of components. Returns @@ -256,7 +256,7 @@ class BRSA(BaseEstimator, TransformerMixin): Parameters ---------- - n_iter : int. Default: 50 + n_iter : int. Number of maximum iterations to run the algorithm. rank : int. Default: None The rank of the covariance matrix. @@ -264,7 +264,7 @@ class BRSA(BaseEstimator, TransformerMixin): to be full rank. When you have many conditions (e.g., calculating the similarity matrix of responses to each event), you might try specifying a lower rank. - auto_nuisance: boolean. Default: True + auto_nuisance: boolean. In order to model spatial correlation between voxels that cannot be accounted for by common response captured in the design matrix, we assume that a set of time courses not related to the task @@ -286,7 +286,7 @@ class BRSA(BaseEstimator, TransformerMixin): Note that nuisance regressor is not required from user. If it is not provided, DC components for each run will be included as nuisance regressor regardless of the auto_nuisance parameter. - n_nureg: Optional[int]. Default: None + n_nureg: Optional[int]. Number of nuisance regressors to use in order to model signals shared across voxels not captured by the design matrix. This number is in addition to any nuisance regressor that the user @@ -296,7 +296,7 @@ class BRSA(BaseEstimator, TransformerMixin): and D Donoho's approximate estimation of optimal hard threshold for singular values. This only takes effect if auto_nuisance is True. - nureg_zscore: boolean, default: True + nureg_zscore: boolean. A flag to tell the algorithm whether data is z-scored before estimating the number of nuisance regressor components necessary to account for spatial noise correlation. It also determinie whether @@ -304,10 +304,10 @@ class BRSA(BaseEstimator, TransformerMixin): regressors from residual. This only takes effect if auto_nuisance is True. nureg_method: string, naming a method from sklearn.decomposition. - 'PCA', 'ICA', 'FA' or 'SPCA' are currently supported. Default: 'PCA' + 'PCA', 'ICA', 'FA' or 'SPCA' are currently supported. The method to estimate the shared component in noise across voxels. This only takes effect if auto_nuisance is True. - baseline_single: boolean, default: False + baseline_single: boolean. 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 @@ -326,7 +326,7 @@ class BRSA(BaseEstimator, TransformerMixin): run and when the design matrix in each run sums together close to a flat line, this option can cause the estimated similarity to be extremely high between conditions occuring in the same run. - GP_space: boolean. Default: False + GP_space: boolean. Whether to impose a Gaussion Process (GP) prior on the log(pseudo-SNR). If true, the GP has a kernel defined over spatial coordinate of each voxel. The idea behind this option is that @@ -335,7 +335,7 @@ class BRSA(BaseEstimator, TransformerMixin): is generally low, smoothness can be overestimated. But such regularization may reduce variance in the estimated SNR map and similarity matrix. - GP_inten: boolean. Defualt: False + GP_inten: boolean. Whether to include a kernel defined over the intensity of image. GP_space should be True as well if you want to use this, because the smoothness should be primarily in space. @@ -346,23 +346,23 @@ class BRSA(BaseEstimator, TransformerMixin): are close). If you accept the second assumption, then you can set GP_inten as True and provide an array to the `inten` variable, expressing the intensities (brightness) for each voxel. - space_smooth_range: float. Default: None + space_smooth_range: float. The distance (in unit the same as what you would use when supplying the spatial coordiates of each voxel, typically millimeter) which you believe is the maximum range of the length scale parameter of Gaussian Process defined over voxel location. This is used to impose a half-Cauchy prior on the length scale. - If not provided, the program will set it to half of the + If set to None, the program will default to half of the maximum distance between all voxels. - inten_smooth_range: float. Default: None + inten_smooth_range: float. The difference in image intensity which you believe is the maximum range of plausible length scale for the Gaussian Process defined over image intensity. Length scales larger than this are allowed, - but will be penalized. If not supplied, this parameter - will be set to half of the maximal intensity difference. - tau_range: float. Default: 5.0 + but will be penalized. If set to None, this parameter + will default to half of the maximal intensity difference. + tau_range: float. The reasonable range of the standard deviation of log(SNR). This range should not be too large. 5 is a loose range. @@ -394,16 +394,16 @@ class BRSA(BaseEstimator, TransformerMixin): from brainiak.reprsimil.brsa import BRSA, prior_GP_var_half_cauchy brsa = BRSA(tau2_prior=prior_GP_var_half_cauchy) - eta: float. Default: 0.0001 + eta: float. A small number added to the diagonal element of the covariance matrix in the Gaussian Process prior. This is to ensure that the matrix is invertible. - init_iter: int. Default: 20 + init_iter: int. How many initial iterations to fit the model without introducing the GP prior before fitting with it, if GP_space or GP_inten is requested. This initial fitting is to give the parameters a good starting point. - optimizer: str or callable. Default: 'L-BFGS-B' + optimizer: str or callable. The optimizer to use for minimizing cost function which scipy.optimize.minimize can accept. We use 'L-BFGS-B' as a default. Users can try other strings @@ -414,12 +414,12 @@ class BRSA(BaseEstimator, TransformerMixin): the fitting is likely to be unbarely slow. We do not calculate Hessian of the objective function. So an optimizer which requires Hessian cannot be used. - random_state : RandomState or an int seed. Default: None + random_state : RandomState or an int seed. A random number generator instance to define the state of the random permutations generator whenever the module needs to generate random number (e.g., initial parameter of the Cholesky factor). - anneal_speed: float. Default: 20 + anneal_speed: float. Annealing is introduced in fitting of the Cholesky decomposition of the shared covariance matrix. The amount of perturbation decays exponentially. This parameter sets @@ -439,7 +439,7 @@ class BRSA(BaseEstimator, TransformerMixin): have to be very large. In other words, scipy.optimize.minize does not need to converge within each step of the alternating fitting procedure. - tol: float. Default: 1e-4. + tol: float. Tolerance parameter passed to scipy.optimize.minimize. It is also used for determining convergence of the alternating fitting procedure. @@ -515,7 +515,7 @@ class BRSA(BaseEstimator, TransformerMixin): """ def __init__( - self, n_iter=80, rank=None, + self, n_iter=100, rank=None, auto_nuisance=True, n_nureg=None, nureg_zscore=True, nureg_method='PCA', baseline_single=False, GP_space=False, GP_inten=False, @@ -815,7 +815,7 @@ def transform(self, X, y=None, scan_onsets=None): (recommended) when fitting the model, data should be z-scored as well when calling transform() y : not used (as it is unsupervised learning) - scan_onsets : numpy array, shape=[number of runs]. Default: None. + scan_onsets : numpy array, shape=[number of runs]. A list of indices corresponding to the onsets of scans in the data X. If not provided, data will be assumed to be acquired in a continuous scan. @@ -889,16 +889,16 @@ def score(self, X, design, scan_onsets=None): design : numpy array, shape=[time_points, conditions] Design matrix expressing the hypothetical response of the task conditions in data X. - scan_onsets : numpy array, shape=[number of runs]. Default: None. + scan_onsets : numpy array, shape=[number of runs]. A list of indices corresponding to the onsets of scans in the data X. If not provided, data will be assumed to be acquired in a continuous scan. Returns ------- - ll: float, + ll: float. The log likelihood of the new data based on the model and its parameters fit to the training data. - ll_null: float, + ll_null: float. The log likelihood of the new data based on a null model which assumes the same as the full model for everything except for that there is no response to any of the @@ -2733,9 +2733,9 @@ class GBRSA(BRSA): Parameters ---------- - n_iter : int. Default: 50 + n_iter : int. Number of maximum iterations to run the algorithm. - rank : int. Default: None + rank : int. The rank of the covariance matrix. If not provided, the covariance matrix will be assumed to be full rank. When you have many conditions @@ -2747,7 +2747,7 @@ class GBRSA(BRSA): here for selecting hyperparameters such as rank. For any formal model comparison, we recommend using score() function on left-out data. - auto_nuisance: boolean. Default: True + auto_nuisance: Boolean. In order to model spatial correlation between voxels that cannot be accounted for by common response captured in the design matrix, we assume that a set of time courses not related to the task @@ -2769,7 +2769,7 @@ class GBRSA(BRSA): Note that nuisance regressor is not required from user. If it is not provided, DC components for each run will be included as nuisance regressor regardless of the auto_nuisance parameter. - n_nureg: Optional[int]. Default: None + n_nureg: Optional[int]. Number of nuisance regressors to use in order to model signals shared across voxels not captured by the design matrix. This number is in addition to any nuisance regressor that the user @@ -2780,7 +2780,7 @@ class GBRSA(BRSA): threshold for singular values. (Gavish & Donoho, IEEE Transactions on Information Theory 60.8 (2014): 5040-5053.) This only takes effect if auto_nuisance is True. - nureg_zscore: boolean, default: True + nureg_zscore: Boolean. A flag to tell the algorithm whether data is z-scored before estimating the number of nuisance regressor components necessary to account for spatial noise correlation. It also determinie whether @@ -2788,10 +2788,10 @@ class GBRSA(BRSA): regressors from residual. This only takes effect if auto_nuisance is True. nureg_method: string, naming a method from sklearn.decomposition. - 'PCA', 'ICA', 'FA' or 'SPCA' are currently supported. Default: 'PCA' + 'PCA', 'ICA', 'FA' or 'SPCA' are currently supported. The method to estimate the shared component in noise across voxels. This only takes effect if auto_nuisance is True. - baseline_single: boolean. Default: False + baseline_single: Boolean. 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 @@ -2810,7 +2810,7 @@ class GBRSA(BRSA): run and when the design matrix in each run sums together close to a flat line, this option can cause the estimated similarity to be extremely high between conditions occuring in the same run. - SNR_prior: string. Default: 'exp' + SNR_prior: string. The type of prior for pseudo-SNR. If set to 'exp', truncated exponential distribution with scale parameter of 1 is imposed on pseudo-SNR. @@ -2826,7 +2826,7 @@ class GBRSA(BRSA): In all the cases, the grids used for pseudo-SNR do not really set an upper bound for SNR, because the real SNR is determined by both pseudo-SNR and U, the shared covariance structure. - logS_range: float. Default: 1.0 + logS_range: float. The reasonable range of the spread of SNR in log scale. This parameter only takes effect if SNR_prior is set to 'lognorm'. It is effectively the `s` parameter of `scipy.stats.lognorm`, @@ -2842,7 +2842,7 @@ class GBRSA(BRSA): SNR_bins accordingly, otherwise the pseudo-SNR values evaluated might be too sparse, causing the posterior pseudo-SNR estimations to be clustered around the bins. - SNR_bins: integer. Default: 21 + SNR_bins: integer. The number of bins used to numerically marginalize the pseudo-SNR parameter. In general, you should try to choose a large number to the degree that decreasing SNR_bins does not change the result @@ -2852,12 +2852,12 @@ class GBRSA(BRSA): the default value of logS_range=1.0 and bin width of 0.3 on log scale. But it is also a reasonable choice for the other two options for SNR_prior. - rho_bins: integer. Default: 20 + rho_bins: integer. The number of bins to divide the region of (-1, 1) for rho. This only takes effect for fitting the marginalized version. If set to 20, discrete numbers of {-0.95, -0.85, ..., 0.95} will be used to numerically integrate rho from -1 to 1. - optimizer: str or callable. Default: 'L-BFGS-B' + optimizer: str or callable. The optimizer to use for minimizing cost function which scipy.optimize.minimize can accept. We use 'L-BFGS-B' as a default. Users can try other strings @@ -2869,8 +2869,6 @@ class GBRSA(BRSA): Hessian of the objective function. So an optimizer which requires Hessian cannot be used. minimize_options: dictionary. - Default: {'gtol': 1e-4, 'disp': False, - 'maxiter': 20} This is the dictionary passed as the options argument to scipy.optimize.minize which minimizes the cost function during fitting. Notice that the minimization is performed for up to @@ -2880,16 +2878,16 @@ class GBRSA(BRSA): 'maxiter' in this dictionary determines the maximum number of iteration done by scipy.optimize.minimize within each of the n_iter steps of fitting. - tol: float. Default: 1e-4. + tol: float. Tolerance parameter passed to scipy.optimize.minimize. It is also used for determining convergence of the alternating fitting procedure. - random_state : RandomState or an int seed. Default: None + random_state : RandomState or an int seed. A random number generator instance to define the state of the random permutations generator whenever the module needs to generate random number (e.g., initial parameter of the Cholesky factor). - anneal_speed: float. Default: 10 + anneal_speed: float. Annealing is introduced in fitting of the Cholesky decomposition of the shared covariance matrix. The amount of perturbation decays exponentially. This parameter sets @@ -2965,7 +2963,7 @@ class GBRSA(BRSA): """ def __init__( - self, n_iter=80, rank=None, + self, n_iter=100, rank=None, auto_nuisance=True, n_nureg=None, nureg_zscore=True, nureg_method='PCA', baseline_single=False, logS_range=1.0, SNR_prior='exp', @@ -4083,7 +4081,7 @@ def _bin_exp(self, n_bin, scale=1.0): ----------- n_bin: int The number of bins to approximate the exponential distribution - scale: float, default: 1.0 + scale: float. The scale parameter of the exponential distribution, defined in the same way as scipy.stats. It does not influence the ratios between the bins, but just controls the spacing between the bins. diff --git a/examples/reprsimil/bayesian_rsa_example.ipynb b/examples/reprsimil/bayesian_rsa_example.ipynb index cf94f1d9a..64e79e8e4 100644 --- a/examples/reprsimil/bayesian_rsa_example.ipynb +++ b/examples/reprsimil/bayesian_rsa_example.ipynb @@ -13,8 +13,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Please note that the model assumes that the covariance matrix U which all $\\beta_i$ follow is zero-meaned. This assumption does not imply there must be both positive and negative responses across voxels.\n", - "However, it means that Bayesian RSA treats the task-evoked activity against baseline BOLD level as signal, while in other RSA tools the deviation of task-evoked activity in each voxel from the average task-evoked activity level across voxels may be considered as signal of interest.\n", + "Please note that the model assumes that the covariance matrix U which all $\\beta_i$ follow describe a multi-variate Gaussian distribution that is zero-meaned. This assumption does not imply that there must be both positive and negative responses across voxels.\n", + "However, it means that (Group) Bayesian RSA treats the task-evoked activity against baseline BOLD level as signal, while in other RSA tools the deviation of task-evoked activity in each voxel from the average task-evoked activity level across voxels may be considered as signal of interest.\n", "Due to this assumption in (G)BRSA, relatively high degree of similarity may be expected when the activity patterns of two task conditions share a strong sensory driven components. When two task conditions elicit exactly the same activity pattern but only differ in their global magnitudes, under the assumption in (G)BRSA, their similarity is 1; under the assumption that only deviation of pattern from average patterns is signal of interest (which is currently not supported by (G)BRSA), their similarity would be -1 because the deviations of the two patterns from their average pattern are exactly opposite." ] }, @@ -30,9 +30,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", @@ -57,9 +55,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "logging.basicConfig(\n", @@ -97,9 +93,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "design = utils.ReadDesign(fname=\"example_design.1D\")\n", @@ -145,9 +139,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "noise_bot = 0.5\n", @@ -229,9 +221,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# import nibabel\n", @@ -255,9 +245,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# ideal covariance matrix\n", @@ -300,9 +288,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "L_full = np.linalg.cholesky(ideal_cov) \n", @@ -415,9 +401,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "scan_onsets = np.int32(np.linspace(0, design.n_TR,num=n_run + 1)[: -1])\n", @@ -437,9 +421,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "\n", @@ -466,9 +448,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(num=None, figsize=(4, 4), dpi=100)\n", @@ -504,9 +484,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "regressor = np.insert(design.design_task,\n", @@ -547,9 +525,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(num=None, figsize=(5, 5), dpi=100)\n", @@ -573,9 +549,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "RMS_BRSA = np.mean((brsa.C_ - ideal_corr)**2)**0.5\n", @@ -607,9 +581,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "\n", @@ -640,9 +612,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "plt.scatter(betas_simulated, brsa.beta_)\n", @@ -674,9 +644,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "u, s, v = np.linalg.svd(noise + inten)\n", @@ -734,9 +702,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "noise_new = np.zeros([n_T, n_V])\n", @@ -799,9 +765,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "[score, score_null] = brsa.score(X=Y_new, design=design.design_task, scan_onsets=scan_onsets)\n", @@ -847,9 +811,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "\n", @@ -868,9 +830,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "plt.pcolor(np.reshape(gbrsa.nSNR_, (ROI_edge, ROI_edge*2)))\n", @@ -935,9 +895,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# \"Decoding\"\n", @@ -973,7 +931,7 @@ "\n", "# cross-validataion\n", "[score, score_null] = gbrsa.score(X=[Y_new], design=[design.design_task], scan_onsets=[scan_onsets])\n", - "print(\"Score of full model based on the correct esign matrix, assuming {} nuisance\"\n", + "print(\"Score of full model based on the correct design matrix, assuming {} nuisance\"\n", " \" components in the noise: {}\".format(gbrsa.n_nureg_, score))\n", "print(\"Score of a null model with the same assumption except that there is no task-related response: {}\".format(\n", " score_null))\n", diff --git a/examples/reprsimil/group_brsa_example.ipynb b/examples/reprsimil/group_brsa_example.ipynb index 7173f8ba2..307e093ac 100644 --- a/examples/reprsimil/group_brsa_example.ipynb +++ b/examples/reprsimil/group_brsa_example.ipynb @@ -17,6 +17,15 @@ "## GBRSA and BRSA might not return exactly the same result. Which one is more accurate might depend on the parameter choice, as well as the property of data." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Please note that the model assumes that the covariance matrix U which all $\\beta_i$ follow describe a multi-variate Gaussian distribution that is zero-meaned. This assumption does not imply that there must be both positive and negative responses across voxels.\n", + "However, it means that (Group) Bayesian RSA treats the task-evoked activity against baseline BOLD level as signal, while in other RSA tools the deviation of task-evoked activity in each voxel from the average task-evoked activity level across voxels may be considered as signal of interest.\n", + "Due to this assumption in (G)BRSA, relatively high degree of similarity may be expected when the activity patterns of two task conditions share a strong sensory driven components. When two task conditions elicit exactly the same activity pattern but only differ in their global magnitudes, under the assumption in (G)BRSA, their similarity is 1; under the assumption that only deviation of pattern from average patterns is signal of interest (which is currently not supported by (G)BRSA), their similarity would be -1 because the deviations of the two patterns from their average pattern are exactly opposite." + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -405,7 +414,7 @@ "The nuisance regressors in typical fMRI analysis (such as head motion signal) are replaced by principal components estimated from residuals after subtracting task-related response. `n_nureg` tells the model how many principal components to keep from the residual as nuisance regressors, in order to account for spatial correlation in noise. When it is set to None and `auto_nuisance=True`, this number will be estimated automatically by an algorithm of Gavish & Dohono 2014. If you prefer not using this approach based on principal components of residuals, you can set `auto_nuisance=False`, and optionally provide your own nuisance regressors as a list (one numpy array per subject) as nuisance argument to GBRSA.fit(). In practice, we find that the result is much better with `auto_nuisance=True`.\n", "\n", "The idea of modeling the spatial noise correlation with the principal component decomposition of the residual noise is similar to that in GLMdenoise (http://kendrickkay.net/GLMdenoise/).\n", - "Apparently one can imagine that the choice of the number of principal components used as nuisance regressors can influence the result. If you just choose 1 or 2, perhaps only the global drift would be captured. But including too many nuisance regressors would slow the fitting speed and might have risk of overfitting. Among all the algorithms we have tested with simulation data, th Gavish & Donoho algorithm appears the most robust and the estimate is closest to the true simulated number. But it does have a tendency to under-estimate the number of components, which is one limitation in (G)BRSA module." + "Apparently one can imagine that the choice of the number of principal components used as nuisance regressors can influence the result. If you just choose 1 or 2, perhaps only the global drift would be captured. But including too many nuisance regressors would slow the fitting speed and might have risk of overfitting. Among all the algorithms we have tested with simulation data, the Gavish & Donoho algorithm appears the most robust and the estimate is closest to the true simulated number. But it does have a tendency to under-estimate the number of components, which is one limitation in (G)BRSA module." ] }, { @@ -768,7 +777,7 @@ "[score, score_null] = gbrsa.score(X=Y_new, design=[d.design_task for d in design], scan_onsets=scan_onsets)\n", "\n", "plt.bar(np.arange(n_subj),np.asarray(score)-np.asarray(score_null), width=width)\n", - "plt.ylim(np.min([np.asarray(score)-np.asarray(score_null)])-100, np.max([np.asarray(score)-np.asarray(score_null)])+100)\n", + "plt.ylim(0, np.max([np.asarray(score)-np.asarray(score_null)])+100)\n", "plt.ylabel('cross-validated log likelihood')\n", "plt.xlabel('partipants')\n", "plt.title('Difference between cross-validated log likelihoods\\n of full model and null model\\non new data containing signal')\n", @@ -779,7 +788,7 @@ "\n", "plt.bar(np.arange(n_subj),np.asarray(score_noise)-np.asarray(score_null_noise), width=width)\n", "plt.ylim(np.min([np.asarray(score_noise)-np.asarray(score_null_noise)])-100,\n", - " np.max([np.asarray(score_noise)-np.asarray(score_null_noise)])+100)\n", + " 0)\n", "plt.ylabel('cross-validated log likelihood')\n", "plt.xlabel('partipants')\n", "plt.title('Difference between cross-validated log likelihoods\\n of full model and null model\\non pure noise')\n", @@ -800,7 +809,7 @@ "metadata": {}, "outputs": [], "source": [ - "gbrsa_noise = GBRSA()\n", + "gbrsa_noise = GBRSA(n_iter=40)\n", "gbrsa_noise.fit(X=[noise[s] + inten[s] for s in range(n_subj)],\n", " design=[d.design_task for d in design],scan_onsets=scan_onsets)\n", "Y_nosignal = [noise_new[s] + inten[s] for s in range(n_subj)]\n", diff --git a/tests/reprsimil/test_brsa.py b/tests/reprsimil/test_brsa.py index 21ec2877e..fbf898b86 100755 --- a/tests/reprsimil/test_brsa.py +++ b/tests/reprsimil/test_brsa.py @@ -178,7 +178,7 @@ def test_fit(): rank = n_C - 1 n_nureg = 1 brsa = BRSA(rank=rank, n_nureg=n_nureg, tol=2e-3, - n_iter=20, init_iter=4, auto_nuisance=True) + n_iter=8, init_iter=4, auto_nuisance=True) brsa.fit(X=Y, design=design.design_task, scan_onsets=scan_onsets) # u_b = brsa.U_ u_i = ideal_cov From 8d9697ceb00c6218f5b00ca11ba45d8ab9dc6a40 Mon Sep 17 00:00:00 2001 From: Mingbo Cai Date: Tue, 20 Feb 2018 15:53:15 -0500 Subject: [PATCH 20/21] removing trailing whitespace --- brainiak/reprsimil/brsa.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brainiak/reprsimil/brsa.py b/brainiak/reprsimil/brsa.py index 8aedef66f..c0cbd37d8 100755 --- a/brainiak/reprsimil/brsa.py +++ b/brainiak/reprsimil/brsa.py @@ -2733,7 +2733,7 @@ class GBRSA(BRSA): Parameters ---------- - n_iter : int. + n_iter : int. Number of maximum iterations to run the algorithm. rank : int. The rank of the covariance matrix. From 2af9eddb8fae86bff739f1b3dfc423f0e46a5356 Mon Sep 17 00:00:00 2001 From: Mingbo Cai Date: Tue, 20 Feb 2018 18:18:46 -0500 Subject: [PATCH 21/21] add newsfragments --- docs/newsfragments/337.trivial | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 docs/newsfragments/337.trivial diff --git a/docs/newsfragments/337.trivial b/docs/newsfragments/337.trivial new file mode 100644 index 000000000..ad12a8e12 --- /dev/null +++ b/docs/newsfragments/337.trivial @@ -0,0 +1,4 @@ +* Change the default optimizer of (G)BRSA to 'L-BFGD-B'. +* Removed all the description of default parameters in docstring of brsa module. +* Increased the default number of iteration for BRSA and GBRSA +* Added explanation in docstring and example that both BRSA and GBRSA assume zero-mean in the distribution of beta patterns.