brainspace.gradient.kernels.compute_affinity¶
-
brainspace.gradient.kernels.
compute_affinity
(x, kernel=None, sparsity=0.9, pre_sparsify=True, non_negative=True, gamma=None)[source]¶ Compute affinity matrix.
Parameters: - x (ndarray, shape = (n_samples, n_feat)) – Input matrix.
- kernel (str, None or callable, optional) –
Kernel function. If None, only sparsify. Default is None. Valid options:
- If ‘pearson’, use Pearson’s correlation coefficient.
- If ‘spearman’, use Spearman’s rank correlation coefficient.
- If ‘cosine’, use cosine similarity.
- If ‘normalized_angle’: use normalized angle between two vectors. This option is based on cosine similarity but provides similarities bounded between 0 and 1.
- If ‘gaussian’, use Gaussian kernel or RBF.
- sparsity (float or None, optional) – Proportion of smallest elements to zero-out for each row. If None, do not sparsify. Default is 0.9.
- pre_sparsify (bool, optional) – Sparsify prior to building the affinity. If False, sparsify the final affinity matrix.
- non_negative (bool, optional) – If True, zero-out negative values. Otherwise, do nothing.
- gamma (float or None, optional) – Inverse kernel width. Only used if
kernel == 'gaussian'
. If None,gamma = 1./n_feat
. Default is None.
Returns: affinity (ndarray, shape = (n_samples, n_samples)) – Affinity matrix.