# Quantifying Quantum Coherence Using Machine Learning Methods
## 2 Materials and Methods
### The Feedforward Neural Network  
The feedforward neural network (FNN) is the earliest and simplest form of artificial neural networks (ANNs) introduced [43]. In this network structure, data flow in a single direction, from the input layer to the output layer. There are also other types of ANNs, such as recurrent neural networks, wherein connections between nodes may form loops. We adopt an FNN in the present paper. If using the backpropagation algorithm [44] to train the FNN, one also refers to this network model as BP neural network. In Figure 1, we depict the structure of the BP neural network. It comprises five layers: one input layer, three hidden layers, and one output layer. The number of hidden layers and the number of nodes in each hidden layer may be adjusted based on the specific problem and the performance of the predictions. The BP neural network can address both classification and regression problems. Since the network needs to output the ROC value of a quantum state, which is a continuous number, there is only one node in the output layer. The number of nodes in the input layer is related to the dimensionality of the density matrix and should equal the number of variables contained in the matrix elements. Specifically, if \(\rho\in\mathcal{D}(\mathbb{C}^{d})\), the number of nodes in the input layer will be \(d^{2}\) if we restrict to real entries, because it must match the number of matrix elements. While designing the number of nodes for the input and output layers is straightforward, designing the hidden layers is more complex [45]. There are several heuristics useful for designing the hidden layers, and the actual structure should ultimately be determined by its performance. Let us explore how backpropagation (BP) is utilized for training feedforward neural networks (FNNs). Each element in our dataset consists of matrix elements arranged in a vector \(\mathbf{x}\) and the corresponding ROC value \(y\). If the dataset \(\{(\mathbf{x}_{1},y_{1}),(\mathbf{x}_{2},y_{2}),\cdots,(\mathbf{x}_{N},y_{N})\}\) with \(N\) samples is collected, we have to randomly split it into two sets: one for training the model and the other one for testing the performance. The overall network operates through \(g(\mathbf{x})=f^{L}(W^{L}f^{L-1}(W^{L-1}\cdots f^{1}(W^{1}\mathbf{x})\cdots))\), where \(L\) represents the total number of layers, while \(W^{l}=(w^{l}_{jk})\) denotes the weight matrix connecting layer \(l-1\) to layer \(l\), with \(w^{l}_{jk}\) indicating the weight between the \(k\)-th node in layer \(l-1\) and the \(j\)-th node in layer \(l\). The function \(f^{l}\) denotes the activation function at layer \(l\), which is crucial for capturing nonlinear properties in the problem. In this study, we employ the ReLU activation function \(\text{ReLU}(x)=\max(0,x)\). The initialization of weights is typically randomized. Training the network is essential for adjusting these weights to minimize the average discrepancy between the network's prediction \(g(\mathbf{x})\) and the actual target \(y\). This discrepancy is measured using a loss function. We choose the mean-squared error (MSE) as the loss function:  
\[\text{MSE}=\frac{1}{N}\sum_{i=1}^{N}(g(\mathbf{x}_{i})-y_{i})^{2}, \tag{4}\]  
because for small errors, MSE can be advantageous due to its sensitivity to error magnitudes [46]. Updating the weight \(w^{l}_{ij}\) involves assessing how changes in \(w^{l}_{ij}\) impact the loss function \(E\). If \(\partial E/\partial w^{l}_{ij}>0\), increasing \(w^{l}_{ij}\) increases \(E\), so we subtract a suitable value \(\Delta w^{l}_{ij}\). To facilitate this, we employ a fixed learning rate \(\eta>0\). Similar reasoning applies when \(\partial E/\partial w^{l}_{ij}<0\). This technique is known as gradient descent, where \(\Delta w^{l}_{ij}=-\eta(\partial E/\partial w^{l}_{ij})\). A common issue in neural networks is overfitting, where the model performs exceptionally well on the training data but poorly on new, unseen data. To detect overfitting, a portion of the training data is reserved as a validation set.