网络参数可视化
The goal of this post is to explain the parameterized binary classifier of a quantum state in the case of 1 qubit. This simple case allows us to have some nice visualizations and even some analytical expressions.
这篇文章的目的是解释在1量子位的情况下量子态的参数化二进制分类器。 这个简单的案例使我们可以有一些不错的可视化甚至解析表达式。
The first part will state the results and display the figures, whereas the technical proofs will be left to the second part. So if you don’t like equations, you can stop reading after the first part.
第一部分将陈述结果并显示数字,而技术证明将留给第二部分。 因此,如果您不喜欢方程式,可以在第一部分之后停止阅读。
I encourage everyone not familiar with the spherical coordinates to have a look here, since it is the core of this post.
我鼓励所有不熟悉球坐标的人在这里看看,因为它是本文的核心。
This post is not an introduction to quantum computing, here is one of the clearest video about it. Here is a more detailed article.
这篇文章不是量子计算的介绍,这是关于它的最清晰的视频之一。 这是更详细的文章。
All the figures have been created with the library QuTip.
所有图形都是使用库QuTip创建的。
可视化和结果 (Visualizations and results)
布洛赫球(The Bloch sphere)
A quantum state can be represented as a complex vector |Ψ> = ????|0>+????|1> such as |????|² + |????|² = 1. It is also defined up to a global phase, and we can write |Ψ> = cos(????/2)|0> + e^(iϕ)sin(????/2)|1> with ???? ∈ [0, π] and ϕ∈ [0, 2π]. The couple (????, ϕ) defines a point on the unit sphere of R^3, and such a representation of the qubit is called the Bloch sphere.
量子态可以表示为复矢量|Ψ> =????| 0> +????| 1>,例如|????|²+ |????|²=1。它也可以定义为一个全局相位,我们可以用????∈[0,π]和ϕ∈ [0,2π]来写|Ψ> = cos(???? / 2)| 0> + e ^(iϕ)sin(???? / 2)| 1>。 偶对(????,defines)在R ^ 3的单位球面上定义了一个点,这样的qubit表示称为Bloch球。
Here is an example of quantum states represented in the Bloch sphere. In blue the state |0>, in red the state |1> and in green the state 1/√2 (|0> + |1>).
这是布洛赫球中表示的量子态的示例。 蓝色为| 0>状态,红色为| 1>状态,绿色为1 /√2(| 0> + | 1>)。
量子态的二元分类器。 (Binary classifier of quantum states.)
As in a classical classification problem, we suppose that for each quantum state is associated a label y in {0, 1}. We have this label observed for a set of states called the training set, and we wish to construct a function which predicts the label of a new quantum state. We wish to construct a parameterized unitary operator U(⍺) such as
就像在经典分类问题中一样,我们假设对于每个量子态,{0,1}中的标记y都与之相关。 我们观察到了称为训练集的一组状态的标签,并且我们希望构建一个预测新量子状态标签的函数。 我们希望构造一个参数化unit运算符U(⍺),例如
U(⍺)|Ψ(x)> =√P(y=0)|0> + √P(y=1)|1>
U(⍺) |Ψ(x)> = √P (y = 0)| 0 > + √P (y = 1)| 1>
The probabilities are estimated by measuring the quantum state. One can then compute a cost function, and update the parameters ⍺ with a classical optimizer.
通过测量量子态来估计概率。 然后可以计算成本函数,并更新参数⍺用经典的优化。
We will not talk about that in this post, the objective is to visualize the effect of a parameterized classifier on the Bloch sphere.
在本文中,我们不会谈论这一点,其目的是可视化参数化分类器对Bloch球的影响。
分类器的基本属性 (Basic properties of the classifiers)
Fortunately, in the one qubit case, the unitary operators are quite simple, and can be fully characterized by 3 parameters. The general form is given by the following formula.
幸运的是,在一个量子比特的情况下,the运算符非常简单,并且可以通过三个参数来充分表征。 一般形式由以下公式给出。
It means that we only have to look at this family of matrices to find our candidate classifier. Moreover, we can prove that the parameter ϕ has no influence on the final probability. It reduces us to the final following form.
这意味着我们只需要查看这个矩阵族即可找到我们的候选分类器。 此外,我们可以证明参数ϕ对最终概率没有影响。 它将我们简化为最终的以下形式。
边界的属性 (Properties of the border)
The border is defined by the set of points for which P(y=0) = P(y=1) = 1/2. In the case of a binary classifier on one qubit, this border is a circle that cuts the Bloch sphere in two equal hemispheres. One hemisphere contains all the quantum states classified as 0 and the other contains all the quantum states classified as 1.
边界由P(y = 0)= P(y = 1)= 1/2的点集定义。 在一个量子位上使用二进制分类器的情况下,该边界是一个将Bloch球切成两个相等的半球的圆。 一个半球包含所有归类为0的量子态,另一个半球包含所有归类为1的量子态。
可视化 (Visualizations)
Let us now visualize what the results of the classifiers look like. For each following graph, we plot the classification regions in red and blue which have been computed by a quantum simulator. The border is drawn in black, knowing the equation of the circle.
现在让我们可视化分类器的结果。 对于以下每个图形,我们用量子模拟器计算出的红色和蓝色分类区域。 知道圆的方程后,边框以黑色绘制。
Below are the results for ???? = 0 and ???? = π and in both cases λ = 0. Completely flipping ???? doesn’t change the place of the border which is in the plan (x,y), but the labels are inverted.
以下是???? = 0和???? = π以及两种情况下λ= 0的结果。完全翻转????不会改变平面(x,y)中边界的位置,但是标签被反转了。
We’ll now have a look at ???? = π/2 still with λ = 0. The border has rotated from the plan (x,y) to the plan (y,z).
现在我们来看看仍为λ= 0的???? = π/ 2。边界从平面(x,y)旋转到平面(y,z)。
Now, more general values with ???? = π/6, and λ = 0, λ = 3π/2. Modifying λ while keeping ???? constant is like spinning the sphere around the z axis.
现在,具有general = π/ 6,λ= 0,λ=3π/ 2的更通用的值。 在保持????不变的同时修改λ 就像围绕z轴旋转球体一样。
数学 (The maths)
Let us now prove in details everything we’ve seen before.
现在让我们详细证明我们之前所见过的一切。
证明ϕ不影响概率。 (Proof that ϕ doesn’t influence the probability.)
Let |Ψ> =⍺|0> + β|1> be a general quantum state, and let us look at the effect of a general unitary U(????, ϕ, λ).
令|Ψ> = ⍺| 0 > +β| 1 >是一般的量子态,让我们看一下一般unit U(ary,ϕ,λ)的作用。
U|Ψ> = cos(????/2)⍺|0> + e^(iϕ)sin(????/2)⍺|1> + (-sin(????/2)e^(iλ)β)|0> + e^(iϕ+iλ)cos(????/2)β|1> = [cos(????/2)⍺+ (-sin(????/2)e^(iλ)β)]|0> + [e^(iϕ)sin(????/2)⍺ + e^(iϕ+iλ)cos(????/2)β]|1>
U |Ψ> = cos(???? / 2) ⍺ | 0> + e ^(iϕ)sin(???? / 2) ⍺ | 1> +(-sin(???? / 2)e ^(iλ)β)| 0> + e ^(iϕ +iλ)cos(???? / 2)β| 1> = [cos(???? / 2) ⍺ +(- sin (???? / 2)e ^(iλ)β)] | 0> + [e ^(iϕ)sin(???? / 2) ⍺ + e ^(iϕ +iλ)cos(???? / 2)β] | 1>
We now take the module square of the amplitude associated to |1>.
现在,我们取与| 1>相关的振幅的模平方。
And we have P(y=1) = |e^(iϕ)sin(????/2)⍺ + e^(iϕ+iλ)cos(????/2)β|²= |e^(iϕ)|²|sin(????/2)⍺ + e^(iλ)cos(????/2)β|² =|sin(????/2)⍺ + e^(iλ)cos(????/2)β|²
而且我们有P(y = 1)= | e ^(iϕ)sin(???? / 2) ⍺ + e ^(iϕ +iλ)cos(???? / 2)β|²= | e ^(iϕ)|²| sin(???? / 2) ⍺ + e ^(iλ)cos(???? / 2)β|²= | sin(???? / 2) ⍺ + e ^(iλ)cos(???? / 2) )β|²
Therefore, the classification probabilities are independent of ϕ.
因此,分类概率与independent无关。
边界方程。 (Equation of the border.)
Let |Ψ> = cos(????/2)|0> + e^(iϕ)sin(????/2)|1> and let us consider the unitary U(Θ, λ) defined the following way.
令|Ψ> = cos(???? / 2)| 0> + e ^(iϕ)sin(???? / 2)| 1>,让我们考虑以下列方式定义的unit U(Θ,λ)。
It is like setting ϕ=0 in the previous paragraph.
就像在上一段中设置ϕ = 0一样。
We then have that the probability to be classified 1 is:
然后,我们可以将分类为1的概率为:
P(y=1) = |sin(Θ/2)cos(????/2) + e^(iλ+iϕ)cos(Θ/2)sin(????/2)|² when replacing ⍺ and β with their expressions. Please do not confuse this ϕ with the one in the previous paragraph.
P(Y = 1)= | SIN(Θ/ 2)cos(θ/ 2)+ E ^(Iλ+Iφ)COS(Θ/ 2)SIN(θ/ 2)| 2更换时⍺和 β及其表达式。 请不要将此ϕ与上一段中的混淆。
Expanding the full expression gives us
扩展完整的表达方式使我们
We can reduce the last two terms using the fact that cos²+sin²=1, and we can reduce the second term by using the identity sin(2⍺) = 2cos(⍺)sin(⍺).
我们可以用事实降低了最后两项是cos²+sin²= 1,我们可以使用标识罪(2⍺)= 2COS(⍺)罪(⍺)减少的第二项。
We then use the identities sin(⍺/2) = (1-cos(⍺))/2 and cos(⍺/2) = (1+cos(⍺))/2 and we have
然后我们使用恒等式sin(⍺/ 2)=(1-cos(⍺))/ 2和cos(⍺/ 2)=(1 + cos(⍺))/ 2
The border is such as P(y=1) = 1/2. Therefore, it is the set of (????, ϕ) such as cos(λ+ϕ)sin(Θ)sin(????) - cos(Θ)cos(????) = 0.
边界例如为P(y = 1)= 1/2。 因此,它是(????,ϕ)的集合,例如cos(λ+ ϕ)sin(Θ)sin(????)-cos(Θ)cos(????)= 0。
Equation of the border:
边界方程:
cos(λ+ϕ)sin(Θ)sin(????) — cos(Θ)cos(????) = 0
cos(λ+ ϕ)sin(Θ)sin(????)— cos(Θ)cos(????)= 0
We will then show that this equation characterizes a circle on the unit sphere centered in the origin.
然后,我们将证明该方程式描述了以原点为中心的单位球面上的一个圆。
球坐标系中的圆方程 (Equation of a circle in spherical coordinates)
A circle on the unit sphere centered in the origin can be fully characterized by a normal vector, as shown in the figure below. Let xᵤ = (????ᵤ, ϕᵤ) the coordinates of this vector.
单位球上以原点为中心的圆可以完全由法线向量表征,如下图所示。 令xᵤ = ( ????ᵤ,ϕᵤ )此向量的坐标。
Let (????, ϕ) a point of the circle. The orthogonality with xᵤ can be written as:
令(????,ϕ)为圆的点。 与xᵤ的正交性可以写为:
sin(????ᵤ)cos(ϕᵤ)sin(????)cos(ϕ) + sin(????ᵤ)sin(ϕᵤ)sin(????)sin(ϕ) + cos(????ᵤ)cos(????) = 0
sin( ????ᵤ )cos( ϕᵤ )sin(????)cos(ϕ)+ sin( ????ᵤ )sin( ϕᵤ )sin(????)sin(ϕ)+ cos( ????ᵤ )cos(????)= 0
sin(????ᵤ)sin(????)(cos(ϕᵤ)cos(ϕ) + sin(ϕᵤ)sin(ϕ)) + cos(????ᵤ)cos(????) = 0
sin( ????ᵤ )sin(????)(cos( ϕᵤ )cos(ϕ)+ sin( ϕᵤ )sin(ϕ))+ cos( ????ᵤ )cos(????)= 0
By using the trigonometry addition formulae,
通过使用三角加法公式,
sin(????ᵤ)sin(????)cos(ϕᵤ+ϕ) + cos(????ᵤ)cos(????) = 0
sin(????ᵤ)sin(????)cos(ϕᵤ + ϕ)+ cos(????ᵤ)cos(????)= 0
Our final circle equation is:
我们最终的圆方程为:
sin(????ᵤ)sin(????)cos(ϕᵤ+ϕ) + cos(????ᵤ)cos(????) = 0
sin( ????ᵤ )sin(????)cos( ϕᵤ + ϕ)+ cos( ????ᵤ )cos(????)= 0
By identifying the terms in cos(λ+ϕ)sin(Θ)sin(????) — cos(Θ)cos(????) = 0 (previous paragraph), we have ϕᵤ=λ, and ????ᵤ=π-Θ.
通过确定cos(λ+ ϕ)sin(Θ)sin(????)-cos(Θ)cos(????)= 0 (上一段)中的项,我们有ϕᵤ =λ,????ᵤ =π-Θ。
Therefore, the border is a circle, for which we can compute the equation given the initial unitary parameters.
因此,边界是一个圆,在给定初始unit参数的情况下,我们可以为其计算方程。
And this is it, some visualizations on quantum classifiers, and the proofs coming along. Parameterized quantum classifier are fully explained in this paper by Maria Schuld et al.
就是这样,有关量子分类器的一些可视化以及随之而来的证明。 Maria Schuld等人在本文中充分解释了参数化量子分类器。
Feel free to share your feedback, you can contact me on LinkedIn, or post a response to the article.
随时分享您的反馈,您可以在LinkedIn上与我联系,或发布对本文的回复。
翻译自: https://towardsdatascience.com/visualizing-parameterized-quantum-classifiers-e5dfb0c584ba
网络参数可视化