# Carbon Quota Allocation Prediction for Power Grids Using PSO-Optimized Neural Networks
## 3 Materials and Methods
### Model Building and Optimization
#### 3.2.2 BPNN Module  
In the mid-1980s, [PERSON] [52] proposed the well-known error back propagation (BP) as a now commonly used machine learning method suitable for constructing multi-layer orthogonal networks and training them with a back propagation algorithm to minimize the difference between the output and the real value. The algorithm is effectively used as an excellent fitting function for practical problem solving such as regression analysis and classification tasks [53]. 1. Neural network algorithm flow The specific process of neural network establishment is as follows: Step 1: Determine the input dimension based on the input sample, and set up the input layer. The activation function is configured as the Sigmoid function, expressed as follows: \[g(x)=1/\left(1+e^{-x}\right)\] (16) Step 2: Output of the hidden and output layersThe BPDNN typically consists of three layers: the input layer (representing the output set of the GM(1,1) model), the hidden layer, and the output layer (representing the carbon emissions from the power sector), as shown in Figure 4. Let the number of nodes in the input, hidden, and output layers be denoted as \(m\), \(n\), and \(s\), respectively. The hidden layer output formula is shown in (17):  
\[H_{k}=f\bigg{(}\sum_{i=1}^{m}x_{i}\cdot w_{ik}-a_{k}\bigg{)} \tag{17}\]  
where \(i=1,2,\ldots,m;k=\mathrm{i}=1,2,\ldots,n;w_{ik}\) is the link weight coefficient from the input layer to the hidden layer and \(a_{k}\) is the bias. The mathematical expression for the output layer is shown in (18):  
\[O_{j}=\sum_{i=1}^{m}\left(H_{k}\cdot w_{kj}\right)-b_{j} \tag{18}\]  
where \(j=1,2,\ldots,s;w_{kj}\) is the connection weight coefficient from the hidden layer to the output layer and \(b_{j}\) is its bias. Step 3: Calculate the error. The error is the difference between the output of the input layer and the desired output, as expressed in Formula (19):  
\[e_{j}=O_{j}^{\prime}-O_{j} \tag{19}\]  
where \(j=1,2,\ldots,s;O_{j}^{\prime}\) denotes the desired output value and \(-O_{j}\) is the true value. Step 4: Weight updating. The formula for updating connection weights from the input layer to the hidden layer is provided in Equation (20):  
\[w_{ik}=w_{ik}+\theta H_{k}(1-H_{k})\cdot x_{i}\sum_{i=1}^{m}\left(e_{j}\cdot w _{kj}\right) \tag{20}\]  
The formula for updating the threshold from the hidden layer to the output layer is given in Equation (21):  
\[w_{kj}=w_{kj}+\theta H_{k}\cdot e_{j} \tag{21}\]  
where \(i=1,2,\ldots,m;k=\mathrm{i}=1,2,\ldots,n;j=1,2,\ldots,s\). Step 5: Update threshold  
The formula for updating the threshold from the input layer to the hidden layer is shown in (22):  
\[a_{k}=a_{k}+\theta H_{k}(1-H_{k})\sum_{i=1}^{m}\left(e_{j}\cdot w_{kj}\right) \tag{22}\]  
Figure 4: BP neural network algorithm. The threshold update formula for the implicit layer to the output layer is shown in (23):  
\[b_{j}=b_{j}+e_{j} \tag{23}\]  
where \(i=1,2,\ldots,m;k=\mathrm{i}=1,2,\ldots,n;j=1,2,\ldots,s\). Step 6: Judge the termination condition  
If the error \(e_{j}\) falls within a reasonable range, the calculation will terminate; otherwise, the hidden and output layers will be recalculated, returning to step 2. 2. PSO optimization algorithm  
PSO is a heuristic search method that mimics the foraging behavior of birds [54; 55]. To address the issue of local optima that the BP neural network tends to encounter during the learning process, this paper incorporates the PSO algorithm to perform a global search for the optimal initial weights and thresholds of the BP neural network. This approach helps the BP neural network escape from local extrema. The PSO algorithm regards the solution of optimal problems as searching for optimal particles in a D-dimensional space.