フィルターのクリア

how to calculate fitness function when simulation is running?

5 ビュー (過去 30 日間)
Selim
Selim 2015 年 8 月 24 日
編集済み: Walter Roberson 2015 年 8 月 24 日
Hi everyone, I have a simulink model and it returns two output. One of them is real and the other is predicted. Both of them have 500*1 size. For the optimization I wrote genetic algorithm code. There is no problem about the ga code. I have a problem writing my cost function. When i run the ga.m my fitness function returns constant value. But it is impossible, for 500 values it must be varied and converge to 0 in optimization process (am i wrong?). Could you please help me?
this is my fitness function
function MSE = optimizationfunc(real,predicted)
real = [2;3;6;.....]; %it has 500 values and i didnt write it here
predicted = get_param('my_sys_simulink/predicted','predicted');
MSE = ((abs((real(:,1)-predicted(:,1)).^2)));
end
  2 件のコメント
Walter Roberson
Walter Roberson 2015 年 8 月 24 日
I suspect you want to either sum() or mean() those squared differences, not abs() them.
Selim
Selim 2015 年 8 月 24 日
編集済み: Walter Roberson 2015 年 8 月 24 日
i also used sum and mean, but i faced the same problem. i want to calculate fitness iteratively ( i mean for each 500 values). i have to change my code. perhaps i might use assignin or evalin functions, but i dont know how to use.

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

回答 (1 件)

Alan Weiss
Alan Weiss 2015 年 8 月 24 日
I have trouble understanding what you are doing. What are your control variables? I mean, which variables should the genetic algorithm change in order to try to minimize something, perhaps a sum of squares?
Whatever that vector of variables is, let's call it x, a row vector.
Your fitness function should accept that row vector and return a real number. Probably, it should look something like this:
function y = optimfunc(x)
[real,predicted] = mysimulationresults(x);
y = norm(real - predicted);
Obviously, I do not exactly know how you are going to write the function mysimulationresults(x), but I assume that you do.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

カテゴリ

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