GA error "your fitness function must return a scalar value"

7 ビュー (過去 30 日間)
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2018 年 4 月 3 日
コメント済み: Geoff Hayes 2018 年 4 月 6 日
Hi all,
I am trying to use GA to minimize a function which is like this:
f=@(x) ((0.0011*(x(2:180)-x(1:179)))'*exp(-0.0078*x(Battery_num*180+1:Battery_num*180+179)))*Battery_cost/20+(0.0011*(x(182:360)-x(181:359)))'*exp(-0.0078*x(Battery_num*180+179+1:Battery_num*180+358))*Battery_cost/20+...
(0.0011*(x(362:540)-x(361:539)))'*exp(-0.0078*x(Battery_num*180+359:Battery_num*180+537))*Battery_cost/20+(0.0011*(x(542:720)-x(541:719)))'*exp(-0.0078*x(Battery_num*180+538:Battery_num*180+716))*Battery_cost/20+...
(0.0011*(x(722:900)-x(721:899)))'*exp(-0.0078*x(Battery_num*180+717:Battery_num*180+895))*Battery_cost/20+
(0.0011*(x(902:1080)-x(901:1079)))'*exp(-0.0078*x(Battery_num*180+896:Battery_num*180+1074))*Battery_cost/20+...
(0.0011*(x(1082:1260)-x(1081:1259)))'*exp(-0.0078*x(Battery_num*180+1075:Battery_num*180+1253))*Battery_cost/20;
however I get an error (after a long time), "Your fitness function must return a scalar value".
The problem is that the function f(x) gives a scalar value when I call it in the command window, so I don't understand why I get this error
any ideas?
thanks in advance
Nikolas

採用された回答

Geoff Hayes
Geoff Hayes 2018 年 4 月 3 日
Nikolas - your objective function must return a scalar value. In the above, f is returning a matrix instead of the scalar. If I evaluate your f with some dummy data, then this function returns a 179x179 matrix. A scalar is needed so that the GA can compare the fitness of one member of the population against all other members...
  21 件のコメント
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2018 年 4 月 6 日
Well I tried something else, I transpose my fitness function so now you can input a row like 1x2513 and you get a scalar (before I was taking a matrix 179x179).
So thank you very much for all these comments!
the problem now is that it takes ages, but I guess tha'ts another question
thanks again!!
Geoff Hayes
Geoff Hayes 2018 年 4 月 6 日
Glad that I was able to help!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by