How to estimate a fitness function to Find minimum of function using genetic algorithm?

6 views (last 30 days)
Hello, I have a Transfer Function model (tf1,discrete)of a system , which is controlled by a PI controller. the PI controller is tuned by 'pidtool'. Now I just want to find the minimum value of the Kp and Ki by the function genetic algorithm, for that I need the fitness function. I have googled ,there are many things about 'PID tuning with genetic algorithm'and also about to write the fitness function, but there are no particular procedure is mentioned about estimating the fitness function. so is there any toolbox or simulink option for calculating the fitness function for genetic algorithm?

Answers (1)

Walter Roberson
Walter Roberson on 8 Jun 2015
Fitness functions are not estimated. But they are designed.
The main thing you need to worry about is how to weight differences contributed by multiple inputs. If you have two inputs X1, X2, then if X1 is off optimal by 0.1 then is that more or less significant than X2 being off optimal by 0.1 ? If one of the two values represents an angle then 0.1 might be a really big change, but for other problems it might be of little consequence. Even if the values are the same scale, you need to ask whether each being off by 0.1 should increase the score the same as if one of them had been off by 0.2 (0.1+0.1), or if it should increase the score the same as if one of them had been off by 0.14142 (sqrt(2)/10) ?
To avoid problems with continuity of derivatives, fitness functions usually do not use sum(abs(a-b)) and instead use sqrt(sum((a-b)^2)) -- Euclidean distance. But there are other distance measures that may be appropriate. Differentiability is not required for Genetic Algorithms but it is a good practice to get into as you often want to be able to use the same fitness function with other search methods that do require differentiability.
When components are independent, fitness functions are often of the form
W1 * (X(1) - optimal_x1).^2 + W2 * (X(2) - optimal_x2).^2
where W1 and W2 are constants that reflect the relative importance of the values being off optimal, and the squares discouraging the search from wasting time far away from optimal.
If you do not know what the optimal is, if you are looking at something like minimizing distances, then you let the distances be your fitness function.
If you want to minimize Kp and Ki together then you can use
W1 * Kp^2 + W2 * Ki^2
with constants W1 and W2 reflecting the relative scales of Kp and Ki and reflecting how important it is that they be optimal. For example if Kp is on the order of 100 times larger than Ki, and it is twice as important that Kp be minimized, then
2 * Kp^2 + 100^2 * Ki^2
the 100^2 brings the Ki to the same scale as Kp, and the 2 makes Kp twice as important

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!