Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recent work to BRSA #194

Merged
merged 154 commits into from Aug 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
e4ab872
a
Sep 2, 2016
06c869a
deleted: brsa/test.txt
Sep 2, 2016
9b0819c
Merge remote-tracking branch 'upstream/master'
Sep 22, 2016
7766c2b
Merge remote-tracking branch 'upstream/master'
Sep 28, 2016
89dc1e1
Merge remote-tracking branch 'upstream/master'
Oct 13, 2016
ea5b572
Merge remote-tracking branch 'upstream/master'
Oct 24, 2016
f65a42f
Merge remote-tracking branch 'upstream/master'
Nov 1, 2016
ea7b002
a
Sep 2, 2016
ad3af51
deleted: brsa/test.txt
Sep 2, 2016
4fec06f
Merge branch 'master' of https://github.com/lcnature/brainiak
Nov 1, 2016
66277e6
a
Sep 2, 2016
1b6127a
deleted: brsa/test.txt
Sep 2, 2016
4b1a794
a
Sep 2, 2016
2ded8db
deleted: brsa/test.txt
Sep 2, 2016
9ac940d
Merge remote-tracking branch 'refs/remotes/origin/master'
Nov 1, 2016
66ebf5f
a
Sep 2, 2016
6a24344
deleted: brsa/test.txt
Sep 2, 2016
746f66e
a
Sep 2, 2016
9fad12b
deleted: brsa/test.txt
Sep 2, 2016
92a199b
a
Sep 2, 2016
5265476
deleted: brsa/test.txt
Sep 2, 2016
3acf09f
a
Sep 2, 2016
bc49c16
deleted: brsa/test.txt
Sep 2, 2016
973bd92
Merge remote-tracking branch 'refs/remotes/origin/master'
Nov 1, 2016
f288c31
forcing scan_onsets to be integer
Nov 1, 2016
accb974
make scan_onsets integers as well in example
Nov 1, 2016
eed8ee8
Merge branch 'master' into add_transform_brsa
mihaic Nov 1, 2016
0e7029f
Merge pull request #1 from mihaic/add_transform_brsa
lcnature Nov 1, 2016
057deb0
Add transform function
Nov 21, 2016
e02d5a0
Adding marginalized version of BRSA
Nov 30, 2016
ceed81d
not finished
Dec 2, 2016
dab73e7
Adding group BRSA
Dec 16, 2016
16b5933
minor changes
Dec 16, 2016
aa8a540
new example for GBRSA
Dec 16, 2016
8e0eca4
correcting a bug of matrix size
Dec 16, 2016
4dd6b16
Cleaning brsa.py
Dec 22, 2016
c23ac2d
updating local changes made a while ago
Jan 10, 2017
1b87212
Making transform function not use private variable
Jan 23, 2017
8289f44
Merge branch 'master' of https://github.com/IntelPNI/brainiak
Jan 23, 2017
a5f9836
Merge branch 'master' of https://github.com/IntelPNI/brainiak into ad…
Jan 23, 2017
ab2fc0f
Merge branch 'master' of https://github.com/IntelPNI/brainiak
Jan 26, 2017
21ae9b6
Merge branch 'master' of https://github.com/IntelPNI/brainiak
Jan 30, 2017
7ca085e
working on forward step
Feb 13, 2017
f93fab9
forward step finished
Feb 13, 2017
2968cd1
Added backward step
Feb 14, 2017
64b58ed
working on score function
Feb 22, 2017
4d74871
finishing the score function
Feb 23, 2017
9655042
Finished the score and transform functions for both BRSA and GBRSA. C…
Feb 27, 2017
1cea980
one commit before trying autopep8
Mar 1, 2017
778ac7d
passed checks
Mar 2, 2017
eaafbd2
finished
Mar 4, 2017
149c37e
stripped the example notebookx
Mar 4, 2017
d6d4e97
merge
Mar 4, 2017
756c8df
add gest_gbrsa.py
Mar 4, 2017
a2309ce
cleaned test code
Mar 4, 2017
ec2ab08
adding some comments
Mar 4, 2017
e284a48
changes in accordance to the comments
Mar 8, 2017
f861056
add reference to BRSA within GBRSA
Mar 8, 2017
4c78752
add back one test to increase coverage of test
Mar 8, 2017
324ee0e
correcting test_brsa.py
Mar 8, 2017
7f7aecf
adding one blank line to score()
Mar 8, 2017
53d0a49
trying to further reduce test time
Mar 8, 2017
0cac292
adding more blank lines...
Mar 8, 2017
bf4c646
Fix Sphinx errors
mihaic Mar 8, 2017
ca7ead1
Merge pull request #2 from mihaic/add_transform_brsa_fix_sphinx
lcnature Mar 8, 2017
4dc630f
add requirements for brsa example
Mar 8, 2017
9716eb4
change back to accepting only strong for nureg_method
Mar 8, 2017
5c2b5e4
change to argument tau2_prior
Mar 10, 2017
18e9db5
basically no change to test again
Mar 11, 2017
ada6841
debugging test failure
Mar 12, 2017
3fabc50
removed print()
Mar 12, 2017
6bef0a1
test what is different on the server
Mar 12, 2017
0974850
test server
Mar 12, 2017
1b3dc06
resubmit
Mar 12, 2017
7687ebe
changed gen_DF
Mar 12, 2017
a168632
changed all use of scipy.linalg.block_diag due to different behavior …
Mar 12, 2017
6eebc78
changes to the docstring
Mar 12, 2017
81cd751
uncomment out one test
Mar 12, 2017
1498229
Made description of the prior_var_GP* functions more generic, changed…
Mar 14, 2017
3784bfd
cut the docstring for prior_GP_var_half_cauchy
Mar 15, 2017
4ff14f8
correct a typo
Mar 15, 2017
99b55a1
change docstring of prior_GP_var_half_cauchy
Mar 17, 2017
b0dbd82
changed score() to make sure scan_onsets is initialized to an array o…
Mar 18, 2017
d1b9501
Additional change to utils.gen_design to make sure that the generated…
Mar 20, 2017
979cd82
Merge remote-tracking branch 'remotes/upstream/master'
Mar 22, 2017
8dcf274
changed example names and simplified _prepare_DF
Mar 22, 2017
d6c6cb8
Merge branch 'master' into add_transform_brsa
lcnature Mar 22, 2017
1139445
changed docstrings related to priors of tau
Mar 22, 2017
bd3bc01
changed docstrings related to priors of tau
Mar 22, 2017
4f78da8
changing default of PCA to whiten the output
Mar 23, 2017
e92ef57
fixed issue with scan_onsets in GBRSA.score() and changed some text i…
Mar 23, 2017
944f0e1
added two prior functions to __all__ of brsa.py. Changed default anne…
Mar 24, 2017
ece81da
remove blank line
Mar 24, 2017
2acd7b6
move the location of input checking in GBRSA
Mar 24, 2017
fe9f954
correcting typo
Mar 31, 2017
7c57abd
add one check for scan_onsets in _fit_RSA_marginalized_null
Apr 4, 2017
733812f
Merge branch 'master' into add_transform_brsa
lcnature Apr 11, 2017
d250e29
Merge branch 'add_transform_brsa' of https://github.com/lcnature/brai…
Apr 12, 2017
741b9ee
Merge remote-tracking branch 'upstream/master'
Apr 12, 2017
bc29bf1
Merge branch 'master' into add_transform_brsa
Apr 12, 2017
cd28f83
Add automatic determination of nuisance regressor numbers based on BIC
Apr 12, 2017
c24d70e
correcting a but introduced to test_brsa.py
Apr 13, 2017
5ada11e
changed number of observations to n_T*n_V
Apr 13, 2017
1188d53
changed some recommendations in the example of (g)brsa
Apr 19, 2017
4664daf
Merge branch 'master' into add_transform_brsa
lcnature May 31, 2017
7e9dbe7
adding Ncomp_SVHT_MG_DLD_approx to brsa.py, and a few other changes f…
May 31, 2017
db2990d
fixed a bug
May 31, 2017
30e3085
incorporating some changes in test_gbrsa into add_transform_brsa whil…
Jun 4, 2017
1506c45
remove redundant sentence in docstring of GBRSA
Jun 4, 2017
b7097f7
reducing complexity of _fit_RSA_marginalized
Jun 4, 2017
50f8820
changed the default method for estimating number of nuisance regresso…
Jun 6, 2017
92bd91f
increase test code coverage for reprsimil
Jun 6, 2017
c225f15
add the two Ncomp functions to the modules listed in __all__ of reprs…
Jun 8, 2017
2cf748b
Merge remote-tracking branch 'upstream/master' into add_transform_brsa
Jun 8, 2017
ea56834
correct docstrings of Ncomp functions
Jun 8, 2017
93cc5c5
fix a bug introduced in the previous version
Jun 9, 2017
6201378
added test for estimating n_nureg_
Jun 9, 2017
b2576ad
add checking for NaN after performing zscore, by adding a customized …
Jun 19, 2017
c672dee
_zscore does not solve the problem. If there is no fluctuation in som…
Jun 19, 2017
3cbad44
implementing some of the suggested changes in pull request
Jun 27, 2017
1b388fb
partial update thanksto some of the comments
Jun 28, 2017
73703f2
fixing docstring problem
Jun 28, 2017
e9909ec
continue debugging docstring
Jun 28, 2017
9689b99
trying to figure out what is wrong with docstring
Jun 28, 2017
85d3ac4
still debugging docstring
Jun 28, 2017
70afe3c
Merge remote-tracking branch 'upstream/master' into add_transform_brsa
Jun 29, 2017
7ac0f17
fix trailing underscore issue
Jun 29, 2017
a414f4f
remove filtering of warnings
Jun 29, 2017
3189ac6
remove import of warnings in brsa
Jun 29, 2017
42e823b
stripped brsa example outputs
Jun 29, 2017
068ced1
more changes according to the code review
Jun 30, 2017
060c706
add more explanation to GP_inten
Jul 5, 2017
28e799a
Changed the default optimizer of GBRSA back to BFGS. This is because …
Jul 5, 2017
dbbfdb8
make sure n_nureg_ is integer in BRSA
Jul 8, 2017
1ccab03
Changed the parameter name DC_single to baseline_single, and changed …
Jul 10, 2017
3fb031f
changed default of nureg_method to PCA
Jul 12, 2017
0c47ede
add checking for SNR_prior
Jul 12, 2017
37f4b22
add comment in _set_SNR_grids
Jul 12, 2017
60593af
corrected for formatting of the comment
Jul 12, 2017
5c87f1e
Merge remote-tracking branch 'upstream/master'
Jul 13, 2017
34af3ac
Merge remote-tracking branch 'upstream/master'
Jul 14, 2017
b918ccb
merged the change in upstream/master
Jul 14, 2017
c34745c
fixed some docstring according to the PR. Isolated the work of creati…
Jul 20, 2017
2e4bb88
renamed test_grid_flatten to test_grid_flatten_num_int
Jul 20, 2017
1545313
in test_grid_flatten_num_int() of test_gbrsa.py(), condense all codes…
Jul 20, 2017
8dd02ca
Merge remote-tracking branch 'remotes/upstream/master'
Jul 31, 2017
5177839
Merge branch 'master' into add_transform_brsa
Jul 31, 2017
9b6ed41
added feature description for this pull-request
Jul 31, 2017
af9fe57
addressed recent comment of brsa, moved CoM_exp function from reprsim…
Aug 9, 2017
e9b41cc
added one sentence
Aug 9, 2017
d5872a2
changing one line to pass run-checks
Aug 9, 2017
60f04e5
replaced the phrase "refreshing noise" by "innovation noise"
Aug 9, 2017
c131485
changed some typo and docstrings
Aug 9, 2017
b665e6b
Merge branch 'master' into add_transform_brsa
mihaic Aug 9, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3,185 changes: 2,841 additions & 344 deletions brainiak/reprsimil/brsa.py

