# Risk Assessment Method of Solar Smart Grid Network Security Based on TimesNet Model
## 3 SSG-NSR Evaluation
### SGTBD Model Based on TimesNet  
The smart grid is a typical Cyber Physical System (CPS); therefore, the NSR evaluation of the smart grid not only involves security issues at the information network level, but also includes security issues of the physical grid. This study first analyzes the security issues of physical power grids. Electricity theft is a common safety issue in the CPS of distribution networks, involving the illegal use of electrical energy in the grid, directly affecting the physical operation of the grid and the legal distribution of electrical energy. Electricity theft detection is an essential component of the NSR assessment of the power grid, which helps identify and prevent illegal activities that may lead to economic losses and threats to the safety of power grid operation [19]. To improve the accuracy of electricity theft detection, feature extraction and selection are first required. The act of electricity theft in the smart grid is a kind of time-series data. Time Series Fresh (Tsfresh) is a Python library used for feature extraction, which can automatically extract features from time series data, covering various aspects of time series data [20]. Therefore, this study uses Tsfresh 0.21.0 to extract features of electricity theft behavior and utilizes the Maximum Information Coefficient (MIC) algorithm for feature selection. MIC is a statistical measure used to measure the relationship between two variables, aimed at capturing various nonlinear relationships [21]. Assuming the electricity consumption data are a matrix \(X^{(n)}=\left\{x_{1},x_{2},x_{3},\ldots,x_{k}\right\}\) with rows \(n\) and columns \(k\), the actual electricity theft result is \(Y=\left\{y_{1},y_{2},y_{3},\ldots,y_{p}\right\}\). The expression of mutual information \(I\left(\left.\left(X,Y\right)\right|_{G_{(x_{i}y_{j})}}\right)\) calculated using an approximate density function is shown in Equation (1). \[I\left(\left.\left(X,Y\right)\right|_{G_{(x_{i}y_{j})}}\right)=\sum_{x\in X} \sum_{y\in Y}p\left(x_{i},y_{j}\right)\log_{2}\frac{p\left(x_{i},y_{j}\right) }{p(x_{i})p(y_{j})} \tag{1}\]  
In Equation (1), \(G_{(x_{i}y_{j})}\) is the grid generated by dividing \(x_{i}\) and \(y_{i}\) into grids. \(p(x_{i})\) is the boundary distribution probability of the electricity consumption data \(x_{i}\) for the \(i\)-th user. \(p(y_{i})\) is the boundary distribution probability of the electricity theft result \(y_{i}\). \(p\left(x_{i},y_{j}\right)\) means the joint possibility of the electricity consumption data of the user \(i\) and the electricity theft result of the \(j\)-th user. The calculation of MIC result \(MIC\left(x_{i},y_{j}\right)\) for \(x_{i}\) and \(y_{i}\) is shown in Equation (2). \[MIC\left(x_{i},y_{j}\right)=\max_{x_{i}y_{j}<B(n)}\left\{\frac{I\left(\left(X,Y \right)_{G_{(x_{i}y_{j})}}\right)}{\log_{2}\min\left(x_{i},y_{j}\right)}\right\} \tag{2}\]  
In Equation (2), \(B(n)\) is a function of the number of samples \(n\). After completing feature selection, this study utilizes the TimesNet model to fully utilize features for detecting electricity theft behavior. The TimesNet model is used for time series analysis, which extracts periodic features through Fast Fourier Transform (FFT) and converts 1D time series into multiple periods arranged side by side 2D sequences. It enables the use of 2D convolution and ResBlock like structures to extract features, which is of great significance for identifying and detecting electricity theft behavior. FFT is an efficient algorithm for computing discrete Fourier transform, aimed at reducing the number of multiplications required for computation, especially when dealing with large amounts of data. Firstly, it is needed to analyze the periodicity of the time series. FFT has been widely used in digital signal processing. Assuming there is a time series \(X_{ID}\) with a time length of \(T\) and a channel dimension of \(C\), its periodicity can be obtained through FFT, as shown in Equation (3).