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

Method _kernel

numpy_ml/utils/kernels.py:159–181  ·  view source on GitHub ↗

Compute the degree-`d` polynomial kernel 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 ` of

(self, X, Y=None)

Source from the content-addressed store, hash-verified

157 self.parameters = {"d": d, "c0": c0, "gamma": gamma}
158
159 def _kernel(self, X, Y=None):
160 """
161 Compute the degree-`d` polynomial kernel between all pairs of rows in `X`
162 and `Y`.
163
164 Parameters
165 ----------
166 X : :py:class:`ndarray <numpy.ndarray>` of shape `(N, C)`
167 Collection of `N` input vectors
168 Y : :py:class:`ndarray <numpy.ndarray>` of shape `(M, C)` or None
169 Collection of `M` input vectors. If None, assume `Y = X`. Default
170 is None.
171
172 Returns
173 -------
174 out : :py:class:`ndarray <numpy.ndarray>` of shape `(N, M)`
175 Similarity between `X` and `Y` where index (`i`, `j`) gives
176 :math:`k(x_i, y_j)` (i.e., the kernel&#x27;s Gram-matrix).
177 """
178 P = self.parameters
179 X, Y = kernel_checks(X, Y)
180 gamma = 1 / X.shape[1] if P["gamma"] is None else P["gamma"]
181 return (gamma * (X @ Y.T) + P["c0"]) ** P["d"]
182
183
184class RBFKernel(KernelBase):

Callers

nothing calls this directly

Calls 1

kernel_checksFunction · 0.85

Tested by

no test coverage detected