How to use "ga" (genetic algorithm) for curve fitting
2 ビュー (過去 30 日間)
古いコメントを表示
Hi every body.
I have two available vectors
and
. I want to fit the function
on Γ which
,
,
,
,
, and
should be identifed to fit the function. So, I have Γ and x already existing in my workspace. I used the genetic algorithm as bellow to find
,
,
,
,
, and
.
Fun=@(p1,w1,x,phi1,p2,w2,phi2)(p1*sin(w1*x+phi1)+p2*cos(w2*x+phi2));
Cost=@(p1,w1,phi1,p2,w2,phi2)norm(Gamma-Fun(p1,w1,x,phi1,p2,w2,phi2));
coef=ga(Cost,6)
but things go wrong when I run the code:
Not enough input arguments.
Error in @(p1,w1,phi1,p2,w2,phi2)norm(Gamma-Fun(p1,w1,x,phi1,p2,w2,phi2))
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 52)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 45)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 399)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
Can anybody help me how I may solve this problem with genetic algorithm?
0 件のコメント
採用された回答
Walter Roberson
2021 年 4 月 16 日
cost_wrapper = @(x) Cost(x(1),x(2),x(3),x(4),x(5),x(6));
coef = ga(cost_wrapper, 6)
3 件のコメント
Walter Roberson
2021 年 4 月 16 日
cost_wrapper accepts a vector of 6 values and extracts each of the 6 values and passes them one-by-one to Cost.
All of the Mathworks optimizers require functions that accept vectors of values, not individual parameters.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Genetic Algorithm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!