# Linear Optics Calibration in a Storage Ring Based on Machine Learning
## 2 Materials and Methods
### Theory of Linear Optics Calibration
#### 2.1.2 Machine Learning Theory
After convolution, the input data must be added to the bias and then calculated by the activation function to  
Figure 1: Schematic illustration of a neuron. obtain the output data of the convolutional layer. Assuming that the kernel size is \(p\times q\), the output of a single kernel can be written as:  
\[O_{x,y}=f\left(\sum_{i}^{p\times q}w_{i}l_{i}+b\right), \tag{1}\]  
where \(l\) is the input data, \(w\) is the weight, \(b\) is the bias, \(f\) is the activation function, \(O\) is the output data, and \(x,y\) is the spatial coordinate of the output data. The output data mentioned here are also called the feature map. In the case of \(n\) kernels, the obtained feature map is expanded to \(n\) dimensions, representing the \(n\) features extracted from the input data. In a CNN, the samples are the collection of features and can be labeled or unlabeled. The labels are the true conclusions of the predicted properties and can be understood as the correct answers. The features are the inherent characteristics of things that can be understood as the basis for obtaining true conclusions, and they are usually used as input variables for the neural network model. Labeled samples are used for model training, and unlabeled samples are used for model prediction. The output data in a good neural network model should be as close as possible to the labels corresponding to the input features. For different types of data, different loss functions are usually set to measure the errors of the output signals and labels. The training process of a CNN is then to find a set of \(w\) and \(b\) that minimizes the loss function. For supervised learning, the error back propagation method, which was proposed by [PERSON] in 1989 [28], is the most common optimization algorithm. The error is propagated backward from the output layer until it reaches the input layer. In this process, the gradient of \(w\) and \(b\) in the network is calculated using the chain rule and changes in the opposite direction of the gradient. This is called gradient descent optimization [32]. The process of updating parameters by the gradient descent method can be written as:  
\[\mathbf{w}^{(n)}=\mathbf{w}^{(n)}-\alpha\frac{\partial E}{\partial w^{(n)}}, \tag{2}\]  
and  
\[\mathbf{b}^{(n)}=\mathbf{b}^{(n)}-\alpha\frac{\partial E}{\partial b^{(n)}}, \tag{3}\]  
Figure 2: An example of convolution with a stride of 1.  
where \(E\) is the error calculated by the loss function and \(\alpha\) is the learning rate. The learning rate is used to control the range of weight adjustment. If the learning rate is set too small, the model converges slowly, and if it is set too large, it may cross the optimal point during training. When the training process is complete, the resulting CNN should be able to predict the unlabeled samples. We can then use the trained model to achieve our physical goals. We want to use the CNN to output the strength of the quadrupoles, which corresponds to the input \(\Delta R\). Figure 3 shows a schematic illustration of the machine-learning-based method for linear optics calibration. More details on the experimental methods are discussed in the next section. The machine-learning-based method actually establishes the nonlinear mapping relationship between the \(\Delta R\) and the quadrupole errors. The method is similar to a \"black box\". In this way, the strength of quadrupoles can be directly predicted from the measured response matrix data. Unlike the traditional LOCO method, the new method does not require SVD calculation and multiple iterations.