Kernel Functions APIs - 5.2 English - 68552

AOCL API Guide (68552)

Document ID
68552
Release Date
2025-12-29
Version
5.2 English
aoclda.kernel_functions.rbf_kernel()#

Compute the RBF (Radial Basis Function) kernel matrix.

\[K(x, y) = \exp(-\gamma ||x - y||^2)\]

If Y is not provided, the RBF kernel is computed between the rows of X, resulting in a matrix of shape (n_samples_X, n_samples_X). Otherwise, it computes the RBF kernel between X and Y, with shape (n_samples_X, n_samples_Y).

Parameters:
  • X (array-like) – The feature matrix of shape (n_samples_X, n_features).

  • Y (array-like, optional) – The optional matrix of shape (n_samples_Y, n_features).

  • gamma (float, optional) – The kernel coefficient. Has to be greater or equal to 0.

Returns:

The RBF kernel matrix of shape (n_samples_X, n_samples_X) if Y is None, or (n_samples_X, n_samples_Y) otherwise.

Return type:

numpy.ndarray

aoclda.kernel_functions.linear_kernel()#

Compute the linear kernel matrix.

\[K(x, y) = x * y\]

If Y is not provided, the linear kernel is computed between the rows of X, resulting in a matrix of shape (n_samples_X, n_samples_X). Otherwise, it computes the linear kernel between X and Y, with shape (n_samples_X, n_samples_Y).

Parameters:
  • X (array-like) – The feature matrix of shape (n_samples_X, n_features).

  • Y (array-like, optional) – The optional matrix of shape (n_samples_Y, n_features).

Returns:

The linear kernel matrix of shape (n_samples_X, n_samples_X) if Y is None, or (n_samples_X, n_samples_Y) otherwise.

Return type:

numpy.ndarray

aoclda.kernel_functions.polynomial_kernel()#

Compute the polynomial kernel matrix.

\[K(x, y) = (\gamma x * y + c)^{d}\]

If Y is not provided, the polynomial kernel is computed between the rows of X, resulting in a matrix of shape (n_samples_X, n_samples_X). Otherwise, it computes the polynomial kernel between X and Y, with shape (n_samples_X, n_samples_Y).

Parameters:
  • X (array-like) – The feature matrix of shape (n_samples_X, n_features).

  • Y (array-like, optional) – The optional matrix of shape (n_samples_Y, n_features).

  • degree (int, optional) – The degree of the polynomial.

  • gamma (float, optional) – The kernel coefficient. Has to be greater or equal to 0.

  • coef0 (float, optional) – The independent term in the polynomial kernel.

Returns:

The polynomial kernel matrix of shape (n_samples_X, n_samples_X) if Y is None, or (n_samples_X, n_samples_Y) otherwise.

Return type:

numpy.ndarray

aoclda.kernel_functions.sigmoid_kernel()#

Compute the sigmoid kernel matrix.

\[K(x, y) = \tanh(\gamma x * y + c)\]

If Y is not provided, the sigmoid kernel is computed between the rows of X, resulting in a matrix of shape (n_samples_X, n_samples_X). Otherwise, it computes the sigmoid kernel between X and Y, with shape (n_samples_X, n_samples_Y).

Parameters:
  • X (array-like) – The feature matrix of shape (n_samples_X, n_features).

  • Y (array-like, optional) – The optional matrix of shape (n_samples_Y, n_features).

  • gamma (float, optional) – The kernel coefficient. Has to be greater or equal to 0.

  • coef0 (float, optional) – The constant factor for the sigmoid kernel.

Returns:

The sigmoid kernel matrix of shape (n_samples_X, n_samples_X) if Y is None, or (n_samples_X, n_samples_Y) otherwise.

Return type:

numpy.ndarray

da_status da_rbf_kernel_s(da_order order, da_int m, da_int n, da_int k, const float *X, da_int ldx, const float *Y, da_int ldy, float *D, da_int ldd, float gamma)#
da_status da_rbf_kernel_d(da_order order, da_int m, da_int n, da_int k, const double *X, da_int ldx, const double *Y, da_int ldy, double *D, da_int ldd, double gamma)#

