Genetic algorithm for tracking
Show older comments
Hi all,
I am trying to produce a tracking algorithm using a genetic algorithm.
I am having an issue where the values created just decrease forever, i believe i need to create a better fitness function to achieve my desired goal as my current one is just minimising the value. Below is my current fitness function.
function [X_New] = Fitness_Function_X( X_Correction)
%% Fitness function
global Xfval %Car_Position_Current_X
X_New = ( Xfval + X_Correction) ;
end
Is there a way to change the value the system is matching the result to to calculate the cost function or is there a better way to word my fitness function?
3 Comments
Geoff Hayes
on 9 Apr 2020
Cameron - you may need to provide some details on your fitness function. Are you trying to maximize or minimize? What do you mean by having an issue where the values created just decrease forevers? Which values?
Cameron Barber
on 9 Apr 2020
Geoff Hayes
on 9 Apr 2020
Cameron - if you want to minimize the distance between any point, then why not calculate the distance between the updated point and the desired point and then have your fitness function return that value? Let's assume you have a desired/target position given by
function [dist] = Fitness_Function_X( X_Correction)
global Xfval %Car_Position_Current_X
global XTargetVal % target position
X_New = ( Xfval + X_Correction);
dist = sqrt((XTargetVal - X_New)^2);
end
If you have coordinates for y (and perhaps z) then you could include them in the distance calculation too. As an aside, I don't like using global variables but have only done it here for illustration. I prefer to use nested functions
Answers (0)
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!