Computing Library › Quantum Ml
Quantum Ml

The Kernel Trick

The kernel trick lets linear algorithms operate in a high-dimensional feature space using only inner products, never computing the explicit coordinates.

Learning without coordinates

Many learning algorithms depend on the data only through inner products between examples. The kernel trick exploits this: instead of mapping each point x to a high-dimensional feature vector phi(x) and computing , you define a kernel function k(x, x') that returns that inner product directly. If k is a valid kernel, the feature space and its map never need to be written down.

Formally, a function k is a valid (positive semi-definite) kernel if for any finite set of points the Gram matrix K with entries K_ij = k(x_i, x_j) is symmetric positive semi-definite. Mercer's theorem guarantees that such a k corresponds to an inner product in some feature space, possibly infinite-dimensional, as with the Gaussian RBF kernel.

Kronos motion — battery never recharge

Why it powers support vector machines

A linear support vector machine finds the maximum-margin separating hyperplane. Its dual optimization involves only inner products among training points, so replacing them with k(x_i, x_j) yields a nonlinear classifier in the input space while the optimization stays convex. The same substitution works for ridge regression, principal component analysis, and clustering.

The quantum connection

A quantum feature map defines exactly such an inner product. If |phi(x)> is the quantum state encoding x, then the fidelity ||^2 is a positive semi-definite kernel. The quantum device estimates each kernel entry; a classical support vector machine then trains on the resulting Gram matrix. This split keeps the hard optimization classical and convex.

python
# Classical kernel SVM skeleton
import numpy as np
def gram(X, kernel):
    n = len(X)
    K = np.empty((n, n))
    for i in range(n):
        for j in range(n):
            K[i, j] = kernel(X[i], X[j])
    return K
# Replace `kernel` with a quantum fidelity estimator to go quantum.

What the trick does not do