Large diffs are not rendered by default.

68 changes: 58 additions & 10 deletions brainiak/utils/utils.py
Expand Up @@ -319,6 +319,7 @@ def read_afni(self, fname):


def gen_design(stimtime_files, scan_duration, TR, style='FSL',
temp_res=0.01,
hrf_para={'response_delay': 6, 'undershoot_delay': 12,
'response_dispersion': 0.9,
'undershoot_dispersion': 0.9,
Expand Down Expand Up @@ -389,6 +390,14 @@ def gen_design(stimtime_files, scan_duration, TR, style='FSL',
means an event starting at 3.0s, lasting for 1.0s, with
amplitude modulation of 1.0.

temp_res: float, default: 0.01
Temporal resolution of fMRI, in second.

hrf_para: dictionary
The parameters of the double-Gamma hemodynamic response function.
To set different parameters, supply a dictionary with
the same set of keys as the default, and replace the corresponding
values with the new values.

Returns
-------
Expand Down Expand Up @@ -433,21 +442,28 @@ def gen_design(stimtime_files, scan_duration, TR, style='FSL',
onsets=design_info[i_s][i_c]['onset'],
event_durations=design_info[i_s][i_c]['duration'],
total_time=scan_duration[i_s],
weights=design_info[i_s][i_c]['weight'])
weights=design_info[i_s][i_c]['weight'],
temporal_resolution=1.0/temp_res)
design[i_s][:, i_c] = double_gamma_hrf(
stimfunction, TR, response_delay=response_delay,
undershoot_delay=undershoot_delay,
response_dispersion=response_dispersion,
undershoot_dispersion=undershoot_dispersion,
undershoot_scale=undershoot_scale, scale_function=0)
undershoot_scale=undershoot_scale, scale_function=0,
temporal_resolution=1.0/temp_res) * temp_res
# We multiply the resulting design matrix with
# the temporal resolution to normalize it.
# We do not use the internal normalization
# in double_gamma_hrf because it does not guarantee
# normalizing with the same constant.
return np.concatenate(design, axis=0)


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])
of dictionary including onsets, durations and weights of each event.
""" 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])
of dictionary including onsets, durations and weights of each event.

Parameters
----------
Expand Down Expand Up @@ -512,10 +528,10 @@ 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]``)
of dictionary including onsets, durations and weights of each event.
""" 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]``)
of dictionary including onsets, durations and weights of each event.

