Quantum Kernel Estimation
Overview
Quantum kernels measure similarity between data points in a high-dimensional quantum feature space. Instead of explicitly computing features in an exponentially large Hilbert space, the quantum kernel estimates the inner product directly via a circuit -- this is the kernel trick applied to quantum computing.
The kernel value K(x1, x2) = |<0|U+(x2)U(x1)|0>|^2 represents the transition probability: how likely the quantum state prepared from x1 is to collapse back to the ground state after applying the inverse of the x2 preparation. Identical points yield K = 1; orthogonal feature mappings yield K approaching 0.
The Kernel Trick
In classical machine learning, the kernel trick avoids computing high-dimensional features explicitly:
CODEClassical: K(x, y) = <phi(x), phi(y)> (dot product in feature space) Quantum: K(x, y) = |<0|U+(y)U(x)|0>|^2 (transition probability)
The quantum advantage: the feature space is exponentially large (2^n dimensions for n qubits), but the kernel can be estimated with a polynomial-size circuit.
The Circuit
ZZ Feature Map U(x)
CODE+---+ +--------+ +-----------------+ +---+ +--------+ q_0: | H |-| RZ(2x0)|--*--| |--*--| H |-| RZ(2x0)| +---+ +--------+ | | | | +---+ +--------+ +---+ +--------+ +-+- |RZ(2(pi-x0)(pi-x1))| +-+- +---+ +--------+ q_1: | H |-| RZ(2x1)|-|X|--| |--|X|-| H |-| RZ(2x1)| +---+ +--------+ +--+ +-----------------+ +--+ +---+ +--------+
Kernel Circuit K(x1, x2)
CODE|0> --[ U(x2) ]--[ U+(x1) ]-- Measure |0> --[ U(x2) ]--[ U+(x1) ]-- Measure Kernel value = P(|00>) = probability of measuring all-zeros state
Feature Map Design
The ZZ Feature Map encodes both individual features and their pairwise interactions:
- Individual encoding: H + RZ(2*xi) rotates each qubit based on its feature value
- Interaction term: CX-RZ(2*(pi-x0)(pi-x1))-CX encodes the product of features
- Repetition: The single-qubit layer is applied twice for expressiveness
The interaction term f(x) = (pi - x0)(pi - x1) ensures that the feature space captures non-linear relationships between input dimensions.
SVM Connection
Quantum kernels plug directly into classical SVMs:
PYTHONfrom sklearn.svm import SVC # Compute quantum kernel matrix K_train = compute_kernel_matrix(X_train, shots=1024) # Train SVM with precomputed quantum kernel clf = SVC(kernel='precomputed') clf.fit(K_train, y_train) # For prediction, compute kernel between test and train points K_test = compute_kernel_matrix_cross(X_test, X_train) predictions = clf.predict(K_test)
Running the Circuit
PYTHONfrom circuit import run_circuit, compute_kernel, compute_kernel_matrix, verify_kernel # Single kernel computation result = run_circuit(x1=[0.5, 0.3], x2=[0.6, 0.4]) print(f"K(x1, x2) = {result['kernel_value']:.4f}") print(f"Similarity: {result['similarity']}") # Direct kernel value k = compute_kernel([0.5, 0.3], [-0.8, 0.9], shots=2048) print(f"K = {k:.4f}") # Full kernel matrix X = [[0.0, 0.0], [0.5, 0.5], [1.0, 0.0], [0.0, 1.0]] K = compute_kernel_matrix(X, shots=512) print(K) # Verify properties v = verify_kernel() print(f"All checks passed: {v['passed']}")
Expected Output
| Scenario | Kernel Value | Interpretation |
|---|---|---|
| Same point K(x, x) | ~1.0 | Perfect self-similarity |
| Similar points | 0.5 - 0.9 | High similarity |
| Different points | 0.1 - 0.5 | Low similarity |
| Orthogonal mapping | ~0.0 | No similarity |
Kernel Properties
- Self-similarity: K(x, x) = 1 (identical points have maximal overlap)
- Symmetry: K(x, y) = K(y, x) (inner product is symmetric)
- Boundedness: 0 <= K(x, y) <= 1 (valid probability)
- Positive semi-definite: The kernel matrix is a valid Gram matrix
Comparison with Classical Kernels
| Kernel | Feature Space | Computation | Advantage |
|---|---|---|---|
| Linear | d dimensions | O(d) | Simple, fast |
| RBF/Gaussian | Infinite | O(d) | Universal approximator |
| Polynomial | O(d^k) | O(d) | Captures interactions |
| Quantum (ZZ) | 2^n dimensions | O(shots) | Exponentially rich |
Applications
- Quantum SVM: Classification with quantum-enhanced feature spaces
- Anomaly detection: Kernel-based outlier detection in quantum feature space
- Clustering: Spectral clustering with quantum kernel similarity
- Feature analysis: Understanding quantum feature map expressiveness
Learn More
- Supervised Learning with Quantum-Enhanced Feature Spaces (Havlicek et al., 2019)
- Quantum Machine Learning in Feature Hilbert Spaces (Schuld & Killoran, 2019)
- Power of Data in Quantum Machine Learning (Huang et al., 2021)