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

[REF] Rename kernel_estimator attribute to kernel_transformer #197

Merged
merged 1 commit into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions nimare/meta/cbma/ale.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class ALE(CBMAEstimator):

Parameters
----------
kernel_estimator : :obj:`nimare.meta.cbma.base.KernelTransformer`, optional
kernel_transformer : :obj:`nimare.meta.cbma.base.KernelTransformer`, optional
Kernel with which to convolve coordinates from dataset. Default is
ALEKernel.
**kwargs
Keyword arguments. Arguments for the kernel_estimator can be assigned
Keyword arguments. Arguments for the kernel_transformer can be assigned
here, with the prefix '\kernel__' in the variable name.

Notes
Expand All @@ -62,29 +62,29 @@ class ALE(CBMAEstimator):
.. [3] Eickhoff, Simon B., et al. "Activation likelihood estimation
meta-analysis revisited." Neuroimage 59.3 (2012): 2349-2361.
"""
def __init__(self, kernel_estimator=ALEKernel, **kwargs):
def __init__(self, kernel_transformer=ALEKernel, **kwargs):
kernel_args = {k.split('kernel__')[1]: v for k, v in kwargs.items()
if k.startswith('kernel__')}
kwargs = {k: v for k, v in kwargs.items() if not k.startswith('kernel__')}
for k in kwargs.keys():
LGR.warning('Keyword argument "{0}" not recognized'.format(k))

if not issubclass(kernel_estimator, KernelTransformer):
raise ValueError('Argument "kernel_estimator" must be a '
if not issubclass(kernel_transformer, KernelTransformer):
raise ValueError('Argument "kernel_transformer" must be a '
'KernelTransformer')

self.mask = None
self.dataset = None

self.kernel_estimator = kernel_estimator(**kernel_args)
self.kernel_transformer = kernel_transformer(**kernel_args)
self.results = None
self.null_distributions = {}

def _fit(self, dataset):
self.dataset = dataset
self.mask = dataset.masker.mask_img

ma_maps = self.kernel_estimator.transform(self.dataset, mask=self.mask, masked=False)
ma_maps = self.kernel_transformer.transform(self.dataset, mask=self.mask, masked=False)
ale_values = self._compute_ale(ma_maps)
self._compute_null(ma_maps)
p_values, z_values = self._ale_to_p(ale_values)
Expand All @@ -102,7 +102,7 @@ def _compute_ale(self, data):
Returns masked array of ALE values.
"""
if isinstance(data, pd.DataFrame):
ma_values = self.kernel_estimator.transform(data, mask=self.mask, masked=True)
ma_values = self.kernel_transformer.transform(data, mask=self.mask, masked=True)
elif isinstance(data, list):
ma_values = apply_mask(data, self.mask)
elif isinstance(data, np.ndarray):
Expand Down Expand Up @@ -438,10 +438,10 @@ def _fit(self, ale1, ale2, image1=None, image2=None, ma_maps1=None,
grp2_voxel = image2 > 0

if ma_maps1 is None:
ma_maps1 = ale1.kernel_estimator.transform(ale1.dataset, masked=False)
ma_maps1 = ale1.kernel_transformer.transform(ale1.dataset, masked=False)

if ma_maps2 is None:
ma_maps2 = ale2.kernel_estimator.transform(ale2.dataset, masked=False)
ma_maps2 = ale2.kernel_transformer.transform(ale2.dataset, masked=False)

n_grp1 = len(ma_maps1)
ma_maps = ma_maps1 + ma_maps2
Expand Down Expand Up @@ -569,11 +569,11 @@ class SCALE(CBMAEstimator):
Tab-delimited file of coordinates from database or numpy array with ijk
coordinates. Voxels are rows and i, j, k (meaning matrix-space) values
are the three columnns.
kernel_estimator : :obj:`nimare.meta.cbma.base.KernelTransformer`, optional
kernel_transformer : :obj:`nimare.meta.cbma.base.KernelTransformer`, optional
Kernel with which to convolve coordinates from dataset. Default is
ALEKernel.
**kwargs
Keyword arguments. Arguments for the kernel_estimator can be assigned
Keyword arguments. Arguments for the kernel_transformer can be assigned
here, with the prefix '\kernel__' in the variable name.

References
Expand All @@ -583,12 +583,12 @@ class SCALE(CBMAEstimator):
(2014): 559-570. https://doi.org/10.1016/j.neuroimage.2014.06.007
"""
def __init__(self, voxel_thresh=0.001, n_iters=10000, n_cores=-1, ijk=None,
kernel_estimator=ALEKernel, **kwargs):
kernel_transformer=ALEKernel, **kwargs):
kernel_args = {k.split('kernel__')[1]: v for k, v in kwargs.items()
if k.startswith('kernel__')}

if not issubclass(kernel_estimator, KernelTransformer):
raise ValueError('Argument "kernel_estimator" must be a '
if not issubclass(kernel_transformer, KernelTransformer):
raise ValueError('Argument "kernel_transformer" must be a '
'KernelTransformer')

kwargs = {k: v for k, v in kwargs.items() if not k.startswith('kernel__')}
Expand All @@ -598,7 +598,7 @@ def __init__(self, voxel_thresh=0.001, n_iters=10000, n_cores=-1, ijk=None,
self.mask = None
self.dataset = None

self.kernel_estimator = kernel_estimator(**kernel_args)
self.kernel_transformer = kernel_transformer(**kernel_args)
self.voxel_thresh = voxel_thresh
self.ijk = ijk
self.n_iters = n_iters
Expand Down Expand Up @@ -628,7 +628,7 @@ def _fit(self, dataset):
self.dataset = dataset
self.mask = dataset.masker.mask_img

ma_maps = self.kernel_estimator.transform(self.dataset, masked=False)
ma_maps = self.kernel_transformer.transform(self.dataset, masked=False)

max_poss_ale = 1.
for ma_map in ma_maps:
Expand Down Expand Up @@ -683,7 +683,7 @@ def _compute_ale(self, df=None, ma_maps=None):
Returns masked array of ALE values and 1XnBins null distribution.
"""
if df is not None:
ma_maps = self.kernel_estimator.transform(df, self.mask, masked=True)
ma_maps = self.kernel_transformer.transform(df, self.mask, masked=True)
ma_values = ma_maps
else:
assert ma_maps is not None
Expand Down
52 changes: 26 additions & 26 deletions nimare/meta/cbma/mkda.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class MKDADensity(CBMAEstimator):

Parameters
----------
kernel_estimator : :obj:`nimare.meta.cbma.base.KernelTransformer`, optional
kernel_transformer : :obj:`nimare.meta.cbma.base.KernelTransformer`, optional
Kernel with which to convolve coordinates from dataset. Default is
MKDAKernel.
**kwargs
Keyword arguments. Arguments for the kernel_estimator can be assigned
Keyword arguments. Arguments for the kernel_transformer can be assigned
here, with the prefix '\kernel__' in the variable name.

Notes
Expand All @@ -47,19 +47,19 @@ class MKDADensity(CBMAEstimator):
cognitive and affective neuroscience 2.2 (2007): 150-158.
https://doi.org/10.1093/scan/nsm015
"""
def __init__(self, kernel_estimator=MKDAKernel, **kwargs):
def __init__(self, kernel_transformer=MKDAKernel, **kwargs):
kernel_args = {k.split('kernel__')[1]: v for k, v in kwargs.items()
if k.startswith('kernel__')}

if not issubclass(kernel_estimator, KernelTransformer):
raise ValueError('Argument "kernel_estimator" must be a '
if not issubclass(kernel_transformer, KernelTransformer):
raise ValueError('Argument "kernel_transformer" must be a '
'KernelTransformer')

kwargs = {k: v for k, v in kwargs.items() if not k.startswith('kernel__')}
for k in kwargs.keys():
LGR.warning('Keyword argument "{0}" not recognized'.format(k))

self.kernel_estimator = kernel_estimator(**kernel_args)
self.kernel_transformer = kernel_transformer(**kernel_args)

self.mask = None
self.dataset = None
Expand All @@ -77,7 +77,7 @@ def _fit(self, dataset):
self.dataset = dataset
self.mask = dataset.masker.mask_img

ma_values = self.kernel_estimator.transform(dataset, masked=True)
ma_values = self.kernel_transformer.transform(dataset, masked=True)

# Weight each SCM by square root of sample size
ids_df = self.dataset.coordinates.groupby('id').first()
Expand All @@ -104,7 +104,7 @@ def _run_fwe_permutation(self, params):
iter_ijk, iter_df, conn, voxel_thresh = params
iter_ijk = np.squeeze(iter_ijk)
iter_df[['i', 'j', 'k']] = iter_ijk
iter_ma_maps = self.kernel_estimator.transform(iter_df, mask=self.mask, masked=True)
iter_ma_maps = self.kernel_transformer.transform(iter_df, mask=self.mask, masked=True)
iter_ma_maps *= self.weight_vec
iter_of_map = np.sum(iter_ma_maps, axis=0)
iter_max_value = np.max(iter_of_map)
Expand Down Expand Up @@ -236,11 +236,11 @@ class MKDAChi2(CBMAEstimator):
prior : float, optional
Uniform prior probability of each feature being active in a map in
the absence of evidence from the map. Default: 0.5
kernel_estimator : :obj:`nimare.meta.cbma.base.KernelTransformer`, optional
kernel_transformer : :obj:`nimare.meta.cbma.base.KernelTransformer`, optional
Kernel with which to convolve coordinates from dataset. Default is
MKDAKernel.
**kwargs
Keyword arguments. Arguments for the kernel_estimator can be assigned
Keyword arguments. Arguments for the kernel_transformer can be assigned
here, with the prefix '\kernel__' in the variable name.

Notes
Expand All @@ -255,19 +255,19 @@ class MKDAChi2(CBMAEstimator):
cognitive and affective neuroscience 2.2 (2007): 150-158.
https://doi.org/10.1093/scan/nsm015
"""
def __init__(self, prior=0.5, kernel_estimator=MKDAKernel, **kwargs):
def __init__(self, prior=0.5, kernel_transformer=MKDAKernel, **kwargs):
kernel_args = {k.split('kernel__')[1]: v for k, v in kwargs.items()
if k.startswith('kernel__')}

if not issubclass(kernel_estimator, KernelTransformer):
raise ValueError('Argument "kernel_estimator" must be a '
if not issubclass(kernel_transformer, KernelTransformer):
raise ValueError('Argument "kernel_transformer" must be a '
'KernelTransformer')

kwargs = {k: v for k, v in kwargs.items() if not k.startswith('kernel__')}
for k in kwargs.keys():
LGR.warning('Keyword argument "{0}" not recognized'.format(k))

self.kernel_estimator = kernel_estimator(**kernel_args)
self.kernel_transformer = kernel_transformer(**kernel_args)
self.prior = prior

def fit(self, dataset, dataset2):
Expand Down Expand Up @@ -295,8 +295,8 @@ def _fit(self, dataset, dataset2):
self.dataset2 = dataset2
self.mask = dataset.masker.mask_img

ma_maps1 = self.kernel_estimator.transform(self.dataset, mask=self.mask, masked=True)
ma_maps2 = self.kernel_estimator.transform(self.dataset2, mask=self.mask, masked=True)
ma_maps1 = self.kernel_transformer.transform(self.dataset, mask=self.mask, masked=True)
ma_maps2 = self.kernel_transformer.transform(self.dataset2, mask=self.mask, masked=True)

# Calculate different count variables
n_selected = ma_maps1.shape[0]
Expand Down Expand Up @@ -365,8 +365,8 @@ def _run_fwe_permutation(self, params):
iter_df1[['i', 'j', 'k']] = iter_ijk1
iter_df2[['i', 'j', 'k']] = iter_ijk2

temp_ma_maps1 = self.kernel_estimator.transform(iter_df1, self.mask, masked=True)
temp_ma_maps2 = self.kernel_estimator.transform(iter_df2, self.mask, masked=True)
temp_ma_maps1 = self.kernel_transformer.transform(iter_df1, self.mask, masked=True)
temp_ma_maps2 = self.kernel_transformer.transform(iter_df2, self.mask, masked=True)

n_selected = temp_ma_maps1.shape[0]
n_unselected = temp_ma_maps2.shape[0]
Expand Down Expand Up @@ -565,11 +565,11 @@ class KDA(CBMAEstimator):

Parameters
----------
kernel_estimator : :obj:`nimare.meta.cbma.base.KernelTransformer`, optional
kernel_transformer : :obj:`nimare.meta.cbma.base.KernelTransformer`, optional
Kernel with which to convolve coordinates from dataset. Default is
KDAKernel.
**kwargs
Keyword arguments. Arguments for the kernel_estimator can be assigned
Keyword arguments. Arguments for the kernel_transformer can be assigned
here, with the prefix '\kernel__' in the variable name.

Notes
Expand All @@ -588,19 +588,19 @@ class KDA(CBMAEstimator):
studies of shifting attention: a meta-analysis." Neuroimage 22.4
(2004): 1679-1693. https://doi.org/10.1016/j.neuroimage.2004.03.052
"""
def __init__(self, kernel_estimator=KDAKernel, **kwargs):
def __init__(self, kernel_transformer=KDAKernel, **kwargs):
kernel_args = {k.split('kernel__')[1]: v for k, v in kwargs.items()
if k.startswith('kernel__')}

if not issubclass(kernel_estimator, KernelTransformer):
raise ValueError('Argument "kernel_estimator" must be a '
if not issubclass(kernel_transformer, KernelTransformer):
raise ValueError('Argument "kernel_transformer" must be a '
'KernelTransformer')

kwargs = {k: v for k, v in kwargs.items() if not k.startswith('kernel__')}
for k in kwargs.keys():
LGR.warning('Keyword argument "{0}" not recognized'.format(k))

self.kernel_estimator = kernel_estimator(**kernel_args)
self.kernel_transformer = kernel_transformer(**kernel_args)

def _fit(self, dataset):
"""
Expand All @@ -614,7 +614,7 @@ def _fit(self, dataset):
self.dataset = dataset
self.mask = dataset.masker.mask_img

ma_maps = self.kernel_estimator.transform(dataset, masked=True)
ma_maps = self.kernel_transformer.transform(dataset, masked=True)
of_values = np.sum(ma_maps, axis=0)
images = {
'of': of_values
Expand All @@ -625,7 +625,7 @@ def _run_fwe_permutation(self, params):
iter_ijk, iter_df = params
iter_ijk = np.squeeze(iter_ijk)
iter_df[['i', 'j', 'k']] = iter_ijk
iter_ma_maps = self.kernel_estimator.transform(iter_df, mask=self.mask, masked=True)
iter_ma_maps = self.kernel_transformer.transform(iter_df, mask=self.mask, masked=True)
iter_of_map = np.sum(iter_ma_maps, axis=0)
iter_max_value = np.max(iter_of_map)
return iter_max_value
Expand Down
4 changes: 2 additions & 2 deletions nimare/parcellate/mamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, dataset, ids):
self.solutions = None
self.metrics = None

def fit(self, target_mask, n_parcels=2, kernel_estimator=ALEKernel,
def fit(self, target_mask, n_parcels=2, kernel_transformer=ALEKernel,
**kwargs):
"""
Run MAMP parcellation.
Expand Down Expand Up @@ -87,7 +87,7 @@ def fit(self, target_mask, n_parcels=2, kernel_estimator=ALEKernel,
if not isinstance(n_parcels, list):
n_parcels = [n_parcels]

k_est = kernel_estimator(self.coordinates, self.mask)
k_est = kernel_transformer(self.coordinates, self.mask)
ma_maps = k_est.transform(self.ids, **kernel_args)

# Step 1: Build correlation matrix
Expand Down