# Piston Error Measurement for Segmented Telescopes Based on a Hybrid Artificial Neural Network
## 3 Simulation
### Simulation on Two Sub-Mirrors Segmented Telescope System  
MATLAB software was used to build the simulation optical system model consisting of two hexagonal sub-mirrors as, shown in Figure 2. The specific system parameters were the same as those set in Section 2.1. During the simulation experiment, the left sub-mirror of the system was set as the reference sub-mirror, and a series of piston errors were introduced on the right sub-mirror. Here, we firstly generated 60,000 sets of piston errors in [\(-\)10-10] \(\upmu\)m randomly and 60,000 sets of focal plane degradation images were obtained by MATLAB simulation. Then, by taking the corresponding piston errors into Equation (10), we obtained 60,000 sets of the MTF sidelobes values. The generated data sets were divided into three groups, namely the training set, verification set, and test set. The proportion of the three parts was 65%:20%:15%, namely 39,000 groups for training, 12,000 groups for verification, and 9000 groups for testing. Then, the network training was be processed based on the obtained data sets. Here we built a Pytorch deep learning environment on an Ubuntu server equipped with Intel i7 CPU and Nvidia GeForce 2080 GPU both from the City of Santa Clare, CA, USA, to achieve the training of the hybrid networks. The Resnet network was first trained to predict the signs of piston error. The focal plane degradation images shown in Figure 3 were used as the input of the Resnet network, and the signs of the piston errors were used as the output of the Resnet network, with the label '0' representing positive and the label '1' representing negative. Each network was trained with 300 epochs, the batch size was set as 32, and the cross-entropy loss function was used as the index function. The network parameters were updated by back-propagation and the evaluation of the trained network was realized through the verification set. At the same time, in order to improve the network efficiency, a kind of strategy known as batch normalization was used between convolutional layers to prevent gradient disappearance. Four Resnet networks with different depths, including Resnet18, Resnet34, Resnet50, and Resnet101, were trained here to test their prediction accuracy of the piston error signs. Figure 9 shows the loss functions of the training set and the verification set, where the horizontal axis represents the number of trainings and the vertical axis represents the cross-entropy loss function. We can see that after 300 rounds of training, the loss function gradually declined and finally reached a stable state. From the loss function curve of the training set, the Resnet networks fitting degree gradually increased with the deepening of the network, but from the loss function curve of the verification set, with the deepening of the network, the generalization ability of the networks Resnet50 and 101 were much lower than that of Resnet18 and 34, resulting in the loss function oscillation of the verification data set. Then, we use the test data set to verify the piston error sign prediction accuracy of the four Resnet networks with different depths. The test result is given in Figure 10 where the prediction accuracy of the piston error signs is given by the number of correct predictions in the test set divided by its total number. From Figures 9 and 10, we can see that the Resnet34 network had the highest generalization ability and the highest prediction accuracy. Therefore, the optimal model for the prediction of the signs of piston error for the two sub-mirror segmented system is the Resnet34 network. Then, the BP neural network was trained to solve the absolute value of the piston errors. The values of the MTF sidelobes shown in Figure 5 were taken as the input of the network, and the corresponding absolute values of the piston error were taken as the output of the network.