Skip to content

Commit cd368da

Browse files
committed
Modifying quantum perceptron
1 parent 3b27356 commit cd368da

9 files changed

+325
-205
lines changed

algpseudocode/TEMPLATE.tex

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
\usepackage{algorithm}
44
\usepackage{algpseudocode}
55
\usepackage{braket}
6-
\usepackage{amsmath}
6+
\usepackage{amsmath, amsfonts, amssymb}
77

88
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}
99

@@ -20,7 +20,7 @@
2020

2121
\Require
2222
\Ensure
23-
\vspace{10pt}
23+
\vspacae{10pt}
2424
\Statex
2525
\State
2626

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
\documentclass{article}
2+
\usepackage[utf8]{inputenc}
3+
\usepackage{algorithm}
4+
\usepackage{algpseudocode}
5+
\usepackage{braket}
6+
\usepackage{amsmath, amsfonts, amssymb}
7+
8+
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}
9+
10+
\makeatletter
11+
\renewcommand{\fnum@algorithm}{\fname@algorithm}
12+
\makeatother
13+
14+
\begin{document}
15+
\pagestyle{empty}
16+
% #Classical perceptron algorithm
17+
\begin{algorithm}[ht]
18+
\caption{Quantum online perceptron training}
19+
\begin{algorithmic}[1]
20+
\Require Quantum access to a dataset $\mathcal{D}=\{ (x^{(1)},y^{(1)}), (x^{(2)}, y^{(2)} ) ,\ldots, ( x^{(n)},y^{(n)})\} \in (\mathbb{R}^{m} \times\{0,1\})^{n}$ via a unitary $U: |j\rangle|{0}\rangle \rightarrow |j\rangle|x^{(j)}\rangle$. An oracle $\mathcal{F}_w$ that can be adapted to the weights $w$ at each iteration.
21+
\Ensure A vector of weights $w$ such that $P\left(\exists j: f_{w}\left(x^{(j)}, y^{(j)}\right)=1\right) \leq \epsilon$
22+
23+
\State Initialize the weights vector $w = 0 \in \mathbb{R}^{m+1}$.
24+
\For {\(h=1, \ldots,\left\lceil \frac{1}{\gamma^{2}}\right\rceil\)}
25+
26+
\For {\(k=1, \ldots,\left\lceil\log \left(\frac{1}{\gamma^{2} \epsilon}\right)\right\rceil\)}
27+
28+
\State Apply Grover's algorithm using $U$ and $\mathcal{F}_w$ on $\frac{1}{\sqrt{n}}\sum_{j=1}^{n} |j\rangle|0\rangle$.
29+
30+
\State Measure the first register of the resulting state $\sum_{j=1}^{n} \alpha_j|j\rangle|0\rangle$.
31+
32+
\If{$f_{w}(x^{(j)}, y^{(j)})=1$ classically}
33+
\State Update $w^{\prime} \leftarrow w+\Delta w \phi$.
34+
\State Update the oracle $\mathcal{F}_w = \mathcal{F}_{w^{\prime}}$.
35+
\EndIf
36+
37+
\EndFor
38+
39+
\EndFor
40+
41+
\Return $w^{\prime}=0$.
42+
\end{algorithmic}
43+
\end{algorithm}
44+
45+
\end{document}

