minimizing with genetic algorithm

5 ビュー (過去 30 日間)
dal
dal 2024 年 12 月 25 日
コメント済み: dal 2024 年 12 月 30 日
Good morming
I would like to minimize my function with GA
function y=obj1(x)
y=(1.002)-((1-exp(-0.00003*x))/(0.00003*(x+1.5)+(0.00063*(1-exp(-0.00003*x)))));
for x=24:720
the résule in Matlab whene I use :
[x,y]=ga(@obj1,1,24,720)
Optimization terminated: average change in the fitness value less than options.TolFun.
x =
-1.499097579634137
y =
-3.566513164743854e+004
negative results.

回答 (2 件)

Walter Roberson
Walter Roberson 2024 年 12 月 25 日
y = @(x) (1.002)-((1-exp(-0.00003*x))./(0.00003*(x+1.5)+(0.00063*(1-exp(-0.00003*x)))));
fplot(y, [-2, 10])
fplot(y, [-1.5 -1.498])
fplot(y, [5 1000])
syms x
[N,D] = numden(y(x))
N = 
D = 
vpasolve(D)
ans = 
So near -1.49906 is indeed a minimum, since it is a critical point of the function. ga() was correct to find it.
On the positive side, the minimum is somewhere near 300.
If you want to constraint to positive values, then use a lb parameter to ga:
A = [];
b = [];
Aeq = [];
beq = [];
lb = 24;
ub = 720;
[x,y]=ga(y, 1, A, b, Aeq, beq, lb, ub)
ga stopped because the average change in the fitness value is less than options.FunctionTolerance.
x = 315.7285
y = 0.0120
Your bug was in providing lb and ub in the slots reserved for A and b.
  1 件のコメント
dal
dal 2024 年 12 月 30 日
Thank you for your help, you've really helped me

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


Sam Chak
Sam Chak 2024 年 12 月 25 日
Hey @dal
For time-invariant real-valued univariate functions, it is recommended to plot the graph to estimate the approximate location of the minimum point. From the graph, we can visually estimate that the local minimum lies between 200 and 400 with a high degree of confidence. Narrowing the search range can sometimes enhance the algorithm's efficiency. If you can provide the rate of change of the function, some algorithms can search even more effectively
In the example below, I used 'fminbnd()' (I call it f min bound) instead of the genetic algorithm, 'ga()'. Please ensure that you enter the intended inputs correctly and in the correct sequence. In your case, the function did not flag an error because there was no error from the perspective of program execution. This can often be challenging for beginners, as they may not understand what went wrong, even though they are certain that the result is incorrect.
lb = 24; % lower bound of plot
ub = 720; % upper bound of plot
ss = 0.01; % step size
%% the function
f = @(x) 1.002 - ((1 - exp(- 0.00003*x))./(0.00003*(x + 1.5) + (0.00063*(1 - exp(- 0.00003*x)))));
x = linspace(lb, ub, (ub - lb)/ss + 1);
%% the plot
plot(x, f(x)), grid on, grid minor
xlabel('x'), ylabel('f(x)')
lb = 200; % lower bound of search
ub = 400; % upper bound of search
%% location of the local minimum value
xmin = fminbnd(f, lb, ub)
xmin = 315.7286
%% the minimum value in the given range
fmin = f(xmin)
fmin = 0.0120
  1 件のコメント
dal
dal 2024 年 12 月 30 日
Thank you for your help, you've really helped me

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

カテゴリ

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