dodiscover.ci.kernel_utils.compute_kernel#

dodiscover.ci.kernel_utils.compute_kernel(X, Y=None, metric='rbf', distance_metric='euclidean', kwidth=None, centered=True, n_jobs=None)[source]#

Compute a kernel matrix and corresponding width.

Also optionally estimates the kernel width parameter.

Parameters:
Xarray_like of shape (n_samples_X, n_features_X)

The X array.

Yarray_like of shape (n_samples_Y, n_features_Y), optional

The Y array, by default None.

metricstr, optional

The metric to compute the kernel function, by default ‘rbf’. Can be any string as defined in sklearn.metrics.pairwise.pairwise_kernels(). Note ‘rbf’ and ‘gaussian’ are the same metric.

distance_metricstr, optional

The distance metric to compute distances among samples within each data matrix, by default ‘euclidean’. Can be any valid string as defined in sklearn.metrics.pairwise_distances().

kwidthfloat, optional

The kernel width, by default None, which will then be estimated as the median L2 distance between the X features.

centeredbool, optional

Whether to center the kernel matrix or not, by default True.

n_jobsint, optional

The number of jobs to run computations in parallel, by default None.

Returns:
kernelarray_like of shape (n_samples_X, n_samples_X) or (n_samples_X, n_samples_Y)

The kernel matrix.

medfloat

The estimated kernel width.