Genetic Algorithm with Array as variable

So say I have some array at the beginning of a very long code. And at the end the program outputs a single value. How do I get the genetic algorithm tool to change the values of each element in the array to minimize the output value? This may be something simple but I cannot find a method or example on how to do this. Thanks for your time!

 採用された回答

Alan Weiss
Alan Weiss 2016 年 8 月 11 日

2 投票

All you have to do is change your array to a row vector, something like this:
input = x(:)';
Here x represents your array of variables (known as decision variables) that the optimizer changes to minimize the output value (known as the objective function or, for ga, the fitness function). Then input is the set of variables that ga evaluates for finding a minimum.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

5 件のコメント

Set Eng
Set Eng 2020 年 10 月 5 日
I have same problem , and I do this step for my variables :
input = x(:)';
but Genetic algorthim code not work with it , how can I fix it ?
Alan Weiss
Alan Weiss 2020 年 10 月 5 日
I have no idea what your inputs and function call are, so how can I comment? I suggest that you ask a new question (I mean start a new Answers topic) and give some detail. Include your function call ([x,fval] = ga(whatever)) and your options.
Alan Weiss
MATLAB mathematical toolbox documentation
Set Eng
Set Eng 2020 年 10 月 5 日
I write new quastion in same Title , and add all details , can you help me ,please
Walter Roberson
Walter Roberson 2020 年 10 月 5 日
Your Question does not appear to be posted yet?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2016 年 8 月 11 日

コメント済み:

2020 年 10 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by