# Optimizing Physics-Informed Neural Network in Dynamic System Simulation and Learning of Parameters
## 5 Computational Simulations of Dynamical Systems
### SIR Model
```
1: Construct PINN  Specify the input: \(t_{n},n=1,\ldots,X\)  Initialize PINN parameter: \(\omega\)  Output layer: \(S_{NN}(t_{n};\omega)\), \(I_{NN}(t_{n};\omega)\) and \(R_{NN}(t_{n};\omega)\), \(n=1,\ldots,X\)
2: Construct neural network: \(\beta\)  Specify the input: \(t_{n},n=1,\ldots,X\)  Initialize PINN parameter: \(\Phi\)  Output layer: \(\beta(t_{n};\Phi),n=1,\ldots,X\)
3: Construct neural network: \(\gamma\)  Specify the input: \(t_{n},n=1,\ldots,X\)  Initialize PINN parameter: \(\Phi\)  Output layer: \(\gamma(t_{n};\Phi),n=1,\ldots,X\)
4: Specify the training set  Training data: using cubic spline to generate \(I(t_{i})\), \(R(t_{i});i=1,\ldots,X\) given from the dataset. 5: Train the neural network

Specify a loss function \[r_{1}(t) =\frac{dS_{NN}(t)}{dt}-\left(\frac{-\beta(t_{n};\Phi)S_{NN}(t_{n} ;\omega)I_{NN}(t_{n};\omega)}{N}\right)\] \[r_{2}(t) =\frac{dI_{NN}(t_{n};\omega)}{dt}-\left(\frac{\beta(t_{n};\Phi)S_ {NN}(t_{n};\omega)I_{NN}(t_{n};\omega)}{N}-\gamma(t_{n};\Phi)I_{NN}(t_{n}; \omega)\right)\] \[r_{3}(t) =\frac{dR_{NN}(t_{n};\omega)}{dt}-\left(\gamma(t_{n};\Phi)I_{NN}( t_{n};\omega)\right)\] Minimize \(min_{k}\zeta(\omega;\kappa)\) using Adam Optimizer. 6: Return PINN solution \(S_{NN}(t_{n};\omega)\), \(I_{NN}(t_{n};\omega)\) and \(R_{NN}(t_{n};\omega)\), \(n=1,\ldots,X\)
7: Return Parameter \(\beta\): \(\beta(t_{n};\Phi),n=1,\ldots,X\)
8: Return Parameter \(\gamma\): \(\gamma(t_{n};\Phi),n=1,\ldots,X\)
```  
**Algorithm 5** PINN algorithm for learning the parameters of the SIR model We define the residual loss \(\zeta_{r}(\omega;\kappa_{r})\) and training loss \(\zeta_{t}(\omega;\kappa_{t})\) as follows:  
\[\zeta_{r}(\omega;\kappa_{r})=\frac{1}{\kappa_{r}}\sum_{i=1}^{3}\sum_{n=1}^{ \kappa_{r}}||r_{i}(t_{n})||_{2}^{2}. \tag{29}\]  
where  
\[ \begin{split} r_{1}(t)&=\frac{dS_{\text{NN}}(t)}{ dt}-\left(\frac{-\beta(t_{n};\Phi)S_{\text{NN}}(t_{n};\omega)I_{\text{NN}}(t_{n}; \omega)}{N}\right)\\ r_{2}(t)&=\frac{dI_{\text{NN}}(t)}{dt}-\left(\frac{ \beta(t_{n};\Phi)S_{\text{NN}}(t_{n};\omega)I_{\text{NN}}(t_{n};\omega)}{N}- \gamma(t_{n};\Phi)I_{\text{NN}}(t_{n};\omega)\right)\\ r_{3}(t)&=\frac{dR_{\text{NN}}(t)}{dt}-\left(\gamma (t_{n};\Phi)I_{\text{NN}}(t_{n};\omega)\right)\\ \zeta_{t}(\omega;\kappa_{t})=\frac{1}{\kappa_{t}}\bigg{(}\sum_{ n=1}^{\kappa_{t}}||S_{\text{NN}}(t_{n};\omega)-S(t_{n})||_{2}^{2}+\sum_{n=1}^{ \kappa_{t}}||I_{\text{NN}}(t_{n};\omega)-I(t_{n})||_{2}^{2}\\ &\hskip 142.26378 pt+\sum_{n=1}^{\kappa_{t}}||R_{\text{NN}}(t_{n}; \omega)-R(t_{n})||_{2}^{2}\bigg{)}.\end{split}  \tag{30}\]  
Here, we use data from Italy [35] starting from the date of the first reported cases to the day before vaccination data were reported, which is from 31 st of January to 11 December 2020. We take the total population \(N\) to be \(59.44\times 10^{6}\) in Italy. Cubic spline interpolation generates 2000 training points from the cumulative infection and recovered data. The cumulative infections and recovered data are matched against the cumulative and recovered learned solutions. Algorithm 5 was implemented using publicly available COVID-19 data [35]. The parameters of the data using the SIR model and the learned cumulative infection and recovered data were obtained after using PINN and the approach of Scenario 2 with five hidden layers, 64 neurons per layer, 100,000 epochs, the tanh activation function was used, and a learning rate of \(10^{-3}\). Figure 20 shows the learned solution of the SIR model, comparing the actual and predicted outputs of the infected and recovered populations. The cumulative data aligns closely with an exponential function. Figure 21 displays the learned values of \(\beta(t)\) and \(\gamma(t)\) using PINN. The phase space plot in Figure 22 illustrates the relationship between the actual and predicted infected and recovered populations. Figure 20: _Cont._  
Figure 23 depicts the absolute error between the target and predicted values of the SIR model using PINN. Table 17 summarizes the error metrics for the SIR model, indicating the accuracy of the PINN solution.