Parameters
----------
Expand Down Expand Up @@ -585,3 +601,35 @@ def _read_stimtime_AFNI(stimtime_files, n_C, n_S, scan_onoff):
design_info[i_s][i_c]['duration'].append(duration)
design_info[i_s][i_c]['weight'].append(weight)
return design_info


def center_mass_exp(a, b, scale=1.0):
""" Calculate the center of mass of negative exponential distribution
p(x) = exp(-x / scale) / scale
in the interval of (a, b). scale is the same scale
parameter as scipy.stats.expon.pdf

Parameters
----------
a: float
The starting point of the interval in which the center of mass
is calculated for exponential distribution.
b: float
The ending point of the interval in which the center of mass
is calculated for exponential distribution.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scale is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

scale: float
The scale parameter of the exponential distribution. See above.

Returns
-------
m: float
The center of mass in the interval of (a, b) for exponential
distribution.
"""
assert a < b, 'a must be smaller than b'
if b < np.inf:
return ((a + scale) * np.exp(-a / scale)
- (scale + b) * np.exp(-b / scale)) \
/ (np.exp(-a / scale) - np.exp(-b / scale))
else:
return a + scale
2 changes: 2 additions & 0 deletions docs/newsfragments/194.feature
@@ -0,0 +1,2 @@
reprsimil: add Group Bayesian RSA, add transform (decoding) and score (model selection) functions, add automatic determination of the number of necessary nuisance regressors.
utils: modified gen_design to make the generated design matrix approximately scaled in amplitudes.