Compute the RBF (Radial Basis Function) kernel matrix for the matrices X and, optionally, Y.

This function computes the RBF kernel between the matrix X (size m \(\times\) k) and Y (size n \(\times\) k) if provided. If Y is null, the kernel is computed between the rows of X, ( \(XX^T\)). The results are stored in D.

The RBF kernel is given by:

\[ K(x, y) = \exp(-\gamma \|\mathbf{x} - \mathbf{y}\|^2). \]
Parameters:
  • order[in] da_order enum specifying column-major or row-major layout.

  • m[in] the number of rows of matrix X. Constraint: m \(\ge\) 1.

  • n[in] the number of rows of matrix Y. Constraint: n \(\ge\) 1.

  • k[in] the number of columns of matrices X and Y. Constraint: k \(\ge\) 1.

  • X[in] the matrix of size m \(\times\) k, stored in column-major order by default.

  • ldx[in] the leading dimension of X. Constraint: ldx \(\ge\) m if order = column_major, or ldx \(\ge\) k if order = row_major.

  • Y[in] the matrix of size n \(\times\) k, or null if computing the kernel of X with itself.

  • ldy[in] the leading dimension of Y. Constraint: ldy \(\ge\) n if order = column_major, or ldy \(\ge\) k if order = row_major.

  • D[out] the resulting kernel matrix of size m \(\times\) n if Y is not null, or m \(\times\) m otherwise.

  • ldd[in] the leading dimension of the matrix D. Constraint: ldd \(\ge\) m, if Y is nullptr or order = column_major, and ldd \(\ge\) n, otherwise.

  • gamma[in] the RBF kernel scale factor. Constraint: gamma \(\ge\) 0.

Returns:

da_status

da_status da_linear_kernel_s(da_order order, da_int m, da_int n, da_int k, const float *X, da_int ldx, const float *Y, da_int ldy, float *D, da_int ldd)#
da_status da_linear_kernel_d(da_order order, da_int m, da_int n, da_int k, const double *X, da_int ldx, const double *Y, da_int ldy, double *D, da_int ldd)#

Compute the linear kernel matrix for the matrices X and, optionally, Y.

This function computes the linear kernel between the rows of X (size m \(\times\) k) and Y (size n \(\times\) k) if provided. If Y is null, the kernel is computed between the rows of X, ( \(XX^T\)). The results are stored in D.

The linear kernel is given by:

\[ K(x, y) = x \cdot y. \]
Parameters:
  • order[in] da_order enum specifying column-major or row-major layout.

  • m[in] the number of rows of matrix X. Constraint: m \(\ge\) 1.

  • n[in] the number of rows of matrix Y. Constraint: n \(\ge\) 1.

  • k[in] the number of columns of matrices X and Y. Constraint: k \(\ge\) 1.

  • X[in] the matrix of size m \(\times\) k, stored in column-major order by default.

  • ldx[in] the leading dimension of X. Constraint: ldx \(\ge\) m if order = column_major, or ldx \(\ge\) k if order = row_major.

  • Y[in] the matrix of size n \(\times\) k, or null if computing the kernel of X with itself.

  • ldy[in] the leading dimension of Y. Constraint: ldy \(\ge\) n if order = column_major, or ldy \(\ge\) k if order = row_major.

  • D[out] the resulting kernel matrix of size m \(\times\) n if Y is not null, or m \(\times\) m otherwise.

  • ldd[in] the leading dimension of the matrix D. Constraint: ldd \(\ge\) m, if Y is nullptr or order = column_major, and ldd \(\ge\) n, otherwise.

Returns:

da_status

da_status da_polynomial_kernel_s(da_order order, da_int m, da_int n, da_int k, const float *X, da_int ldx, const float *Y, da_int ldy, float *D, da_int ldd, float gamma, da_int degree, float coef0)#
da_status da_polynomial_kernel_d(da_order order, da_int m, da_int n, da_int k, const double *X, da_int ldx, const double *Y, da_int ldy, double *D, da_int ldd, double gamma, da_int degree, double coef0)#

