Repository navigation
Adding ISC and ISFC - #183
Conversation
|
The code looks great! I will make some suggestions to improve readability. |
| group = np.mean(D[:, :, np.arange(n_subj) != loo_subj], axis=2) | ||
| subj = D[:, :, loo_subj] | ||
| for v in range(n_vox): | ||
| ISC[v, loo_subj] = stats.pearsonr(group[v, :], subj[v, :])[0] |
There was a problem hiding this comment.
Why don't you use fcma.util.compute_correlation here as well? If it is because of the data layouts, you can simply convert them accordingly. I believe even adding the layout conversion time up, the overall running time should outperform scipy.stats.pearsonr.
There was a problem hiding this comment.
@yidawang, is this what you had in mind? I though you meant it would be better to make single call to compute_correlation per subject.
There was a problem hiding this comment.
I don't think that is possible (@yidawang, correct me if I'm wrong) - compute_correlation computes correlations between all pairs of vectors, while for ISC we only need correlations between corresponding pairs (i.e. the diagonal of what compute_correlation returns).
There was a problem hiding this comment.
If this is the case, calling scipy.stats.pearsonr is fine with me.
There was a problem hiding this comment.
Then it is probably best to revert to the original code, for clarity.
There was a problem hiding this comment.
Yes, reverting it would be better in terms of performance as well. Sorry for the confusion, I didn't fully get what you are doing in the beginning. @cbaldassano
There was a problem hiding this comment.
I've just tested this, and yes it is much faster to use pearsonr in this case, so I've reverted the change.
|
|
||
| Parameters | ||
| ---------- | ||
| data_files : list of filenames of subject nii files |
There was a problem hiding this comment.
Please document the required data shape.
There was a problem hiding this comment.
This is just a base python list, so it is 1D
There was a problem hiding this comment.
That is clear, but what is the expected shape of the data inside the nii files?
There was a problem hiding this comment.
Ah sorry, I've clarified in the comments now
| ------- | ||
| (D, coords) : tuple of voxel by time by subject ndarray, and | ||
| x,y,x (as provided by nibabel) coordinates of voxel locations (as a | ||
| tuple of ndarrays |
There was a problem hiding this comment.
I think the coords type and meaning could be clearer. Please document D and coords separately, using the expected style, i.e., one line for the type and separate text for the meaning.
| n_vox = D.shape[0] | ||
| n_subj = D.shape[2] | ||
| ISFC = np.zeros((n_vox, n_vox, n_subj)) | ||
| for loo_subj in range(D.shape[2]): |
There was a problem hiding this comment.
Is loo an abbreviation for index? If so, could you please replace it with a more common abbreviation, e.g., subj_idx?
There was a problem hiding this comment.
loo is short for leave-one-out, which I've now clarified in a comment
| subj = D[:, :, loo_subj] | ||
| ISFC[:, :, loo_subj] = compute_correlation(group, subj) | ||
| ISFC[:, :, loo_subj] = (ISFC[:, :, loo_subj] + | ||
| ISFC[:, :, loo_subj].T) / 2 |
There was a problem hiding this comment.
Could you please add a comment describing this operation?
| import numpy as np | ||
| from matplotlib import pyplot as plt | ||
| from scipy.cluster.hierarchy import fcluster, linkage | ||
| import sys, os |
There was a problem hiding this comment.
Imports should be on separate lines.
| ISC_vol = np.zeros(brain_nii.shape) | ||
| ISC_vol[coords] = ISC | ||
| ISC_nifti = nib.Nifti1Image(ISC_vol, | ||
| brain_nii.get_affine(), brain_nii.header) |
There was a problem hiding this comment.
get_affine() is deprecated; use affine:
http://nipy.org/nibabel/reference/nibabel.spatialimages.html#nibabel.spatialimages.SpatialImage.get_affine
| print('Calculating ISFC on ', np.sum(ISC_mask), ' voxels...') | ||
| D_masked = D[ISC_mask, :, :] | ||
| ISFC = brainiak.isfc.isfc(D_masked) | ||
| coords_ISFC = [x[ISC_mask] for x in coords] |
| z = fcluster(Z, 2, criterion='maxclust') | ||
| clust_inds = np.argsort(z) | ||
|
|
||
| plt.imshow(ISFC[np.ix_(clust_inds,clust_inds)]) |
There was a problem hiding this comment.
Could you please add a comment explaining briefly what the image shows?
| Functions for computing intersubject correlation (ISC) and intersubject | ||
| functional correlation (ISFC), and utility functions for loading subject data | ||
| files and masks | ||
| """ |
There was a problem hiding this comment.
Please add references to papers.
|
|
||
| ISFC = brainiak.isfc.isfc(D) | ||
|
|
||
| gt = \ |
|
Hmm, the macos build is failing but it is working fine on my laptop. If I click Details, I get a permissions error "chrisb is missing the Overall/Read permission" so I'm not able to see what is going wrong. |
|
As the commiter, you should have received an email from Jenkins with the output. (The Princeton Jenkins administrator does not have a solution for allowing the public to view the output yet.) The problem is your usage of |
|
I fixed the compute_correlation issue in the most recent commit c811e7c but the builds are still failing. I've never gotten email from Jenkins, is there a way to see what email it is sending to? My local git email might not be set correctly? |
|
The email address is extracted from the commit, so you should make sure it is valid. The error now is: |
|
Ok, fixed - forgot that run-tests didn't also run the static code checker. I have my local email set up correctly now, so hopefully Jenkins will send me emails now. |
|
During the last commit one of the Travis builds ended in an error due to a timeout on the server - hopefully it goes through successfully this time, otherwise it might need to manually re-run in some way. |
|
@cbaldassano, I am ready to merge this. However, we need to update it with the latest commits from master. Usually, I would just use the "Update branch" button on GitHub to update it myself, but I noticed you are using your master branch instead of a branch specifically created for this PR. Can you please do the update? |
Bringing fork up to date with master
|
OK I think my fork is now up to date and should be mergeable by @mihaic |
Search PATH in addition to current directory for executables
* Make numpy arrays immutable in numbuf * Move break statement outside of brackets * Simplify test case * Simplify test case
I've added some simple functions for computing ISC and ISFC, taking advantage of the optimized correlation engine from FCMA. I also wrote a utility function for loading a set of masked subject data for use with these functions. Per the contributing doc, I've put these functions in a single file rather than a submodule.