algpseudocode/perceptronalgo.tex

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
\documentclass{article}
2+
\usepackage[utf8]{inputenc}
3+
\usepackage{algorithm}
4+
\usepackage{algpseudocode}
5+
\usepackage{braket}
6+
\usepackage{amsmath, amsfonts, amssymb}
7+
8+
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}
9+
\algdef{SE}[DOWHILE]{Do}{doWhile}{\algorithmicdo}[1]{\algorithmicwhile\ #1}%
10+
11+
\makeatletter
12+
\renewcommand{\fnum@algorithm}{\fname@algorithm}
13+
\makeatother
14+
15+
\begin{document}
16+
\pagestyle{empty}
17+
% #Classical perceptron algorithm
18+
\begin{algorithm}[ht]
19+
\caption{Classical online perceptron training}
20+
\begin{algorithmic}[1]
21+
\Require A dataset $\mathcal{D}=\{ (x^{(1)},y^{(1)}), (x^{(2)}, y^{(2)} ) ,\ldots, ( x^{(n)},y^{(n)})\} \in (\mathbb{R}^{m} \times\{0,1\})^{n}$
22+
\Ensure A vector of weights $w$ such that $y^{(j)}(w^\top x^{(i)}) > 0$ for all $j \in \{1, \dots, n\}$
23+
\State Initialize ${w}:={0} \in \mathbb{R}^{m+1}$
24+
\State $\mathrm{continue}=0$
25+
\Do
26+
\For {every data point $\left(x^{(j)}, y^{(j)}\right) \in \mathcal{D}$}
27+
\State Compute the prediction $\hat{y}^{[i]}:=\sigma\left(\mathbf{x}^{[i]T} {w}_{i}+b\right)$
28+
\State Compute the $\mathrm{error}:=\left(\hat{y}^{(i)}-{y}^{(i)}\right)$
29+
\State $\mathrm{continue} = \mathrm{continue} + |\mathrm{error}|$
30+
\State Update the weights ${w}_{i}^{'}:={w}_{i}+\Delta{w}$
31+
\EndFor
32+
33+
\doWhile{$\mathrm{continue}!=0$}
34+
\end{algorithmic}
35+
\end{algorithm}
36+
37+
\end{document}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
\documentclass{article}
2+
\usepackage[utf8]{inputenc}
3+
\usepackage{algorithm}
4+
\usepackage{algpseudocode}
5+
\usepackage{braket}
6+
\usepackage{amsmath, amsfonts, amssymb}
7+
8+
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}
9+
10+
\makeatletter
11+
\renewcommand{\fnum@algorithm}{\fname@algorithm}
12+
\makeatother
13+
14+
\begin{document}
15+
\pagestyle{empty}
16+
\begin{algorithm}[ht]
17+
\caption{Quantum version space perceptron training}
18+
\begin{algorithmic}[1]
19+
\Require Quantum access to a set of weight vectors $\{w^{(1)}, \ldots, w^{(k)}\}$ sampled from a Gaussian spherical distribution, via a unitary $U: |j\rangle|{0}\rangle \rightarrow |j\rangle|w^{(j)}\rangle$. An oracle $\mathcal{F}$ such that $\mathcal{F}|w^{(j)}\rangle=(-1)^{1+\left(f\left(w^{(j)},x^{(1)}, y^{(1)}\right) \vee \cdots \vee f\left(w^{(j)},x^{(n)}, y^{(n)}\right)\right)}|w^{(j)}\rangle$.
20+
\Ensure A vector of weights $w$ such that $P\left(\exists j: f_{w}\left(x^{(j)}, y^{(j)}\right)=1\right) \leq \epsilon$
21+
22+
\State Initialize $k = \frac{1}{\gamma}\log(1/\epsilon)$.
23+
\For {\(h = 1, \ldots,\left\lceil\log \epsilon\right\rceil\)}
24+
25+
\State Apply Grover's algorithm using $U$ and $\mathcal{F}$ on $\frac{1}{\sqrt{k}}\sum_{j=1}^{k} |j\rangle|0\rangle$.
26+
27+
\State Measure the first register of the resulting state $\sum_{j=1}^{n} \alpha_j|j\rangle|0\rangle$ and call the output $j$.
28+
29+
\If{\(f\left(w^{(j)}, x^{(i)}, y^{(i)}\right)=0\) for all \(i \in\{1, \ldots, n\}\)}
30+
31+
\State Return $w_j$.
32+
33+
\EndIf
34+
35+
\EndFor
36+
37+
\State \Return $w=0$.
38+
\end{algorithmic}
39+
\end{algorithm}
40+
41+
\end{document}

images/online_quantum_perceptron.png

78.9 KB
Loading

images/perceptronalgo.png

56.1 KB
Loading
72.9 KB
Loading

0 commit comments

Comments
 (0)