# Deep Lifelong Learning Optimization Algorithm in Dense Region Fusion
## 3 Materials and Methods
### Algorithm Principle in DLLO-DRF
#### 3.2.2 Dense Region Fusion  
In order to observe the distribution of parameters under lifelong learning, we conducted 10 stages of training on the Cascade R-CNN object detection algorithm using the model fine-tuning lifelong learning training paradigm. Figure 2 shows some parameters in the model changing with the task stage, and it can be observed that these parameters are often concentrated in one of the regions. The region with the highest concentration of parameters is referred to as the dense region. For neural networks, these aggregated parameters are more valuable to the model itself, as they often carry the most important knowledge within the model. Based on the above findings, dense region fusion divides the parameters of models from multiple task stages of lifelong learning into regions at the same location, and takes the average of all parameters in the region with the densest parameter distribution as the parameters of the fusion model. Therefore, the model fused in this way can maximize the information of all stages of lifelong learning tasks. The main steps and related formulas of dense region fusion are introduced in the following paragraphs. Through the training method defined in Section 3.2.1, we can obtain the model for each stages: \(Model=model^{(1)},model^{(2)},\ldots,model^{(n)}\). For deep neural network models, the parameter dimensions correspond to the size of the convolutional kernel. Typically, the convolutional kernel size varies across different layers. To enable the fusion process, it is crucial to map the parameter vectors in the network onto a one-dimensional space, as the convolutional kernel size varies across layers. The dimension mapping algorithm is illustrated in Algorithm 1. Through dimension mapping, the parameter at position \(i\) of the \(k^{th}\) stage model is represented as \(x_{i}^{(k)}\). Consequently, the parameter set encompassing all stage models at position \(i\) is \(X_{i}=x_{i}^{(1)},x_{i}^{(2)},\ldots,x_{i}^{(n)}\). In order to identify the most densely distributed region in \(X_{i}\), it is essential to partition \(X_{i}\) into distinct regions, with each region's size determined by the parameter range of \(X_{i}\), computed using Equation (2). \[size=\frac{x_{max}-x_{min}}{j}, \tag{2}\]  
where \(j\) is the number of regions that are divided, and \(x_{max}\) and \(x_{min}\) are the maximum and minimum values in \(X_{i}\), respectively. ```
Input:\(Model=\{model^{(1)},model^{(2)},\ldots,model^{(n)}\}\): The set of the trained model. Output: Model set with weight parameters reduced to one dimension. Shape: Original model parameter dimension. 1 Obtain the parameter dimension shape in Model;
2 For each model, \(model^{(i)}\), traverse all parameters based on their dimensions and merge them into a one-dimensional array;
3 For each model, \(model^{(i)}\), replace all the parameters to an array obtained in the last step. ```  
**Algorithm 1**Dimension Mapping  
Figure 2: Fine-tune the distribution of model parameters under lifelong learning. The blue points represent the parameters in the dense region, while the red points refer to those outside the dense region. The region division implementation is depicted in Algorithm 2. Through region division, the \(j\) subset of \(X_{i}\) parameter space for all models at position \(i\) can be acquired, denoted as \(X_{i1},X_{i2},\ldots,X_{ij}\). The objective of dense region fusion is to identify the subset with the highest number of parameters within the \(j^{th}\) subsets, namely, the dense region \(X_{dense}\). To circumvent the uncertainty in dense region selection when parameter quantities are relatively evenly distributed across different regions, which could compromise the fusion model's robustness, the dense region \(X_{dense}\) is determined based on \(X_{i1},X_{i2},\ldots,X_{ij}\). The parameter quantity's variance \(s^{2}\) is calculated for each subset, and when \(s^{2}\) falls below a predefined threshold, the original parameter set \(X_{i}\) is directly treated as the dense region.