A support vector machine (SVM) is a type of machine learning algorithm that is commonly used for classification. In a binary classification problem, SVM seeks to find the best possible boundary or hyperplane that can separate the two classes. The algorithm does this by identifying the data points closest to the boundary or hyperplane, which are called support vectors. The SVM then maximizes the margin, which is the distance between the boundary or hyperplane and the support vectors on each side.
A kernel-based SVM, also known as kernel SVM, is a variant of the traditional SVM algorithm that uses a kernel function to transform the input data into a higher dimensional space. The kernel function is a mathematical function that takes in the original data and returns a transformed version of the data in a higher-dimensional space. The idea behind kernel SVM is to find a linear boundary or hyperplane in the transformed space that can separate the two classes of data.
def kernel(x1, x2):
feature_map(x1)
qml.adjoint(feature_map)(x2)
return qml.expval(qml.PauliZ(2))
For a support vector machine (SVM), the kernel is a function that measures the similarity between two data points. In a quantum SVM, we can use a quantum kernel to compute the similarity between two data points in a quantum feature space.Â
The kernel used in the quantum SVM is defined in terms of a feature map and a measurement operator. The measurement operator is a Pauli-Z operator applied to two qubits, which measures the quantum state.
The kernel function takes two input data points, denoted by x and y, and applies the feature map to each data point to obtain two quantum states. The two quantum states are then measured using the Pauli-Z operator, and the expectation value of the product of the two measurements is computed. This expectation value represents the similarity between the two data points in the quantum feature space.
This quantum circuit is based on the work from the "Quantum Support Vector Machines" paper by Havlicek et al.
def feature_map(x):
for i in range(3):
qml.Hadamard(wires=i)
qml.RY(x[i], wires=i)
qml.CNOT(wires=[0, 1])
qml.CNOT(wires=[1, 2])
qml.RZ(x[0] * x[1], wires=2)
qml.CNOT(wires=[1, 2])
qml.RY(x[1] * x[2], wires=2)
qml.CNOT(wires=[0, 1])
qml.CNOT(wires=[1, 2])
qml.RZ(x[0] * x[2], wires=2)
qml.CNOT(wires=[1, 2])
The circuit starts with a Hadamard gate on each qubit, which puts the qubits in a superposition state. Then, for each feature in the input data, the circuit applies a rotation gate (RY) on the corresponding qubit, with the angle of the rotation determined by the value of the feature. This part of the circuit is analogous to the linear transformation used in a classical SVM.
After the rotation gates, the circuit applies a series of controlled-NOT (CNOT) gates to entangle the qubits. The entanglement allows the circuit to capture non-linear correlations between the features.
Finally, the circuit applies a few more rotation gates (RZ and RY) and CNOT gates to complete the feature map. The resulting quantum state is then used to compute the inner product between two data points, which is a key step in the SVM algorithm.