# Quantum-Inspired Neural Network Model of Optical Illusions
## 2 Deep Neural Network Algorithm  
The architecture of the neural network used in this work is illustrated in Figure 3. The network consists of an input layer that has \(L=100\) input nodes, three hidden layers each of which has \(N=20\) nodes and an output layer that has \(M=2\) output nodes that are used to classify the perceptual state of the Necker cube. The weights of the connections of the network are updated using a cross-entropy-driven back-propagation algorithm [71; 72]. The learning rate parameter used in all computations is \(\alpha=0.01\). Figure 3: Sketch of the deep neural network architecture used to model the perception of the Necker cube. The network consists of an input layer, three hidden layers and an output layer that has two nodes. Labels \(W^{(n)}\) with \(n=1\ldots 4\) denote the matrices of the weights of network connections. The network is trained using the images of the Necker cube with the shaded front and rear faces that correspond to \(|0\rangle=[0\,1]\) and \(|1\rangle=[1\,0]\) training states, respectively. Characters \({}^{\prime}|0\rangle^{\prime}\) and \({}^{\prime}|1\rangle^{\prime}\) are not part of the training images. The test input is an image of the ambiguous Necker cube. All input images consist of a total of 100 pixels. Individual pixels of each image form input vector \(x_{j}\) with \(j=1\ldots 100\). The activation function of the nodes of the hidden layers is represented by the Rectified Linear Unit (ReLU) that can be defined as [71; 72]  
\[\phi_{ReLU}(x_{j})= \begin{cases}x,&x_{j}>0\\ 0,&x_{j}\leq 0\end{cases} , \tag{1}\]  
where \(j=1\ldots L\) is the index denoting the sequential number of the input node and \(x_{j}\) is the output from this node. As the activation function of the output nodes we choose the Softmax function that accounts not only for the weighted sum of the inputs to the given node but also for the inputs to the other output nodes [71; 72]. This function is  
\[\phi_{smax}(v_{i})=\frac{\exp(v_{i})}{\sum_{k=1}^{M}\exp(v_{k})}\,, \tag{2}\]  
where \(v_{i}\) is the weighted sum of the input signals to the \(i\)th output node and \(M\) is the total number of the output nodes. The use of Equation (2) enables satisfying probability normalisation condition \(\sum_{k=1}^{M}\phi_{smax}(v_{k})=1\). The network is trained using the following procedure [72]:  
1. Construct two output nodes that correspond to \(\ket{0}=[1\ 0]\) and \(\ket{1}=[0\ 1]\) perceptual states of the Necker cube;
2. Initialise the weights of the neural network in the range from \(-1\) to \(1\) using a random number generator;
3. Enter input data \(x_{j}\) and corresponding training data \(d_{i}\) that encode the perceptual states of the Necker cube (the top and the middle illustrations on the left of Figure 3);
4. Calculate error \(e_{i}\) between output \(y_{i}\) and target \(d_{i}\) as \(e_{i}=d_{i}-y_{i}\);
5. Propagate output \(\delta_{i}=e_{i}\) in the backward direction of the network and compute respective parameters \(\delta_{i}^{(n)}\) of the hidden nodes using equations \(e_{i}^{(n)}={W^{(n)}}^{\top}\delta_{i}\) and \(\delta_{i}^{(n)}=\phi_{ReLU}^{\prime}\Big{(}v_{i}^{(n)}\Big{)}e_{i}^{(n)}\), where index \(n\) denotes the sequential number of the hidden layer, prime denotes the derivative of the activation function and \(W^{\top}\) is the transpose of the matrix of weights corresponding to each relevant layer of the network. 6. Repeat Step 5 until the back-propagation algorithm reaches the first hidden layer;
7. Update the weights using learning rule \(w_{ij}^{(n)}:=w_{ij}^{(n)}+\Delta w_{ij}^{(n)}\), where \(w_{ij}^{(n)}\) are the weights between output node \(i\) and input node \(j\) of the \(n\)th layer and \(\Delta w_{ij}^{(n)}=\alpha\delta_{i}^{(n)}x_{j}\);
8. Repeat Steps 4-7 for all values of the training data set;
9. Repeat Steps 4-8 until the neural network is trained with desired accuracy. The exploitation process essentially reproduces Steps 1-3 [72]. We establish that it suffices to use 1000 epochs to obtain convergent results in all calculations.