From 754cade1dcc13e7e2005ebea2684ba3433d5e9c6 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Sat, 7 Dec 2019 12:54:42 -0500 Subject: [PATCH] kernel_estimator --> kernel_transformer --- nimare/meta/cbma/ale.py | 36 +++++++++++++-------------- nimare/meta/cbma/mkda.py | 52 +++++++++++++++++++-------------------- nimare/parcellate/mamp.py | 4 +-- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/nimare/meta/cbma/ale.py b/nimare/meta/cbma/ale.py index df35e5d27..78b0e7e88 100755 --- a/nimare/meta/cbma/ale.py +++ b/nimare/meta/cbma/ale.py @@ -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 @@ -62,21 +62,21 @@ 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 = {} @@ -84,7 +84,7 @@ 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) @@ -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): @@ -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 @@ -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 @@ -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__')} @@ -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 @@ -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: @@ -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 diff --git a/nimare/meta/cbma/mkda.py b/nimare/meta/cbma/mkda.py index e5d01717d..6dc2989b2 100644 --- a/nimare/meta/cbma/mkda.py +++ b/nimare/meta/cbma/mkda.py @@ -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 @@ -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 @@ -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() @@ -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) @@ -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 @@ -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): @@ -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] @@ -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] @@ -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 @@ -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): """ @@ -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 @@ -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 diff --git a/nimare/parcellate/mamp.py b/nimare/parcellate/mamp.py index f608f7889..eae455c06 100644 --- a/nimare/parcellate/mamp.py +++ b/nimare/parcellate/mamp.py @@ -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. @@ -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