Curve Fitting Problem using Genetic Algorithm

6 次查看(过去 30 天)
Hi i have two vectors of data as Input and output of a system; I want to model a function ( Which I call It mapping function) which maps input vector to output vector by use of Genetic algorithm the problem is I don't know how should I write Fitness function for genetic algorithm (because I need to have The mapping function for future use) and generally does genetic algorithm can be applied to this family of problems
  2 个评论
Nitin
Nitin 2013-6-22
An example would makes things easier to understand..
alix
alix 2013-6-23
I have input and output as names in & out that input is the input of system and output is systems response for example input is [50000 70000 80000 140000 60000 200000] and output is [38000 80000 120000 160000 140000 160000]
I want to find a relation between input an out put as a function to predict for example what would be the output of(78554)

请先登录,再进行评论。

回答(2 个)

Janarthanan
Janarthanan 2014-10-21
Curve fit can be done in matlab as follows:
Create two files GA.m and curvefit_multiobjective.m and run GA.m in the command window.
GA.m
%%First read the expt data 'Data' to fit from a file the content of which is shown below...
%e.g. y=a*exp(-b*x); where a= 10, b=0.2; and x: 0 to 10
%0.000 10.000
%1.000 8.187
%2.000 6.703
%3.000 5.488
%4.000 4.493
%5.000 3.679
%6.000 3.012
%7.000 2.466
%8.000 2.019
%9.000 1.653
%10.000 1.353
Data_exp=fopen('Data','r');
exp_data=fscanf(Data_exp,'%f',[2 inf]);
fclose(Data_exp);
exp_data=exp_data';
FitnessFunction = @(x)curvefit_multiobjective(x,exp_data); % Function handle to the fitness function
numberOfVariables = 2; % Number of decision variables
lb = []; % Lower bound
ub = []; % Upper bound
A = []; % No linear inequality constraints
b = []; % No linear inequality constraints
Aeq = []; % No linear equality constraints
beq = []; % No linear equality constraints
hybridopts = optimoptions('fminunc','Display','iter','Algorithm','quasi-newton','MaxFunEvals',100);
options = gaoptimset('CreationFcn',{@gacreationlinearfeasible},'TolFun',1e-4,'Generations',300,'StallGenLimit',200,'PopulationSize',200,'MutationFcn',{@mutationgaussian},'EliteCount',1,'CrossoverFraction',0.8,'CrossoverFcn',{@crossovertwopoint},'HybridFcn',{@fminunc,hybridopts});
[x,Fval,exitFlag,Output] = gamultiobj(FitnessFunction,numberOfVariables,A,b,Aeq,beq,lb,ub,options);
fprintf('The number of points on the Pareto front was: %d\n', size(x,1));
fprintf('The number of generations was : %d\n', Output.generations);
% x: the fit parameters, Fval: The minimized objective function
curvefit_multiobjective.m
function y = curvefit_multiobjective(x,exp_data)
%KUR_MULTIOBJECTIVE Objective function for a multiobjective problem.
% The Pareto-optimal set for this two-objective problem is nonconvex as
% well as disconnected. The function KUR_MULTIOBJECTIVE computes two
% objectives and returns a vector y of size 2-by-1.
%
% Reference: Kalyanmoy Deb, "Multi-Objective Optimization using
% Evolutionary Algorithms", John Wiley & Sons ISBN 047187339
% Copyright 2007 The MathWorks, Inc.
% Initialize for two objectives
% Compute first objective
[row,col]=size(exp_data');
y = zeros(2,1);
for i = 1:row
y(1) = y(1)+power(1-(x(1)*exp(-(x(2)*exp_data(i,1)))/exp_data(i,2)),2);
y(2) = y(2)+power(1-(x(1)*exp(-(x(2)*exp_data(i,1)))/exp_data(i,2)),2);
end
Good luck! Jana_bio

Frederico Severgnini
This is super old thread but I'd like to thank Janarthanan on the great answer. One question: In other curve fitting solvers (like lsqlin) we need to offer an initial guess for the curve parameters, which will be used as initial point in matlab calculations. Is there something similar in genetic algorithm applications for fitting problems? It seems ga has it's own set of technical terms, so if this concept existis here, I'm not sure what is the name for it.
Regards,
Fred

类别

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