{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Quantum Classifier\n", "\n", " Copyright (c) 2021 Institute for Quantum Computing, Baidu Inc. All Rights Reserved. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview\n", "\n", "In this tutorial, we will discuss the workflow of Variational Quantum Classifiers (VQC) and how to use quantum neural networks (QNN) to accomplish a **binary classification** task. The main representatives of this approach include the [Quantum Circuit Learning (QCL)](https://arxiv.org/abs/1803.00745) [1] by Mitarai et al. (2018), Farhi & Neven ( 2018) [2] and [Circuit-Centric Quantum Classifiers](https://arxiv.org/abs/1804.00633) [3] by Schuld et al. (2018). Here, we mainly talk about classification in the language of supervised learning. Unlike classical methods, quantum classifiers require pre-processing to encode classical data into quantum data, and then train the parameters in the quantum neural network. Finally, we benchmark the optimal classification performance through test data.\n", "\n", "### Background\n", "\n", "In the language of supervised learning, we need to enter a data set composed of $N$ groups of labeled data points $D = \\{(x^k,y^k)\\}_{k=1}^{N}$ , Where $x^k\\in \\mathbb{R}^{m}$ is the data point, and $y^k \\in\\{0,1\\}$ is the label associated with the data point $x^k$. **The classification process is essentially a decision-making process, which determines the label attribution of a given data point**. For the quantum classifier framework, the realization of the classifier $\\mathcal{F}$ is a combination of a quantum neural network (or parameterized quantum circuit) with parameters $\\theta$, measurement, and data processing. An excellent classifier $\\mathcal{F}_\\theta$ should correctly map the data points in each data set to the corresponding labels as accurate as possible $\\mathcal{F}_\\theta(x^k ) \\rightarrow y^k$. Therefore, we use the cumulative distance between the predicted label $\\tilde{y}^{k} = \\mathcal{F}_\\theta(x^k)$ and the actual label $y^k$ as the loss function $\\mathcal {L}(\\theta)$ to be optimized. For binary classification tasks, we can choose the following loss function,\n", "\n", "$$\n", "\\mathcal{L}(\\theta) = \\sum_{k=1}^N |\\tilde{y}^{k}-y^k|^2. \\tag{1}\n", "$$\n", "\n", "### Pipeline\n", "\n", "Here we give the whole pipeline to implement a quantum classifier under the framework of quantum circuit learning (QCL).\n", "\n", "1. Apply the parameterized quantum circuit $U$ on the initialized qubit $\\lvert 0 \\rangle$ to encode the original classical data point $x^k$ into quantum data that can be processed on a quantum computer $\\lvert \\psi_{in}\\rangle^k$.\n", "2. Apply the parameterized circuit $U(\\theta)$ with the parameter $\\theta$ on input states $\\lvert \\psi_{in} \\rangle^k$, thereby obtaining the output state $\\lvert \\psi_{out} \\rangle^k = U(\\theta)\\lvert \\psi_{in} \\rangle^k$.\n", "3. Measure the quantum state $\\lvert \\psi_{out}\\rangle^k$ processed by the quantum neural network to get the estimated label $\\tilde{y}^{k}$.\n", "4. Repeat steps 2-3 until all data points in the data set have been processed. Then calculate the loss function $\\mathcal{L}(\\theta)$.\n", "5. Continuously adjust the parameter $\\theta$ through optimization methods such as gradient descent to minimize the loss function. Record the optimal parameters after optimization $\\theta^* $, and then we obtain the optimal classifier $\\mathcal{F}_{\\theta^*}$.\n", "\n", "![QCL](figures/qclassifier-fig-pipeline.png \"Figure 1: Flow chart of quantum classifier training\")\n", "