Compute the polynomial kernel matrix for the matrices X and, optionally, Y.

This function computes the polynomial kernel between the rows of X (size m \(\times\) k) and Y (size n \(\times\) k) if provided. If Y is null, the kernel is computed between the rows of X, ( \(XX^T\)). The results are stored in D.

The polynomial kernel is given by:

\[ K(x, y) = (\gamma x \cdot y + c)^d. \]
Parameters:
  • order[in] da_order enum specifying column-major or row-major layout.

  • m[in] the number of rows of matrix X. Constraint: m \(\ge\) 1.

  • n[in] the number of rows of matrix Y. Constraint: n \(\ge\) 1.

  • k[in] the number of columns of matrices X and Y. Constraint: k \(\ge\) 1.

  • X[in] the matrix of size m \(\times\) k, stored in column-major order by default.

  • ldx[in] the leading dimension of X. Constraint: ldx \(\ge\) m if order = column_major, or ldx \(\ge\) k if order = row_major.

  • Y[in] the matrix of size n \(\times\) k, or null if computing the kernel of X with itself.

  • ldy[in] the leading dimension of Y. Constraint: ldy \(\ge\) n if order = column_major, or ldy \(\ge\) k if order = row_major.

  • D[out] the resulting kernel matrix of size m \(\times\) n if Y is not null, or m \(\times\) m otherwise.

  • ldd[in] the leading dimension of the matrix D. Constraint: ldd \(\ge\) m, if Y is nullptr or order = column_major, and ldd \(\ge\) n, otherwise.

  • gamma[in] the scale factor used in polynomial kernel. Constraint: gamma \(\ge\) 0.

  • degree[in] the degree of the polynomial kernel. Constraint: degree \(\ge\) 0.

  • coef0[in] the independent term in the polynomial kernel.

Returns:

da_status

da_status da_sigmoid_kernel_s(da_order order, da_int m, da_int n, da_int k, const float *X, da_int ldx, const float *Y, da_int ldy, float *D, da_int ldd, float gamma, float coef0)#
da_status da_sigmoid_kernel_d(da_order order, da_int m, da_int n, da_int k, const double *X, da_int ldx, const double *Y, da_int ldy, double *D, da_int ldd, double gamma, double coef0)#

Compute the sigmoid kernel matrix for the matrices X and, optionally, Y.

This function computes the sigmoid kernel between the rows of X (size m \(\times\) k) and Y (size n \(\times\) k) if provided. If Y is null, the kernel is computed between the rows of X, ( \(XX^T\)). The results are stored in D.

The sigmoid kernel is given by:

\[ K(x, y) = \tanh(\gamma x \cdot y + c). \]
Parameters:
  • order[in] da_order enum specifying column-major or row-major layout.

  • m[in] the number of rows of matrix X. Constraint: m \(\ge\) 1.

  • n[in] the number of rows of matrix Y. Constraint: n \(\ge\) 1.

  • k[in] the number of columns of matrices X and Y. Constraint: k \(\ge\) 1.

  • X[in] the matrix of size m \(\times\) k, stored in column-major order by default.

  • ldx[in] the leading dimension of X. Constraint: ldx \(\ge\) m if order = column_major, or ldx \(\ge\) k if order = row_major.

  • Y[in] the matrix of size n \(\times\) k, or null if computing the kernel of X with itself.

  • ldy[in] the leading dimension of Y. Constraint: ldy \(\ge\) n if order = column_major, or ldy \(\ge\) k if order = row_major.

  • D[out] the resulting kernel matrix of size m \(\times\) n if Y is not null, or m \(\times\) m otherwise.

  • ldd[in] the leading dimension of the matrix D. Constraint: ldd \(\ge\) m, if Y is nullptr or order = column_major, and ldd \(\ge\) n, otherwise.

  • gamma[in] the scale factor used in sigmoid kernel. Constraint: gamma \(\ge\) 0.

  • coef0[in] constant term in the sigmoid kernel.

Returns:

da_status