# Risk Assessment Method of Solar Smart Grid Network Security Based on TimesNet Model
## 3 SSG-NSR Evaluation
### SGTBD Model Based on TimesNet
\[A,\left\{f_{1},\ldots,f_{k}\right\},\left\{p_{1},\ldots,p_{k}\right\}=Period (X_{ID}) \tag{3}\]In Equation (3), \(A\) is the intensity of each frequency component. \(\{f_{1},\ldots,f_{k}\}\) is the \(k\) frequency with the highest intensity. \(\{p_{1},\ldots,p_{k}\}\) is the most significant \(k\) cycle length. The formula for converting 1D time series \(X_{1D}\) to 2D is shown in Equation (4). \[X_{2D}^{i}=Reshape_{p_{i},f_{i}}(Padding(X_{1D})),i\in\{l,\ldots,k\} \tag{4}\]  
The 2D tensor \(\left\{X_{2D}^{l},X_{2D}^{2},X_{2D}^{3},\ldots,X_{2D}^{k}\right\}\) can be obtained through Equation (4). The TimesNet model consists of stacked time blocks, as shown in Figure 1[22]. In Figure 1, each time block in the TimesNet model has residual connections, which are responsible for capturing 2D changes in the time series and adaptively aggregating characterization features from different periods. The input for the time block in layer \(l\) is \(X_{ID}^{l-1}\). Firstly, the time series changes are extracted through 2D convolution, as shown in Equation (5). \[X_{1D}^{l}=TimesBlock\Big{(}X_{1D}^{l-l}\Big{)}+X_{1D}^{l-l} \tag{5}\]  
Secondly, the 2D temporal variation representation is extracted. This study uses the Inception model to extract information from the 2D tensor \(X_{2D}^{l,i}\), as shown in Equation (6). \[\hat{X}_{2D}^{l,i}=Inception\Big{(}X_{2D}^{l,i}\Big{)} \tag{6}\]  
Then, the 2D representation is transformed into 1D representation to achieve a more in-depth and effective modeling of temporal changes, as shown in Equation (7). \[\hat{X}_{1D}^{l,i}=Trunc\Big{(}Reshape_{1,(p_{i}\times f_{i})}\Big{(}\hat{X}_ {2D}^{l,i}\Big{)}\Big{)},i\in\{1,\ldots,k\} \tag{7}\]  
In Equation (7), \(Trunc\Big{(}Reshape_{1,(p_{i}\times f_{i})}\Big{(}\hat{X}_{2D}^{l,i}\Big{)} \Big{)}\) represents the addition of 0 after removing \(Padding(X_{1D})\). Finally, the 1D representation is weighted and summed according to the corresponding frequency to obtain the final feature output, as shown in Equation (8). \[\left\{ \begin{aligned} \hat{A}_{f_{1}}^{l-1},\ldots,\hat{A}_{f_{k}}^ {l-1}&=Soft\text{max}\Big{(}A_{f_{1}}^{l-1},\ldots,A_{f_{k}}^{l-1 }\Big{)}\\ X_{1D}^{l}&=\sum\limits_{i=l}^{k}\hat{A}_{f_{i}}^{l-1} \times\hat{X}_{iD}^{l,i}\end{aligned} \right. \tag{8}\]  
In summary, the framework of the SGTBD model based on TimesNet is displayed in Figure 2.  
Figure 1: Structure diagram of TimesNet model. Normal electricity consumption behavior usually has obvious periodicity: for example, household electricity consumption is low during the day and high at night, factory electricity consumption is high during working hours and low after work, and seasonal changes such as heating in winter and air conditioning in summer. And electricity theft behavior may disrupt this periodicity, such as through intermittent or sustained electricity theft, leading to abnormal fluctuations in the electricity consumption curve. In Figure 2, the SGTBD model based on TimesNet first uses Tsfresh to extract electricity theft behavior features from the input electricity consumption data, mainly used to extract time series features such as highest or lowest electricity consumption, average electricity consumption, and peak electricity consumption. Then, MIC is used for feature screening to identify features highly correlated with electricity theft behavior. Finally, the selected features are input into the TimesNet for classification. TimesNet learns patterns from time series data, identifies abnormal patterns that differ from normal electricity consumption behavior, and outputs the final detection results of electricity theft behavior, providing a basis for the network security assessment of smart grids. In summary, in order to improve the detection accuracy of the TimesNet model, the study proposes using Tsfresh for electricity theft behavior feature extraction and using MIC algorithm for feature selection to improve the TimesNet model.