フィルターのクリア

How to constrain the Genetic Algorithm so that the variables are in the form of an n by m matrix

2 ビュー (過去 30 日間)
My cost function will only accept a 25 * 51 matrix as an input (1275 variables) and then it returns a single number. How will I set up the GA to minimise this cost function?
Thanks!

採用された回答

Matt J
Matt J 2014 年 5 月 15 日
編集済み: Matt J 2014 年 5 月 15 日
Insert the following as the first line in your cost function
x=reshape(x,25,51);
Now it doesn't matter what shape the original input x, is.
  3 件のコメント
Matt J
Matt J 2014 年 5 月 15 日
編集済み: Matt J 2014 年 5 月 15 日
So the problem is that the current cost function yourfunc(x) doesn't know the matrix dimensions in advance? You will have to wrap it in another function that does know the architecture and which reshapes the input accordingly, e.g.,
fitnessFunc=@(x) yourfunc(reshape(x,[M,N]))
Surely, you have something outside of yourfunc() that does know the architecture. How else does the matrix get into its intended shape in the first place?
Craig
Craig 2014 年 5 月 15 日
Sorry, your original suggestion works. I just misunderstood what it would do. Thanks for your answer!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by