## 3 Methods
### Overview
### Variable Block

We reexamine the self-attention mechanism from a new perspective and introduce Variable Attention, as shown in Figure 2b. In past time-series analyses, self-attention mechanisms mainly focused on the dynamic changes and long-term dependencies exhibited by time series over time, meaning they primarily allocated attention weights along the time dimension. However, our proposed Variable Attention mechanism aims to consider not only the temporal correlations through Time Blocks in multivariate time-series data but also emphasizes the importance and interactions among different variables. This implies that, at any given time point, the model will not only focus on which past time points have the greatest impact on the current time point but also on which variables among all observed variables are crucial for understanding the entire data pattern. This approach enhances the model's ability to filter key information in complex data structures, particularly in cases where significant interactions exist among variables. Assuming we have \(S\) Variable Blocks, where the input of the \(s-\)th Variable Block is \(X_{s-1}^{en}=Variable-Block(X_{s-2}^{en})\), the expression for the Variable Block is given in Equation (12):

\[ \begin{split} x_{v}^{s-1}=Permute(x^{s-1})\\ z_{v}^{s}=Layer-Norm(MHSA(x_{v}^{s-1})+x_{v}^{s-1})\\ x_{v}^{s}=Layer-Norm(Feedward(z_{v}^{s})+z_{v}^{s})\\ x^{s}=Permute(x_{v}^{s})\end{split}  \tag{12}\]

where \(x^{s-1}\in R^{L\times d_{model}}\); the Permute function exchanges the first and second dimensions, resulting in \(x_{v}^{s-1}\in R^{d_{model}\times L}\). \(z_{v}^{s},x_{v}^{s}\in R^{d_{model}\times L}\). After obtaining \(x_{v}^{s}\), applying the Permute function exchanges the first and second dimensions again, resulting in \(x^{s}\in R^{L\times d_{model}}\). ## 4 Experiment

### Data Sources and Simulation Setup

To validate the effectiveness of our proposed algorithm for detecting communication anomalies in distributed photovoltaic power generation systems, we constructed a simulation model using the Simulink environment of MATLAB R2021b. This model, referred to as Case 1, is illustrated in Figure 1. This microgrid model was connected to a 380 V grid to ensure constant power output and integrated a 200 Ah energy storage battery with accompanying converters. The 380V DC bus was responsible for mediating the flow of electrical energy between the photovoltaic array and the grid-connected inverter. The simulated experiment was set to run under conditions of solar irradiance ranging from 800 to 1500 W/m\({}^{2}\) and an ambient temperature of 25 \({}^{\circ}\)C. The monitored parameters were summarized as a vector \(x\), as shown in Equation (13):

\[x=\{V_{PV},I_{PV},P_{PV},V_{DC},I_{DC},P_{T},V_{B},I_{B},S_{B}\} \tag{13}\]

where \(V_{PV},I_{PV},\) and \(P_{T}\) are the measured values of voltage, current, and power output of the photovoltaic array, respectively; \(V_{DC}\) and \(I_{DC}\) are the measured values of voltage and current of the DC bus; \(P_{T}\) is the measured power transmission from the microgrid to the 380V grid; \(V_{B},I_{B},\) and \(S_{B}\) are the measured values of voltage, current, and state of charge of the battery, respectively. For the detection task, we developed a 2-second sliding time window, generating a time series every 2 s. The dataset includes 3000 s of simulated results (totaling 15,000 scenarios), covering common features of the operational process, with a sampling frequency of 5 samples per second. To validate the effectiveness of the detection method under different conditions, we applied signal interference with an amplitude of 10-40% of the sensor's maximum measurement value to \(V_{PV},I_{PV},\) and \(P_{T}\) every 2 s across a total of 1500 scenarios, while conducting a denial-of-service (DoS) attack every 4 s. The dataset was divided into 70% for training, 10% for validation, and 20% for testing the network's performance.