필터 지우기
필터 지우기

plot the function value according to the value of the optimized parameter by genetic algorithm

조회 수: 15 (최근 30일)
Dears,
I would like to extract the value of the optimized parameters x* and the value of the function at each step of the optimization.
From my initial search on the internet there is a way using the plot functionality, but I was not able to get the funtion value Y in terms of the optmized parameters values X* at each step neither
The optimization methodology is GA.
Could you please help me with that.
  댓글 수: 4
Asvin Kumar
Asvin Kumar 2020년 4월 7일
The options I mentioned in my previous comment plot the best and mean value of a particular generation at the specified Plot Interval.
I'm unsure what you're looking for. If you would like to extract the optimal parameters and optimal value at each generation, you can have a look at the following link or at Ameer Hamza's answer.
Depending on the nature of your variable of optimization, you can try using 'gaplotbestindiv' as mentioned at https://www.mathworks.com/help/gads/genetic-algorithm-options.html#f14474.
Let me know if this helps or if it doesn't, please clarify your question and I'll get back to you.
Zakaria
Zakaria 2020년 4월 7일
Thank you Asvin for the response,
Ameer's code works perfectly and answers my question.

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 6일
This example shows how to extract the best objective function value and the corresponding x vector at each iteration
global x_iterations y_iterations
x_iterations = [];
y_iterations = [];
obj_fun = @(x) sum(x.^2);
opts = optimoptions('ga', 'OutputFcn', @myOutFcn);
[x_final, f_final] = ga(obj_fun, 10, [], [], [], [], [], [], [], opts);
function [state, options, optchanged] = myOutFcn(options, state, ~)
global x_iterations y_iterations
[best_val, idx] = min(state.Score);
best_x = state.Population(idx,:);
x_iterations = [x_iterations; best_x];
y_iterations = [y_iterations; best_val];
optchanged = false;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by