Sitemap

Quantum Kernel-based Classification

4 min readJun 22, 2021

--

A very famous Supervised Machine Learning algorithm considered a celebrity among ML /Non-ML Engineers as well as non-Engineers. When a classification problem dealing with very huge data with minimal classes or multiple classes with a good amount of labeled training data then the Support Vector Machine model can handle single-handedly.

Using qiskit library

The data set which cannot be classified so easily can be mapped into a higher dimensional space with the inner products of two vectors (classes of the data) which map data points into linearly separable data points. Here comes a support vector used to draw a hyperplane between the separable data points. If the data is n dimension, then the hyperplane (dividing support vector) will be n-1 dimension. The distance between the data points in different classes and the dividing line is known as the margin. The aim of an SVM algorithm is to maximize this margin. Linearly separable data is the hard margin whereas non-linearly separable data poses a soft margin. Dealing linearly separable data can be handled with SVM black box, but in the case of non-linear data and to obtain soft margin we need a black box better than the existing SVM.

SVM model data distribution

Here, we have Kernel methods, the set of algorithms for pattern analysis or recognition of the data points. Kernel methods map data into higher dimensional spaces in the hope of ease in data structure and separability. The data can be mapped not only to higher dimensional space but to an infinite dimension. Kernel “trick” is the method of replacing the inner products of two vectors in our algorithm with the kernel function (inner products of new space with given new dimensionality). Kernel function should be continuous, symmetric, positive definite Gram Matrix

Gram Matrix

There are different types of Kernel functions available with their unique math’s. For sequence data, graphs, text, images, as well as vectors the most used type of kernel function is Gaussian radial basis function (RBF). For image processing models the best suit is the polynomial kernel. For Image Classification models, we can use Histogram Intersection kernel function. The Neural Network models we can apply the Hyperbolic tangent kernel function.

So things go fine but how can we make the process more powerful computationally and efficiently. Nature gives way for all, which it created. Quantum computing the new buzz word can be used as a Sause in our pasta to make it relish.

Thanks, IBM Qiskit team for availing the inbuild Quantum Support Vector Machine (QSVM) model to use in our classification model. Readers looking for QSVM kindly check my previous post on QSVM, here.

Let’s come back to the title of this post Quantum Kernel methods. Here, A technique for finding a hyperplane is applying a nonlinear transformation to the data, This is known as a “feature map”. We can either apply available qiskit feature maps like Ising model feature maps such as Z feature map, ZZ feature map, or Pauli feature map which contains Pauli (X, Y, Z) gates or Rawfeaturevector feature map.

Get Arthi Udayakumar’s stories in your inbox

Join Medium for free to get updates from this writer.

QSVM uses a Quantum processor to solve this problem by direct estimation of the kernel in the feature space. In the training phase, the kernel is estimated or calculated, and support vectors are obtained. But in applying the Quantum Kernel function directly, we should transform our training data and test data into appropriate quantum states. We can encode the training instances in a superposition in a register, and the test instances in another register using Amplitude Encoding. These two registers are put into entanglement using the Ancilla qubit.

Press enter or click to view image in full size
Quantum Kernel Ansatz circuit

The shallow circuit contains our desired kernel function as the Ansatz circuit. Ancilla qubit (ql0) |0> Superposition state entangle training qubit, Ancilla qubit |1> Superposition entangle with the testing qubit.ql1 is the index qubit, ql2 is the data qubit where training and test data are encoded. ql3 is the class/label qubit that results in the classification. A very good example is available in Qiskit Community tutorial git, here.

Reference for learning more about Q kernel:

https://www.nature.com/articles/s41534-020-0272-6

--

--