Machine Learning Control: Optimizing a PID Controller with Genetic Algorithms

Welcome back! In the previous segment, we discussed how to use a genetic algorithm to optimize a PID controller’s control gains. The goal was to minimize the cost function of a transfer function called G. We coded the algorithm and ran it successfully. Now, it’s time to analyze the results and see what this optimization achieved.

Machine Learning Control: Optimizing a PID Controller with Genetic Algorithms
Machine Learning Control: Optimizing a PID Controller with Genetic Algorithms

Plotting the Step Responses

First, let’s take a moment to appreciate the visual representation of the genetic optimization process. By running the algorithm, we obtain 250 control laws, each with its corresponding step response. Initially, the algorithm tries various random PID gains, resulting in high-cost functions. However, after a few iterations, it starts to converge on better control laws that yield improved performance. As we observe the step responses, we can see that the cost function hones in on values close to the optimal solution. Sometimes, due to mutations, the cost function may fluctuate slightly, but overall, we see a convergence around a value of 1.5.

At the end of the algorithm, the best PID gains are revealed, along with the optimal output value. This time, the optimal output value is 1.49. It’s worth noting that the exact output value may vary due to the randomness inherent in the genetic algorithm. Nevertheless, it remains close to the desired value.

Analyzing the Evolution of Control Laws

To gain a deeper understanding of the genetic optimization process, we can plot and analyze the intermediate generations and individuals. By visualizing the solutions, we can identify trends and patterns.

Further reading:  Techal: Revolutionizing Storage with Cloud Object Storage

In one of the plots, we observe all 25 individuals for each of the 10 generations. The individuals are color-coded based on their performance, with small cost functions represented by shades of blue and large cost functions represented by shades of yellow. A clear trend emerges: as the generations progress, more and more control laws achieve low cost functions and nearly optimal performance. The first generation consists mostly of poorly performing individuals, as they were randomly generated. However, by the second generation, the number of poorly performing individuals decreases significantly. This trend continues, and eventually, we see a dominance of low-cost control laws in the later generations.

Moreover, the plot reveals that even the initial population contained some individuals with decent performance. However, as the generations progress, these control laws become further optimized, resulting in darker shades of blue.

Converging to the Optimal Parameters

Another interesting plot showcases the evolution of the PID values across the generations. Initially, the individuals are scattered in a cube corresponding to the possible PID values. However, as time goes on, they start converging towards a specific region in parameter space, which represents the best-performing set of control laws. The more generations there are, the closer the individuals get to this sweet spot in parameter space, resulting in the best performance.

Comparing the First and Last Generations

To further illustrate the improvement achieved by the genetic algorithm, we compare the individuals from the first and last generations. In the first generation, the output responses vary significantly, with some individuals being unstable and yielding poor performance. However, by the tenth generation, all the PID control laws are stable, with a narrow band of responses that achieve low cost functions. The improvement is evident in both the smaller control input and the reduced overall integrated LQR cost, which decreases by almost a factor of two.

Further reading:  Clustering and Classification: Support Vector Machines and Decision Trees

Conclusion

In conclusion, the genetic algorithm successfully optimized the PID controller, resulting in significant improvement in control performance. By analyzing the intermediate generations and individuals, we gained insights into the evolution of the control laws and the convergence towards optimal parameter values. This process allowed us to diagnose the learning rate, the effectiveness of the initial population, and the performance of the best individual in the first generation. Genetic algorithms, such as the one implemented in this example, are powerful tools in control systems optimization. You can try this code on your own control system and explore its capabilities. For more information and resources on machine learning and information technology, visit Techal. Happy optimizing!

YouTube video
Machine Learning Control: Optimizing a PID Controller with Genetic Algorithms