MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / _kernel

Method _kernel

numpy_ml/utils/kernels.py:217–238  ·  view source on GitHub ↗

Computes the radial basis function (RBF) kernel between all pairs of rows in `X` and `Y`. Parameters ---------- X : :py:class:`ndarray ` of shape `(N, C)` Collection of `N` input vectors, each with dimension `C`. Y : :py:cl

(self, X, Y=None)

Source from the content-addressed store, hash-verified

215 self.parameters = {"sigma": sigma}
216
217 def _kernel(self, X, Y=None):
218 """
219 Computes the radial basis function (RBF) kernel between all pairs of
220 rows in `X` and `Y`.
221
222 Parameters
223 ----------
224 X : :py:class:`ndarray <numpy.ndarray>` of shape `(N, C)`
225 Collection of `N` input vectors, each with dimension `C`.
226 Y : :py:class:`ndarray <numpy.ndarray>` of shape `(M, C)`
227 Collection of `M` input vectors. If None, assume `Y` = `X`. Default
228 is None.
229
230 Returns
231 -------
232 out : :py:class:`ndarray <numpy.ndarray>` of shape `(N, M)`
233 Similarity between `X` and `Y` where index (i, j) gives :math:`k(x_i, y_j)`.
234 """
235 P = self.parameters
236 X, Y = kernel_checks(X, Y)
237 sigma = np.sqrt(X.shape[1] / 2) if P["sigma"] is None else P["sigma"]
238 return np.exp(-0.5 * pairwise_l2_distances(X / sigma, Y / sigma) ** 2)
239
240
241class KernelInitializer(object):

Callers

nothing calls this directly

Calls 2

kernel_checksFunction · 0.85
pairwise_l2_distancesFunction · 0.85

Tested by

no test coverage detected