## 3 Proposed Control Methods  
### Data Preparation and Processing  
The first step is to clarify the available data and required preparation and processing. One is power commands in the controller, and the other is load changes in the system. Since the DG output varies with load changes, the main task is to establish the power commands settings based on load consumption, especially from common loads. The data-matching process needs to build relationship between power commands and load consumption. Load consumption therefore serves as input data, while power commands become output data. Thus, the system's load consumption changes can be converted into corresponding power commands within the controller. So where does this data come from? Thanks to the smart meters, phasor measurement units, and supervisory control and data acquisition systems equipped during the intelligent construction of microgrids, the power consumption of loads and output power of DGs can be measured and recorded in real time. This is sufficient to support the source of the aforementioned power data. Among these, the common load power variations, which serve as input data, are provided by the above systems and can be obtained even when the microgrid is operating only at the primary level. The key questions are how much controller input power each DG actually needs, and how to obtain this through the already-known common load power variations. Based on these secondary-level control principles, the PI controller can compensate for the offset introduced by droop control at the primary level, providing insights into setting the controller input powers. Under this secondary level scenario, when the system operates stably, input and output data are collected for artificial intelligence neural network algorithm training. The collection results are shown in the Figure 2. The first black curve represents the common load power as training input, while the second to fourth (red, blue, and green) curves represent the required controller input powers for DG1 to DG3, respectively, as training outputs. To maintain data collection correspondence and ensure sufficient training data volume, a sample-and-hold circuit is employed. Its function is to capture the input signal value at each sampling moment and maintain this value unchanged until the next sampling  
Figure 2: Curves of input-output data that need to be fitted. moment, with relatively short intervals between sampling moments. This is implemented through the following formula:  
\[y(t)=u(kT)\text{ for }kT\leq t\leq(k+1)T \tag{8}\]  
where \(T\) is the sampling period, which is set to \(1\times 10^{-4}\) s in this study, \(u(kT)\) is the value of the input signal at sampling instant \(kT\), and \(y(t)\) is the output signal. Based on the above discussion, it can be deduced that the power reference value \(P^{*}\) can be calculated using the following formula, noting that the system maintains a stable operating state, ignoring transient fluctuations and oscillations:  
\[P^{*}=\frac{1}{m}\delta\omega=\frac{1}{m}\bigg{(}K_{p\omega}\left(\omega^{*}- \omega\right)+K_{i\omega}\int\left(\omega^{*}-\omega\right)dt\bigg{)} \tag{9}\]  
Through the above formula, when there are changes in common load power, by correcting the real-time system frequency through the secondary level, the \(P^{*}\) value for each DG can be obtained, thereby achieving frequency restoration to the rated value at the primary level without using the secondary level. Here, the data provided for subsequent neural network training can only be obtained initially through the secondary level control compensator. However, through one-shot or few-shot learning, the system can still be prepared for generalization and control at the primary level. The main reason is that microgrids operate within a specified frequency range bounded by upper and lower limits. The maximum frequency fluctuations are typically restricted to \(\pm\)0.8 Hz or \(\pm\)0.5 Hz, though these specific limits vary by country and region.