|
| 1 | +# ============================================================================== |
| 2 | +# Copyright contributors to the oneDAL project |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# ============================================================================== |
| 16 | + |
| 17 | +import numpy as np |
| 18 | +from onedal.primitives import poly_kernel as onedal_poly_kernel |
| 19 | + |
| 20 | +def poly_kernel(X, Y=None, gamma=1.0, coef0=0.0, degree=3, queue=None): |
| 21 | + """ |
| 22 | + sklearnex interface for the polynomial kernel using oneDAL backend. |
| 23 | +
|
| 24 | + K(x, y) = (gamma * <x, y> + coef0) ** degree |
| 25 | + for each pair of rows x in X and y in Y. |
| 26 | +
|
| 27 | + Parameters |
| 28 | + ---------- |
| 29 | + X : array-like of shape (n_samples_X, n_features) |
| 30 | + Input feature array. |
| 31 | +
|
| 32 | + Y : array-like of shape (n_samples_Y, n_features), default=None |
| 33 | + Optional second feature array. If None, Y = X. |
| 34 | +
|
| 35 | + gamma : float, default=1.0 |
| 36 | + Scaling factor for the inner product. |
| 37 | +
|
| 38 | + coef0 : float, default=0.0 |
| 39 | + Constant term added to scaled inner product. |
| 40 | +
|
| 41 | + degree : int, default=3 |
| 42 | + Degree of the polynomial kernel. |
| 43 | +
|
| 44 | + queue : SyclQueue or None, default=None |
| 45 | + Optional SYCL queue for device execution. |
| 46 | +
|
| 47 | + Returns |
| 48 | + ------- |
| 49 | + kernel_matrix : ndarray of shape (n_samples_X, n_samples_Y) |
| 50 | + Polynomial kernel Gram matrix. |
| 51 | + """ |
| 52 | + return onedal_poly_kernel(X, Y=Y, gamma=gamma, coef0=coef0, degree=degree, queue=queue) |
0 commit comments