現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
genetic algorithm run time and result analysis
10 ビュー (過去 30 日間)
古いコメントを表示
Hello
i am using Genetic algorithm. my problem has
nvars=30,
population size = 400
size of initial population matrix = 50x30
max. generation = 200
the following is a plot of best fitness value optained at each generation. the dark dots are ''best value across a generation '' the lighter dots are ''mean value across a generation''
question 1 is; it takes very long time to reach this figure, more than 10 hours, is that normal for my code that has around 300 lines?
question 2: whould any one comment on the shape of output result, this is scattered but on the same area. may be the search space does not mutate enogh? i used the default options for mutation and crossover.
question 3: what options could be useful to reduce running time but get an accurate result, i can reduce the max generations and population size, but i want to lmite the run time to 15 min.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/368806/image.png)
15 件のコメント
Walter Roberson
2020 年 9 月 30 日
is that normal for my code that has around 300 lines?
Did you implement genetic algorithm yourself, in about 300 lines of code? Or are you using ga() ?
Nourhan Elsayed
2020 年 9 月 30 日
i use this function
[x,fval,exitflag,output,population,scores] =ga(@FittingFunction,nvars,[],[],[],[],lb,ub,@NonLinearConstraints,[],options);
Walter Roberson
2020 年 9 月 30 日
What kinds of operations do you do in those 300 lines?
Are the nonlinear constraints only inequalities or are there equalities as well? You can end up having to test a lot of differerent values to find matches for nonlinear equalities.
Star Strider
2020 年 9 月 30 日
One possibility is that ga is chasing a moving target, and the fitness function is changing arbitrarily, perhaps due to a random number generator call. A static fitness function — where only the parameters are changing — should converge.
Nourhan Elsayed
2020 年 9 月 30 日
thank you Strider
would you please explaine more about a moving target?
in addition, i want to ask about the last numer '0'
i got when i interrupt the run. as i got this massage
Read of fitting fn successeful
127 1005600 1.55399e+11 1211 0
Optimization terminated: Stopped in inner iterations.
Nourhan Elsayed
2020 年 9 月 30 日
thank you Walter Roberson
i have only nonlinear equality constraints
What kinds of operations do you do in those 300 lines?
i have to make a sequance of calculations to define dependent variables that participate on the fitting function. in addition, some lines calculate the initial population matrix. and other lines read and load input data from excel file
Walter Roberson
2020 年 9 月 30 日
How large is the fitting function and what kinds of operations are you doing in it?
Are you loading a file inside the fitting function?
Walter Roberson
2020 年 9 月 30 日
I do not recognize that final message about inner iterations. Which MATLAB version are you using?
Walter Roberson
2020 年 9 月 30 日
Nonlinear equality constraints effectively require the equivalent of an fsolve to try find a position that meets the constraints. That can be tricky since the constraints are permitted to be discontinuous. Also sometimes the constraints involve considerable computation.
Nourhan Elsayed
2020 年 9 月 30 日
編集済み: Nourhan Elsayed
2020 年 9 月 30 日
ok,
my project has 4 files
file 1: it loads input data from excel file and creat initial population matrix based on input data. it contains lower and upper bounds, some independent variables that are defined as Global and most of them are vectors. (i run this file before i run the ga file , i used to do this step befor i run the ga to overcome the error of undefined variable).
file 2 : Fitting Function: this file containes 4 sections doing next tasks:
%%Task 1: Decision variables : define vector X [x1, x2, x3, ..... x30] of 30 Decision variables for the optimization process
%% Task 2: range of suitable Engines
the code access ''excel file'' to look up for data within a defined range and store them on a matrix,
each element of this matrix is compare to value of x1 and choose the closest then the code acces the excel file again and extract data coressponding to this value.
this step repated for x2 and x3
%% Task 3 : calculate dependent variables (V1, V2, PTO, PTI)
V1 = a* Ld^2 + b * Ld + c * ones(1,9)
V2 = u* LF^2 + d * LF + cw* ones(2,9)
given that
Ld = [x(2:12)]
LF = [x(13 :21); x(22:30)]
% PTO and PTI
PTI = P_Prop_left - x1 * Ld;
PTI (PTIt<0)= 0
PTO= x1* Ld - P_Prop_left;
PTO(PTOt<0) = 0 ;
%% Task 4 objective function:
TFC = (( x1 * (Ld.* V1)+ x1 * (Ld .* V1)) * T') + ((x2* (LF .* V2) * T')
Note that operations are matrix operations.
file 3: NonLinearConstraints:
c = [];
ceq = x1 * Ld+ 0.5 * x2* LF - P_Prop_left - 0.5 * P_EL
file 4: it contains only the ga function and optimization options.
i provided here only a sample and conclusion for the code operations for more clarification.
when i interrupt the run. as i got this massage
Read of fitting fn successeful
127 1005600 1.55399e+11 1211 0
Optimization terminated: Stopped in inner iterations.
i want to ask about the meaning of last naumber of this massage. i suppose that the algorithm can not satisfy the constraint.
i hope you can help
thank you a lot
later.
Walter Roberson
2020 年 9 月 30 日
編集済み: Walter Roberson
2020 年 10 月 4 日
Are you reading a file inside your objective function (task 2)? That is expensive to process. https://www.mathworks.com/help/matlab/math/parameterizing-functions.html
Nourhan Elsayed
2020 年 10 月 1 日
yes Walter, it sounds you are right. parametrizing function could be one solution .
i suggest also to use bilevel concept. x1, x2, x3 are the upper level variables which pass their values to lower level optimization process. in that case, lower level optimization problem has a fixed x1, x2, x3 and that will reduce search space significantly.
thank you a lot
Nourhan Elsayed
2020 年 10 月 4 日
that one was helpful https://www.mathworks.com/matlabcentral/answers/602392-genetic-algorithm-run-time-and-result-analysis#comment_1031587
i used function handle on my task and i re-formated the whole problrm.
i devided it into two optimization problems, or two layers, one inside the other.
the outer layer i used ga algorithm and the inner layer i used fmincon algorithm. that gave me the figure below.
would you please check that. the process terminated because it reached maximum no of generations. i am asking , on the light of this output, do my problem is going on the right way. i know this information is not enough to judge. but i was watching the code during running and i noticed that my variables are changing , but unfortunatlty, i coudn't get out information about each generation
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/370912/image.png)
Walter Roberson
2020 年 10 月 4 日
You might want to add an additional PlotFcn to plot the generation information. Or since you are only running 50 generations, change the 'Display' option to 'iter'
回答 (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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)