# Data encoding in the quantum perceptron model

In this paper, this figure shows the perceptron model used for quantum neural network. When realizing the inner product between weight vector and input vector, it defines a unitary transformation $$U_W$$, such that $$U_W|\phi_W\rangle = |1\rangle^ {\otimes N}$$.

My question is, what's the intuition behind this? Why should the quantum state be $$|1\rangle^ {\otimes N}$$?

#### Why that $$|1\rangle^{\otimes N}$$?

The reason for requiring the final state to be $$|1\rangle^{\otimes N}$$, is that in this way you can easily propagate the information on an ancilla (i.e. additional) qubit using a multi controlled CNOT, with the target on the ancilla. In this way, measurements on the ancilla yield outcome $$|1\rangle$$ with probability given by the desired inner product $$\big|\sum_j i_jw_j\big|^2$$. In this model of a quantum perceptron, the ancilla measurement indicates the neuron's activation value: the higher the number of $$|1\rangle$$ measured, the higher the activation.

Note that you could also require that $$U_w |\phi_w\rangle$$ = $$|0\rangle^{\otimes N}$$, and then use again a multi controlled CNOT on the ancilla, but with the control states set to |$$0\rangle$$ instead of $$|1\rangle$$, and obtain the same result. This operation is usually depicted in the quantum circuit representation with the control circles colored white instead of black.

Anyway, the idea for such a scheme, it is that is then very natural to consider a quantum neural network structure: instead of measuring the ancilla qubit, you can input that qubit to a following layer of neurons, thus creating a fully coherent (because you don't need to measure) feed-forward architecture.

That's one part of the story.

#### But how do you realize $$U_w$$?

Remember that the goal of the neuron is to evaluate the inner product $$\langle \phi_w | \phi_i\rangle$$ between the input vector quantum state $$|\phi_i\rangle$$ and the weight vector quantum state $$|\phi_w\rangle$$. In addition, note that the requirement that $$U_w|\phi_w\rangle = |1\rangle^{\otimes N}$$ is equivalent to $$\langle \phi_w |= \langle 1|^{\otimes N} U_w^\dagger$$.
So it holds that (essentially Eqs. 5 and 6 form the paper): \begin{align} \langle \phi_w | \phi_i\rangle &= \langle 11..1|U_w^\dagger |\phi_i\rangle\\ & = \langle 11..1|U_w^\dagger U_i|0\rangle^{\otimes N} \\ & = \langle 11..1| \big(U_w^\dagger U_i|0\rangle^{\otimes N}\big)\\ \end{align}

So, you can see that evaluating the inner product $$\langle \phi_w | \phi_i\rangle$$ is equivalent to first apply $$U_i$$ to the blank register $$|0\rangle^{\otimes N}$$; then apply the operator $$U_w^\dagger$$ on the resulting state; and eventually measure the state and count the number of $$|11...1\rangle = |1\rangle^{\otimes N}$$ outcomes.
The explicit expression for $$U_w$$ is essentially the same of the operation $$U_i$$, with the obvious change of the parameters $$\vec{i} \rightarrow \vec{w}$$, and with the addition of a final layer of $$X$$ gates on all the qubits, in order to send them to the desired state $$|1\rangle^{\otimes N}$$. This method of computing inner values of quantum states is now often called as compute-uncompute method, with the only difference that in this case the final value is stored on the coefficient of the $$|1\rangle^{\otimes N}$$ state instead of state $$|0\rangle^{\otimes N}$$, as is the case for the standard compute-uncompute method.

Hope this helps you :)