# A Comparison of Deep Learning Algorithms for Anomaly Detection in Discrete Mechanical Systems
## 4 Network Architecture and Training
### Physics-Informed Neural Network  
The training of deep neural networks requires the availability of large datasets, which may not always be simple to acquire for pre-existing structures and are difficult to retrieve in damage scenarios. Physics-informed neural networks are able to overcome this limitation. Indeed, such networks can be trained with additional information from the physical laws governing the dynamic behavior of the system taken into account, seamlessly integrating data and mathematical models, which may not be even totally understood and may be uncertain and highly dimensional [39; 40]. For this reason, the built-in loss function is not useful for training the PINN and a custom loss function is needed. In particular, this loss function should take into account the physical laws governing the dynamic response of the system, restricting the space of admissible solutions in the training of the autoencoder. The scheme of the proposed custom loss is reported in Figure 8.  
The signals outputs \(y_{i}\) of the autoencoder are the reconstructed time histories of the scaled vibration signals acquired for the healthy scenario, which in turn represent the response of the system to the input force applied by the hammer. However, after a certain amount of time, set equal to 10 s in this case, it is possible to assume that the transient behavior due to the forced motion of the system completely dies out. Thus, after inverse scaling through the vector G, containing the values of the scaler used during the pre-processing phase, the remaining part of each reconstructed time history should satisfy, with low error, the already presented set of ODEs (1). In particular, in order to be coherent with the measurements units, the ODEs are divided by the mass of the correspondent floor; in this way, the error functions are expressed in acceleration units. This is performed in order to ensure that the physical loss has the same measurements units as that calculated by the data-driven model. Moreover, it is likely that a greater error will result when considering the time histories of the damaged scenario. For this reason, after proper integration in the time domain [41; 42], the following error functions were evaluated for each time instant:  
\[ \begin{split} err_{1}&=\frac{m_{11}\cdot\ddot{y}_{1 }+c_{11}\cdot\dot{y}_{1}+c_{12}\cdot\dot{y}_{2}+k_{11}\cdot y_{1}+k_{12}\cdot y _{2}}{m_{11}}\\ err_{2}&=\frac{m_{22}\cdot\ddot{y}_{2}+c_{21} \cdot\dot{y}_{1}+c_{22}\cdot\dot{y}_{2}+c_{23}\cdot\dot{y}_{3}+k_{12}\cdot y _{1}+k_{22}\cdot y_{2}+k_{23}\cdot y_{3}}{m_{22}}\\ err_{3}&=\frac{m_{33}\cdot\dot{y}_{3}+c_{32} \cdot\dot{y}_{2}+c_{33}\cdot\dot{y}_{3}+c_{34}\cdot\dot{y}_{4}+k_{32}\cdot y _{2}+k_{33}\cdot y_{3}+k_{34}\cdot y_{4}}{m_{33}}\\ err_{4}&=\frac{m_{44}\cdot\ddot{y}_{4}+c_{43} \cdot\dot{y}_{3}+c_{44}\cdot\dot{y}_{3}+k_{43}\cdot y_{3}+k_{44}\cdot y_{4}}{ m_{44}}\\ \end{split}  \tag{13}\]  
Figure 8: Custom loss scheme. where, as already said, \(y_{i}\), \(\dot{y}_{i}\), and \(\dot{y}_{i}\) are the displacement, the velocity, and the acceleration signals coming from the reconstruction of the autoencoder, respectively. Then, the absolute of their mean values is used to constitute the physical portion of the custom function loss:  
\[\mathcal{L}^{physic}=\frac{\sum_{i=1}^{N}|err_{1,i}|}{N}+\frac{\sum_{i=1}^{N}| err_{2,i}|}{N}+\frac{\sum_{i=1}^{N}|err_{3,i}|}{N}+\frac{\sum_{i=1}^{N}|err_{4,i}|}{N} \tag{14}\]  
where \(N\) is the number of time steps for which the error functions are evaluated. In order to demonstrate the validity of the information coming from the physical portion of the loss, the error functions, reported in Equation (13), are evaluated for both a \"healthy\" and a \"damaged\" time history, in which the defect, identified by a reduction in stiffness of 20% of the nominal value, is located in the third floor. The results, shown in Figure 9, confirm the equation of motion of the system as a valuable option for the physics portion of the custom loss.