How to Set Up a Genetic Algorithm to Minimize Goodness of Fit

조회 수: 1 (최근 30일)
CJ
CJ 2016년 4월 7일
댓글: CJ 2016년 4월 7일
I would like to use the genetic algorithm functionality to minimize the error between two sets of data, and determine the best values for two coefficients. The following is my code:
% Set initial paramters.
Cl_initial=3;
R=0.5;
u=0.5;
T=40;
t=[68.92 109.97 287.22 116.95 171.89 90.3 103.54];
Nt = length(t);
Clt = zeros(1,Nt);
THM = zeros(1, Nt);
result = zeros(2, Nt);
% Solve for Chlorine residual.
for i = 1:Nt
Clt(i) = [Cl_initial*(1-R)/(1-R*exp(-u*t(i)))];
end
% Solve for THM formation.
NClt = length(Clt);
for j = 1:NClt
THM(j) = T*(Cl_initial-Clt(j));
end
%Combine into single matrix.
result = [Clt; THM];
%Calculate mean square error between results and solution.
solution=[0.7075 0.9133 0.7125 0.86 0.7375 0.8225 0.984;
16.4 24.7 27.4 22.7 27.2 20.6 22.9];
cost_func = 'MSE';
fit = goodnessOfFit(result, solution, cost_func);
I need to minimize "fit" while varying the coefficients of "R" and "u" to find the best values for those two coefficients. I also know that R and u have to be between 0 and 1.
I am a little overwhelmed as to where to start. Any help would be appreciated.
Thanks.
  댓글 수: 2
Brendan Hamm
Brendan Hamm 2016년 4월 7일
Why would you think that you would need a Genetic Algorithm here?
This could be solved with basic Optimization Toolbox solvers like fmincon or lsqcurvefit .
CJ
CJ 2016년 4월 7일
Yes, you are correct. I was thinking I could use the ga function in preparation for something later, but it is much easier to use fmincon. Thanks.

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by