필터 지우기
필터 지우기

GA fitness function with variables in a summation

조회 수: 1 (최근 30일)
Nima
Nima 2022년 11월 8일
댓글: Star Strider 2022년 11월 10일
What is the best way to define the following fitness function for GA optimization?
where are the variables to be found with GA-toolbox. N can be a positive integer.
  댓글 수: 2
Star Strider
Star Strider 2022년 11월 8일
What is y?
How large is N and how is it defined?
Nima
Nima 2022년 11월 8일
I just made a change in the formula! So ist frequency dependent impedance and as an example.

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

채택된 답변

Star Strider
Star Strider 2022년 11월 8일
편집: Star Strider 2022년 11월 8일
I still do not completely understand what you want to do.
Perhaps this —
Z = randn(16,1) + 1j*randn(16,1); % Creeate Data
omega = (0:15).'; % Creeate Data
objfcn = @(b,x) b(1) + 1i.*x.*b(2) + 1./(b(3) + 1j.*x.*b(4)); % Objective Function
Parms = 4; % Number Of Parameters To Be Estimated
ftnsfcn = @(b) norm(Z - objfcn(b,omega)); % Fitness Function
[B,fval,exitflag,output,population,scores] = ga(ftnsfcn, Parms, [],[],[],[], zeros(1,Parms)); % Genetic Algorithm Call
Optimization terminated: average change in the fitness value less than options.FunctionTolerance.
fprintf('\nR\t= %15.3f\nL\t= %15.3f\nG\t= %15.3f\nC\t= %15.3f\n',B)
R = 0.000 L = 0.007 G = 1.275 C = 0.760
fprintf('\nFinal Fitness Value = %15.6f\n',fval)
Final Fitness Value = 6.843630
fprintf('\nGenerations = %6d\n', output.generations)
Generations = 157
fprintf('\nMessage: %s\n',output.message)
Message: Optimization terminated: average change in the fitness value less than options.FunctionTolerance.
figure
plot(omega, real(Z), 'pm', 'DisplayName','Re(Z)')
hold on
plot(omega, imag(Z), 'pc', 'DisplayName','Im(Z)')
plot(omega, real(objfcn(B,omega)), '-m', 'DisplayName','Re(Z_{est})')
plot(omega, imag(objfcn(B,omega)), '-c', 'DisplayName','Im(Z_{est})')
hold off
grid
legend('Location','best')
I do not understand the reason for the summation in the objective funciton, so I do not use it here.
It may be necessary to run ga a few times to get the best fit (save the results each time), however it should be possible to get a decent fit to your data.
EDIT — Corrected typographical errors.
.
  댓글 수: 4
Nima
Nima 2022년 11월 10일
Thank you so much!
Star Strider
Star Strider 2022년 11월 10일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by