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.
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
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!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 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 (한국어)