Skip to content

FateZer0/QuantumMachineLearning

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

QuantumMachineLearning

Quantum Deep learning Binary Classification Code

This varational quantum circuit is capable of classifiying 3s and 6s from the MNIST dataset with an accuracy of 95.5%.

Credit: The code to encode the image data onto the qubits was provided by Samuel Stein, Fordham University.

Abstract: Creating a neural network using only a quantum computer is challenging due to the fundamental differences between quantum and classical computers. This research describes a solution to this problem by creating a hybrid system that uses a quantum computer and a classical computer to mimic a deep neural net. This is called a variational circuit and can be used for many problems such as regression, classification, autoencoders, etc., depending on the circuit design. The main purpose of this study was to create a variational circuit capable of accurately classifying images of handwritten digits from the MNIST dataset. The variational quantum circuit obtained an accuracy of 95.35% in its classification of threes and sixes.

Introduction:Classical Computing: Classical computers use bits to encode data, a singular bit can be represented as a 0 or a 1. A machines power increases in a 1:1 relationship with the number of transistors.Quantum Computing:Quantum computers use qubits to encode data, a qubit can represent 0 or 1, or 0 and 1 simultaneously (before being measured). Quantum computers can represent 2n states with n qubits, meaning their power scales exponentially compared to classical computers. Quantum superposition allows qubits to be in multiple states simultaneously before being measured. Variational Circuit:A variational Circuit is a trainable hybrid system where a classical computer and a quantum computer are used together to build a trainable system that mimics a classical neural network.

Methodology/Process: Data was retrieved from the MNIST dataset (an image dataset of handwritten digits). We specifically looked into classifying images of threes and sixes. Of the 14,032 images, 12,032 were used for training and 2,000 were kept for testing. The only data pre-processing done was downscaling the image sizes from 28x28 pixels, shown in figure 1, to 8x8 which is shown in figure 2. The image data is then re-shaped down to a one dimensional vector with 64 features where each feature is one grayscale pixel value. 64 features are then encoded onto only 6 qubits. We takethe upper bound of log2(n_features).Our circuit has 7 qubits where 6 qubits have input data encoded on them and 1 qubit has no input. The circuit has one classical bit that is used to hold an output value of 0 or 1. Our circuit has 27 parametrized gates that are analogous to classical neural network weights. Our goal is to use this variational circuit to mimic a classical neural network and then use the parameter shift rule along with binary cross entropy loss to perform mini-batch gradient descent and train our circuit.The quantum circuit is then trained using mini-batch gradient descent with 64 batches. To train the circuit, we first randomly initialized the weights of the quantum gates between 0 and π. Since the qubits in our circuit are quantumly entangled, we cannot use classical backpropagation. Instead, we use what is known as the parameter shift rule. This equation calculates how much to change the quantum gates’ parameter by in hopes to minimize our loss function (Binary Cross Entropy Loss fig.5). We execute this equation by first changing our current quanum gates θ by +and measuring the cost of our output over one batch or 188 images, and then doing the same with - . Once we have these two costs, we subtract costFunction( θ+ ) by costFunction( θ- ) and divide the result by 2. We then shift the current quantum gates θ by thatnumber multiplied by a learning rate which is 1 in our case.

Results: After training the quantum circuit on 12,032 images of threes and sixes, the model was able to classify 2,000 unseen images with an accuracy of 95.35%. These results are competitive with some of the best quantum circuits in other research papers. During the training of the circuit the accuracy and loss was recorded and can be seen below in figures 7 and 8.The same model architecture was used to train a circuit with 4x4 images instead of 8x8. This model had an accuracy of 92.5%. For future research we can extend our networks capabilities handle multiclass-classification. Another optimization that could be beneficial would be using quantum natural gradient descent instead of mini-batch gradient. Quantum natural gradient descent is a method of gradient descent that is specifically optimized to traverse the quantum landscape which allows the function to find local minima quicker. This method of gradient descent reduces training time and can increase the accuracy of the model. Another optimization could be testing different loss functions

About

Quantum Deep learning Binary Classification

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 100.0%