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

Method _kernel

numpy_ml/utils/kernels.py:96–116  ·  view source on GitHub ↗

Compute the linear kernel (i.e., dot-product) between all pairs of rows in `X` and `Y`. Parameters ---------- X : :py:class:`ndarray ` of shape `(N, C)` Collection of `N` input vectors Y : :py:class:`ndarray

(self, X, Y=None)

Source from the content-addressed store, hash-verified

94 self.parameters = {"c0": c0}
95
96 def _kernel(self, X, Y=None):
97 """
98 Compute the linear kernel (i.e., dot-product) between all pairs of rows in
99 `X` and `Y`.
100
101 Parameters
102 ----------
103 X : :py:class:`ndarray <numpy.ndarray>` of shape `(N, C)`
104 Collection of `N` input vectors
105 Y : :py:class:`ndarray <numpy.ndarray>` of shape `(M, C)` or None
106 Collection of `M` input vectors. If None, assume `Y` = `X`.
107 Default is None.
108
109 Returns
110 -------
111 out : :py:class:`ndarray <numpy.ndarray>` of shape `(N, M)`
112 Similarity between `X` and `Y`, where index (`i`, `j`) gives
113 :math:`k(x_i, y_j)`.
114 """
115 X, Y = kernel_checks(X, Y)
116 return X @ Y.T + self.parameters["c0"]
117
118
119class PolynomialKernel(KernelBase):

Callers

nothing calls this directly

Calls 1

kernel_checksFunction · 0.85

Tested by

no test coverage detected