-
Notifications
You must be signed in to change notification settings - Fork 137
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
Adding statistical tests to ISC and ISFC #310
Conversation
brainiak/isfc.py
Outdated
pos_freq = np.arange(1, (D.shape[1] - 1) // 2 + 1) | ||
neg_freq = np.arange(D.shape[1] - 1, (D.shape[1] - 1) // 2, -1) | ||
|
||
shift = np.random.rand(D.shape[0], len(pos_freq), D.shape[2]) * 2 * math.pi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to avoid np.random.rand
in favor of np.random.RandomState.rand
, according to the Scikit-learn guidelines:
https://github.com/brainiak/brainiak/blob/master/CONTRIBUTING.rst#standards
http://scikit-learn.org/stable/developers/contributing.html#random-numbers
tests/isfc/test_isfc.py
Outdated
D[:, :, 2] = \ | ||
[[-0.26593192, -0.56914734, 0.28397317, 0.30276589, -0.42637472], | ||
[-0.67598379, -0.51549055, -0.64196342, 1.60686666, 0.04127293]] | ||
[0.04127293, -0.67598379, -0.51549055, -0.64196342, 1.60686666]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the reordering necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment to clarify, I wanted to create a null ISC to make sure it was not significant.
tests/isfc/test_isfc.py
Outdated
@@ -35,13 +40,20 @@ def test_ISFC(): | |||
|
|||
assert D.shape == (4, 5, 2), "Loaded data has incorrect shape" | |||
|
|||
ISFC = brainiak.isfc.isfc(D) | |||
np.random.seed(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to remove this seed setting when you switch to using RandomState
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you actually forget to remove the line? :)
brainiak/isfc.py
Outdated
return ISFC, p | ||
|
||
|
||
def phase_randomize(D): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is not really ISFC specific. I think it fits better in utils/utils.py
.
brainiak/isfc.py
Outdated
back into the time domain. This yields timecourses with the same power | ||
spectrum (and thus the same autocorrelation) as the original timecourses, | ||
but will remove any meaningful temporal relationships between the | ||
timecourses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a paper reference by any chance?
brainiak/isfc.py
Outdated
return np.real(ifft(F, axis=1)) | ||
|
||
|
||
def ecdf(x): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utils/utils.py
?
brainiak/isfc.py
Outdated
return ISFC[..., 0] | ||
|
||
|
||
def p_from_null(X, two_sided=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function also belongs in utils/utils.py
.
tests/isfc/test_isfc.py
Outdated
@@ -35,13 +40,20 @@ def test_ISFC(): | |||
|
|||
assert D.shape == (4, 5, 2), "Loaded data has incorrect shape" | |||
|
|||
ISFC = brainiak.isfc.isfc(D) | |||
np.random.seed(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you actually forget to remove the line? :)
@@ -667,3 +671,78 @@ def usable_cpu_count(): | |||
except AttributeError: | |||
result = os.cpu_count() | |||
return result | |||
|
|||
|
|||
def phase_randomize(D, random_state=0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests for the new functions. They can be as simple as you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the prompt changes, @cbaldassano.
Adding statistical testing through phase randomization, as requested by https://groups.google.com/forum/#!topic/brainiak/vZnOgGoV7q4 and as described in Simony et al. (2015, DOI: 10.1038/ncomms12141)