# Improved SPGD Algorithm for Optical Phased Array Phase Calibration
## 3 Calibrating Algorithm  
SPGD is a popular adaptive wave-front control technique proposed by [PERSON] [18,19]. In the SPGD algorithm with \(N\) control channels, the fitness function is defined as  
\[J=J(u_{1},\ u_{2},\ \ldots,\ u_{N}) \tag{1}\]  
where \(u_{i}\) is the voltage of the \(i\)th channel.  
Random perturbations \(\delta uj\), whose average value is 0 and variance is equal, i.e.,  
\[<\delta u_{i}>=0 \tag{2}\]  
\[\delta u_{i}\delta u_{j}=\sigma^{2}\delta_{ij} \tag{3}\]  
Applying them to every channel simultaneously and  
\[J^{+}=J(\mathbf{u}+\delta\mathbf{u}) \tag{4}\]  
\[J^{-}=J(\mathbf{u}-\delta\mathbf{u}) \tag{5}\]  
\[\delta J=\frac{J^{+}-J^{-}}{2} \tag{6}\]  
Applying them to  
\[u_{j}^{(k+1)}=u_{j}+\gamma\delta J^{(k)}\delta u_{j}^{(k)} \tag{7}\]  
where \(k\) is the number of iterations, and \(\gamma\) represents learning rate, which is one of the determining factors of \(u_{j}\). Renew the parameter \(u\) and calculate the next iteration until the stop condition is satisfied.  
However, traditional SPGD easily falls into the local optimum, and the convergence speed is limited [17].  
NAG is a method that can endow gradient descent (GD) momentum [20,21], and improve GD's convergence performance. The basic equation of NAG is described as  
\[m^{k+1}=\mu\cdot m^{k}+\gamma\cdot\
abla_{\theta}\big{(}\theta-\mu\cdot m^{k} \big{)} \tag{8}\]  
\[\theta^{k+1}=\theta^{k}-m^{k+1} \tag{9}\]  
where \(\mu\cdot m^{k}\) is the momentum term, \(\mu\) is the momentum factor, \(\gamma\) denotes the learning rate, \(\theta\) denotes the current status (if in the OPA system, it represents the voltage of the channel),and \(\
abla_{\theta}\big{|}\) is the partial derivative of the fitness function. \(m^{k}\) is used to drive the movement of system status and \(\theta-\mu\cdot m^{k}\) will predict the approximation of the status in the future.  
Therefore, we combine NAG and SPGD to bring prediction into traditional SPGD. The combined equation is described as  
\[m^{k+1}=\mu\cdot m^{k}+\gamma\cdot(\delta J-\mu\cdot m^{k}) \tag{10}\]  
\[u_{j}^{k+1}=u_{j}^{k}-m^{k+1}\cdot\delta u_{j}^{k} \tag{11}\]  
Fitness function in our system is defined as  
\[J=\iint\limits_{\Omega}ld\sigma \tag{12}\]where \(\Omega\) is the region chosen to integrate light intensity and \(I\) represents the light intensity. The flow chart of the NSPGD algorithm is shown in Figure 2; firstly, some parameters such as \(\gamma\), \(k\), \(\mu\), and \(G\) are initialized, then \(\delta u\) will be generated, \(J^{+}\), \(J^{-}\) and \(\frac{J^{+}-J^{-}}{2}\) are evaluated afterward. Momentum \(m\) will be calculated, and these values are applied to Equation (11) and \(J(u^{(k+1)})\) will be compared to \(J(u^{k})\), if \(J(u^{(k+1)})>J(u^{k})\), \(J_{\max}=J(u^{(k+1)})\), otherwise \(J_{\max}=J(u^{k})\). Then, compare \(k+1\) with \(G\) (maximum iterations set in initialization); if \(k+1<G\), \(k=k+1\) and start up the next iteration, otherwise output \(J_{\max}\) and end the algorithm. The optimal solution, i.e., a voltage set, can be found after \(G\) iterations.  
We added the HC algorithm to the comparison to evaluate the performance of SPGD and NSPGD. How HC works is shown in Figure 3.  
Figure 3: Flow chart of HC algorithm.  
Figure 2: Flow chart of NSPDG algorithm.