how to use genetic algorithm (GA) in matlab ?
16 次查看(过去 30 天)
显示 更早的评论
Hi, all
I found GA function https://kr.mathworks.com/help/gads/options-in-genetic-algorithm.html.
% input_data shape = [ M x N x T ] ( channel, trials, time sample )
% ga : Find minimum of function using genetic algorithm
ga(fitness_function_my_own, input_data)
I want to find a few channels that minimize the fitness function for M channels, and the question is two.
Q1. I wonder if ga can be applied to the matrix data ?
Q2. I know that parameters that need to be set, such as crossover probability and mutation probability, are theoretically necessary to apply ga.
Is it necessary to modify the ga function directly in the file implemented to apply this option to the corresponding function?
0 个评论
采纳的回答
Walter Roberson
2021-2-15
Q1. I wonder if ga can be applied to the matrix data ?
Yes, but fitness_function_my_own must return a scalar.
If you want fitness_function_my_own to return multiple values because you are trying to optimize multiple functions at the same time, then you need gamultiobj() instead of ga()
Is it necessary to modify the ga function directly in the file implemented to apply this option to the corresponding function?
No, see gaoptimset() to construct an options structure. The options structure must be passed as either the 10th or 11th parameter to ga(); you can use [] for parameters you are not using. For example,
ga(fitness_function_my_own, 3, [], [], [], [], [], [], [], options)
Note: you do not pass your data directly in to fitness_function_my_own . Instead see http://www.mathworks.com/help/matlab/math/parameterizing-functions.html
3 个评论
Walter Roberson
2021-2-15
Yes. See the list of options at https://www.mathworks.com/help/gads/ga.html#mw_4a8bfdb9-7c4c-4302-8f47-d260b7a43e26
In particular see the details for MutationFcn https://www.mathworks.com/help/gads/genetic-algorithm-options.html#f6633 and CrossOverFcn https://www.mathworks.com/help/gads/genetic-algorithm-options.html#f7820
You can also code custom mutation and crossover functions.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!