フィルターのクリア

How to invoke and use GA tool in Matlab R2022b?

23 ビュー (過去 30 日間)
Sadiq Akbar
Sadiq Akbar 2022 年 12 月 14 日
コメント済み: Star Strider 2022 年 12 月 20 日
I typed optimtool in Matlab R2022b to invoke the GA Tool but its' not there. Can anybody guide me how to invoke and use GA tool in Matlab R 2022b because I usually tune the setting for the best results but since its not here, so what to do and how to do?
Regards,
  4 件のコメント
Star Strider
Star Strider 2022 年 12 月 14 日
First, there is no reason to put the ga call in a loop unless you are varying specific parameters between calls to it.
Second, I have no idea what the fitness function is or the problem you are optimising.
Third, it is never advisable to use global variables. See the documentation on Passing Extra Parameters to understand how to do that correctly.
Sadiq Akbar
Sadiq Akbar 2022 年 12 月 14 日
Reason to put ga in loop: Because I want to get 10 independent run values for the same parameters.
The fitness function is a user defined function defined for the problem. My problem is to find the desired solution x whose value matches the value of my desired vector u or nearly matches it.
Use of global variables: If I don't use global variables, then how will it be visible to my fitness function?

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

採用された回答

Star Strider
Star Strider 2022 年 12 月 14 日
If you are doing parameter estimation, this approach will likely work —
x = 1:0.1:10;
y = 2.5*exp(-(x-5).^2/2)+randn(size(x))*0.25;
objfcn = @(b,x) b(1).*exp(-(x-b(2)).^2*b(3));
fitnessfcn = @(b) norm(y-objfcn(b,x));
Parms = 3;
opts = optimoptions('ga', 'MaxGenerations',1000);
[B,fval,exitflag,output] = ga(fitnessfcn, Parms,[],[],[],[],[],[],[],opts);
Optimization terminated: average change in the fitness value less than options.FunctionTolerance.
Parameters = B
Parameters = 1×3
2.5311 4.8704 0.5030
BestFitness = fval
BestFitness = 2.2760
Generations = output.generations
Generations = 129
figure
plot(x, y, '.', 'DisplayName','Data')
hold on
plot(x, objfcn(B,x), '-r', 'DisplayName','Function Fit')
hold off
grid
legend('Location','best')
This uses ga to estimate the parameters of the function fitting the data.
With respect to eliminating global variables, see the ‘Passing Extra Parameters’ documentation I already linked to.
.
  17 件のコメント
Sadiq Akbar
Sadiq Akbar 2022 年 12 月 20 日
Thanks a lot for your pray dear Star Strider. Stay blessed.
Star Strider
Star Strider 2022 年 12 月 20 日
As always, my pleasure!
Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by