This study proposes integrating Machine Learning (ML) into the optimization process of PID controllers using Genetic Algorithm (GA) and Particle Swarm Optimization (PSO). The aim is to enhance the performance, speed up optimization, and improve the control system's robustness. By combining ML with GA and PSO, the method introduces adaptability, allowing the system to learn from past optimizations and generalize the PID tuning process for a wide range of operating conditions.
GA optimizes PID gains by evolving candidate solutions over generations, but its computational expense arises from evaluating each candidate via simulations of the continuous stirred tank reactor (CSTR) model. To address this, surrogate models (which are also known as meta-models or response surfaces) are introduced to approximate the performance of each PID controller candidate. These models are trained using ML, utilizing neural networks, on previously evaluated PID candidates. Once trained, GA can predict fitness values for new candidates using the surrogate model, reducing the need for full simulations.
In cases where the CSTR undergoes changes or new operating conditions arise, the standard GA would require re-optimization from scratch. However, ML enables the GA to utilize knowledge gained from previous optimizations, learning patterns in PID gains across different operating conditions such as temperature and reactant concentration. This reduces the search space and accelerates convergence. Furthermore, ML can dynamically adjust GA's mutation and crossover rates based on population diversity or previous generations' outcomes, making the process more efficient. The ML model \(\:\widehat{f}\left(P\right)\) is trained to approximate the true fitness function \(\:f\left(P\right)\), where:
$$\:\widehat{f}\left({P}^{\left(i\right)}\right)\approx\:f\left({P}^{\left(i\right)}\right)={\int\:}_{0}^{T}{e\left(t\right)}^{3}dt\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:21$$
where \(\:{P}^{\left(i\right)}=({K}_{p}^{\left(i\right)},{K}_{i}^{\left(i\right)},{K}_{d}^{\left(i\right)})\).
In this case, the optimization is performed as
$$\:{P}_{new}^{\left(i\right)}=GA\left({P}_{old}^{\left(i\right)},\widehat{f}\left({P}^{\left(i\right)}\right)\right)\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:22$$
The GA uses the ML-predicted fitness \(\:\widehat{f}\) instead of performing full simulations to guide optimization. ML also enhance the PSO performance by improving the swarm’s ability to explore and exploit the search space more intelligently. Similar to GA, PSO benefits from surrogate models that predict candidate PID gains’ performance without running full simulations. Additionally, ML can prevent premature convergence and accelerate optimization by dynamically adjusting the swarm’s behavior.
In classical PSO, particle velocities are updated using fixed cognitive and social parameters. However, in different regions of the search space, varying exploration strategies may be needed. A neural network can be used to dynamically adjust these parameters based on the current particle and swarm states. The velocity update rule:
$$\:{v}_{i}\left(t+1\right)=w{v}_{i}\left(t\right)+{c}_{1}{r}_{1}\left({P}_{best}-{K}_{i}\left(t\right)\right)+{c}_{2}{r}_{2}\left({g}_{best}-{K}_{i}\left(t\right)\right)\:\:\:\:\:\:\:\:\:\:\:23$$
Equation (23) is modified as
$$\:{v}_{i}\left(t+1\right)=w{v}_{i}\left(t\right)+{c}_{1}\left(t\right){r}_{1}\left({P}_{best}-{K}_{i}\left(t\right)\right)+{c}_{2}\left(t\right){r}_{2}\left({g}_{best}-{K}_{i}\left(t\right)\right)\:\:\:\:\:\:\:\:\:\:24$$
where \(\:{c}_{1}\left(t\right)\) and \(\:{c}_{2}\left(t\right)\) are learned by a neural network that adapts to the swarm’s dynamics.
The ML model for particle movement uses the particle's current position \(\:{X}_{i}\left(t\right)=({K}_{p},{K}_{i},{K}_{d})\) to adjust the velocity \(\:{v}_{i}(t+1)\) and optimize the negative of the fitness function:
$$\:r\left(t\right)=-f\left({X}_{i}\left(t\right)\right)=-{\int\:}_{0}^{T}{e\left(t\right)}^{2}dt\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:25$$
The ML is further employed to learn gain-scheduling rules. Neural networks can be trained to map operating conditions (e.g., temperature \(\:T\), concentration \(\:{C}_{A}\) to optimal PID gains \(\:({K}_{p},{K}_{i},{K}_{d})\).. Data is collected by running GA or PSO under varying conditions and recording the optimal gains. The trained ML model can then predict the best gains for new operating conditions:
$$\:\left[{K}_{p},{K}_{i},{K}_{d}\right]=ML\:Model\left(T,{C}_{A}\right)\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:26\:\:$$
The ML model may be a neural network, decision tree, or other regression method that maps operating conditions to optimal PID gains. By incorporating ML into GA and PSO, the system becomes more adaptable and efficient in handling complex, nonlinear dynamics, such as those in a CSTR system. This significantly improves the overall performance and reduces computational overhead in PID tuning.
In this approach, neural-based machine learning (ML) is used to optimize PID controller parameters (\(\:{K}_{p},{K}_{i},{K}_{d})\) that can handle the worst-case conditions of a Continuous Stirred Tank Reactor (CSTR) system. The worst-case scenario involves system parameters such as reaction rates, inflow concentrations, and heat removal rates that make the CSTR difficult to control. These parameters include the reaction rate constant \(\:{k}_{0}\), activation energy \(\:{E}_{a}\), heat transfer coefficient \(\:U\), and inflow concentration \(\:{C}_{A}^{0}\). The optimization problem is structured as
$$\:\underset{{K}_{p},{K}_{i},{K}_{d}}{\text{min}}\underset{{\theta\:}_{{CSTR}}}{\text{max}}J({K}_{p},{K}_{i},{K}_{d},\:{\theta\:}_{CSTR})\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:27$$
where \(\:J({K}_{p},{K}_{i},{K}_{d},\:{\theta\:}_{CSTR})\) is the cost function based on an error metric, such as the Integral of Square Error (ISE). The goal is to find the PID parameters that minimize error while accounting for the most challenging CSTR parameters \(\:{\theta\:}_{CSTR}\), including \(\:{k}_{0},{E}_{a},U\), which could make the system difficult to control.
In this study, neural networks are employed to enhance both the optimization of PID gains and the identification of worst-case CSTR parameters. The process involves two neural models, the first Neural Model for Worst-Case CSTR Parameter Prediction: This neural network is trained to predict the worst-case CSTR system parameters \(\:{\theta\:}_{CSTR}\)that maximize the error for a given set of PID gains. The goal is to use the model to efficiently approximate which combination of CSTR parameters leads to the most difficult-to-control dynamics.
The second Neural Model for PID Optimization: Another neural network is used to optimize the PID parameters (\(\:{K}_{p},{K}_{i},{K}_{d}\)). This network learns the relationship between PID gains and system performance by analyzing data from previous optimizations. The aim is to generalize this knowledge, allowing the network to suggest optimal PID settings for minimizing the error, even under adversarial CSTR conditions. The optimization problem is then tackled as
$$\:\underset{({K}_{p},{K}_{i},{K}_{d})}{\text{min}}\underset{{\theta\:}_{{CSTR}}}{\text{max}}\widehat{J}({K}_{p},{K}_{i},{K}_{d},{\theta\:}_{CSTR})\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:28$$
where \(\:\widehat{J}({K}_{p},{K}_{i},{K}_{d},{\theta\:}_{CSTR})\) is the neural network approximation of the true cost function \(\:J({K}_{p},{K}_{i},{K}_{d},{\theta\:}_{CSTR})\). This neural-based surrogate model reduces the need for computationally expensive simulations by predicting system behavior and performance for both PID and CSTR parameter combinations.
The optimization process in the GA-based approach, each individual in the population is represented as a vector that includes both the PID gains and CSTR parameters:
$$\:{P}^{\left(i\right)}=\left({K}_{p}^{\left(i\right)},{K}_{i}^{\left(i\right)},{K}_{d}^{\left(i\right)},{\theta\:}_{CSTR}^{\left(i\right)}\right)\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:29$$
A neural network surrogate model is trained to predict the fitness value for each individual, estimating the combined effect of the PID gains and worst-case CSTR parameters. The network accelerates the GA by providing fast fitness evaluations:
$$\:f\left({P}^{\left(i\right)}\right)=\widehat{J}\left({K}_{p}^{\left(i\right)},{K}_{i}^{\left(i\right)},{K}_{d}^{\left(i\right)},{\theta\:}_{CSTR}^{\left(i\right)}\right)\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:30$$
This reduces the need to run full simulations for each candidate solution, enabling the GA to evolve PID gains and CSTR parameters more efficiently. The crossover, mutation, and selection processes focus on minimizing the error for the worst-case CSTR parameters predicted by the neural network.
In the PSO, each particle represents both the PID gains and the CSTR parameters:
$$\:{X}^{\left(i\right)}=\left({K}_{p}^{\left(i\right)},{K}_{i}^{\left(i\right)},{K}_{d}^{\left(i\right)},{\theta\:}_{CSTR}^{\left(i\right)}\right)\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:31$$
The particle swarm is guided by neural-based predictions of both the worst-case CSTR parameters and the corresponding optimal PID gains. The fitness function for PSO is evaluated using the neural model:
$$\:f\left({X}^{\left(i\right)}\right)=\widehat{J}\left({K}_{p},{K}_{i},{K}_{d},{\theta\:}_{CSTR}\right)\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:32$$
The velocity and position updates adjust the particles based on the neural network’s predictions, helping the swarm converge faster to both the best PID parameters and the most challenging CSTR conditions.
The neural networks are trained using data from multiple optimization runs where GA or PSO is used to tune the PID parameters under various CSTR conditions. The data consists of input-output pairs: operating conditions \(\:(T,{C}_{A}^{0},{k}_{0},{E}_{a})\) and corresponding optimal PID gains \(\:({K}_{p},{K}_{i},{K}_{d})\).
The neural network learns the mapping:
$$\:\left[{K}_{p},{K}_{i},{K}_{d}\right]=ML\:Model\:\left(T,{C}_{A}^{0},{k}_{0},{E}_{a}\right)\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:33$$
This allows the model to predict the optimal PID gains based on given CSTR parameters and vice versa.
Once trained, the model generalizes the relationship between operating conditions and optimal PID gains, enabling the optimizer to efficiently explore the parameter space. It also suggests worst-case scenarios that push the PID controller to its limits.
Adversarial ML techniques are applied to actively generate worst-case CSTR scenarios that stress-test the PID controller. The neural network model is trained to identify which CSTR parameters \(\:{\theta\:}_{CSTR}\) lead to the worst performance for a given PID controller. These adversarial scenarios are then introduced during the optimization process, helping to discover more robust PID settings.
By leveraging neural-based ML, the optimization process becomes more efficient and adaptable. The system learns from past optimization runs and applies this knowledge to reduce the computational effort required for evaluating new scenarios. This makes the approach ideal for handling the complex, nonlinear dynamics typical of CSTR systems.
In the adversarial optimization case, the goal is to find the best PID controller parameters (\(\:{K}_{p},{K}_{i},{K}_{d})\) that perform well under the worst-case CSTR system parameters, such as the worst combination of reaction rates, inflow concentrations, or heat removal rates. The system parameters to be tuned include variables such as the reaction rate constant \(\:{k}_{0}\), activation energy \(\:{E}_{a}\), heat transfer coefficient \(\:U\), and other parameters that affect the CSTR’s dynamics. To achieve this goal, the optimization problem is formed as using Eq. 27. The inner maximization problem finds the worst-case CSTR parameters \(\:{\theta\:}_{CERT}\), which make the system behave in a way that is hardest to control. The outer minimization problem seeks the optimal PID gains (\(\:{K}_{p},{K}_{i},{K}_{d}\)) that minimize the error in controlling the worst-case CSTR plant.
In this study both GA and PSO are used simultaneously optimize both the PID gains and the CSTR system parameters. One optimization loop focuses on finding the worst-case CSTR parameters, while the other loop finds the best PID controller parameters.
In the GA case the Population Representation is achieved by representing each individual in the population is represented as a vector consisting of both PID gains and CSTR parameters as illustrated in Eq. (27). The PID parameters \(\:{(K}_{p},{K}_{i},{K}_{d})\) are optimized in the outer loop to minimize the error, while the CSTR parameters \(\:{\theta\:}_{CSTR}\) are optimized in the inner loop to maximize the error. The fitness function evaluates both how well the PID controller performs and how adversarial the CSTR system behaves:
$$\:f\left({P}^{\left(i\right)}\right)=\underset{{K}_{p}^{\left(i\right)},{K}_{i}^{\left(i\right)},{K}_{d}^{\left(i\right)}}{\text{min}}\underset{{\theta\:}_{{CSTR}}^{\left(i\right)}}{\text{max}}{\int\:}_{0}^{T}{e\left(t\right)}^{2}dt\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:34$$
where \(\:e\left(t\right)={T}_{setpoint}-T\left(t\right)\) is the error between the desired and actual reactor temperature.
The evolutionary process for both PID gains and CSTR parameters undergo crossover, mutation, and selection to evolve toward the optimal solution. The PID gains evolve to minimize the error, while the CSTR parameters evolve to make the system as difficult as possible to control.
The PSO particle representation of each particle represents both the PID controller gains and the CSTR system parameters are illustrated in Eq. (31). The velocity and position updates aim to find the worst-case CSTR parameters \(\:{\theta\:}_{CSTR}\) that maximize the error and the best PID parameters (\(\:{K}_{p},{K}_{i},{K}_{d}\)) that minimize the error.
The position of each particle is updated based on both individual best (PID and CSTR) and global best (worst-case CSTR and best PID) solutions. The fitness function for this arrangement is given by Eq. (32). The dual optimization problem involves, minimizing the outer loop of the cost function to achieve an optimal PID parameters \(\:{(K}_{p},{K}_{i},{K}_{d})\), while the inner loop maximises the cost function by finding the worst case CSRT parameters \(\:{\theta\:}_{CSTR}\). This result of the min-max formulation is given as in Eq. (28).
The ML will significantly improve the adversarial optimization process through the use of surrogate model that evaluate both the CSTR system and the PID controller over a wide range of parameters can be computationally expensive. The surrogate model will be trained using Neural Networks to approximate the cost function \(\:J({K}_{p},{K}_{i},{K}_{d},\:{\theta\:}_{CSTR})\), reducing the need for full evaluations. The surrogate model can predict the performance of candidate PID and CSTR parameter combinations, allowing GA or PSO to explore the parameter space more efficiently. The surrogate model \(\:\widehat{j}\) approximates the true cost function as
$$\:\widehat{J}\left({K}_{p},{K}_{i},{K}_{d},\:{\theta\:}_{CSTR}\right)\approx\:J\left({K}_{p},{K}_{i},{K}_{d},\:{\theta\:}_{CSTR}\right)\:\:\:\:\:\:\:\:\:\:\:\:\:35$$
In this case each adversarial optimization episode can be treated as a trial in which an RL agent learns the optimal strategy for adjusting the PID gains to minimize the error under varying worst-case conditions. The RL agent can be trained using a reward signal based on the performance of the PID controller for each worst-case CSTR scenario as
$$\:r\left(t\right)=\underset{{\theta\:}_{{CSTR}}}{\text{max}}J({K}_{p},{K}_{i},{K}_{d},\:{\theta\:}_{CSTR})\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:\:36$$
The adversarial ML techniques is used to actively generate adversarial samples of worst case CSTR scenarios that push the PID controller to its limits. The adversarial ML model can be trained to learn which CSTR parameters \(\:{\theta\:}_{CSTR}\) result in the worst performance for any given PID controller. This adversarial model can then suggest worst-case scenarios during the optimization process to help find a more robust PID controller.