# Model Predictive Evolutionary Temperature Control via Neural-Network-Based Digital Twins
## 2 Materials and Methods
### Control Policy Generation Using Genetic Programming  
The subsequent component of the pipeline involves the utilization of genetic programming (GP) to generate control policies for the fans. GP is a variant of Genetic Algorithms (GA) developed by [PERSON], where the solution is encoded in a tree structure instead of a string [40; 41; 42]. Similar to GA, GP draws inspiration from nature and mimics the evolutionary process by iteratively applying a set of genetic operations on an initially randomly selected pool of candidate solutions [43; 44; 41]. However, unlike GA, which aims to solve specific optimization tasks, genetic programming focuses on creating a model with a predefined objective [45].  
In this study, the controller population is designed with two primary objectives. Firstly, it aims to adjust the fans to achieve a homogeneous temperature field. Secondly, it strives to prevent the occurrence of local hot spots. Evaluating these phenomena can be challenging, and relying solely on a single metric may be insufficient. To address this issue, we propose a combination of three metrics to assess the performance of the controller. The first metric targets the homogeneity of the temperature field by minimizing the standard deviation of the pixel values. A lower standard deviation indicates a more uniform temperature distribution. However, relying solely on this metric is inadequate for effectively penalizing hot spot formation. Hence, we introduce a second loss, referred to as the hot spot loss, which calculates the sum of all positive pixel values after subtracting the mean temperature from each pixel. This loss function encourages strong cooling and discourages the formation of regions with temperatures significantly higher than the system's average temperature. Additionally, we incorporate an auxiliary loss function to penalize excessive fan usage:  
\[\begin{split} Loss_{STD}=\sqrt{\frac{\sum_{i=1}^{n}{(x_{i}-\mu)^ {2}}}{n}}\\ Loss_{hotspot}=\sum_{i=1}^{m}{x_{i}-\mu}\\ Loss_{fanload}=\frac{1}{300}\sum_{i=1}^{3}{f_{i}}\end{split} \tag{2}\]  
where \(\mu\) represents the mean value, \(n\) corresponds to the total number of pixels, and \(m\) corresponds to the number of pixels with values larger than \(\mu\). To ensure an appropriate evaluation, we scale these three losses to the same order of magnitude and assign weights to emphasize their relative importance. The  
can be spanned by deeper trees, enabling the generation of solutions based on the complete temperature field, rather than randomly selected local regions of interest.  
Control laws in the form of a 3D vector are generated by each candidate in the population (Figure 11). To align with the expected input dimensions of the second part of the predictor, the vector is duplicated 100 times. Next, the proposed fan settings vector is appended, and predictions are generated using the decoder component of the digital twin model. These predictions are then evaluated against a predefined fitness function, and the corresponding fitness scores are assigned to the respective individuals (Figure 11).  
The GP controller undergoes evolutionary training for 5 generations on each training experiment, amounting to a total of 1410 generations. Limiting the training to only 5 generations per sequence prevents overfitting to a specific problem, allowing for the transmission of genes that exhibit generalization capabilities across various heating loads. This can be considered similar to the early stopping policies in NN training. For additional information on the GP controller's configuration and the reasoning behind the chosen approaches, refer to Appendix B. Appendix C further presents the details of the MPC experiment design for a population of control laws.