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

replace sklearn's deprecated RandomizedPCA with PCA #87

Merged
merged 2 commits into from Nov 26, 2018
Merged
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions neurosynth/analysis/cluster.py
Expand Up @@ -85,6 +85,9 @@ def magic(dataset, method='coactivation', roi_mask=None,
'studies': Treat each study as a feature in an n-dimensional space.
I.e., voxels will be assigned to the same cluster if they tend
to be co-reported in similar studies.
'features': Voxels will be assigned to the same cluster if they
tend to have similar feature vectors (i.e., the studies that
activate those voxels tend to use similar terms).
roi_mask: A string, nibabel image, or numpy array providing an
inclusion mask of voxels to cluster. If None, the default mask
in the Dataset instance is used (typically, all in-brain voxels).
Expand Down Expand Up @@ -158,12 +161,19 @@ def magic(dataset, method='coactivation', roi_mask=None,
reference = roi

if reduce_reference is not None:

if isinstance(reduce_reference, string_types):

# Number of components can't exceed feature count or cluster count
n_feat = reference.data.shape[1]
n_components = min(n_components, n_feat)

reduce_reference = {
'pca': sk_decomp.RandomizedPCA,
'pca': sk_decomp.PCA,
'ica': sk_decomp.FastICA
}[reduce_reference](n_components)

# For non-coactivation-based approaches, transpose the data matrix
transpose = (method == 'coactivation')
reference = reference.transform(reduce_reference, transpose=transpose)

Expand All @@ -181,7 +191,6 @@ def magic(dataset, method='coactivation', roi_mask=None,
}[clustering_algorithm](n_clusters, **clustering_kwargs)

labels = clustering_algorithm.fit_predict(distances) + 1.

header = roi.masker.get_header()
header['cal_max'] = labels.max()
header['cal_min'] = labels.min()
Expand Down