ga-fitness
Show older comments
Dear All,
I need to optimize parameters of a function using the ga module. I have a coefficient matrix say A(9:4):
A =
-0.0996 -0.0323 -0.0640 -0.0365
0.0859 -0.0636 0.0552 0.0315
0.1805 0.0125 0.1159 0.0662
0.0521 0.0513 0.0335 0.0191
-0.3028 0.0647 -0.1946 -0.1111
-0.2242 -0.0382 -0.1440 -0.0822
0.0475 -0.0191 0.0305 0.0174
0.2170 -0.0010 0.1394 0.0796
0.0437 0.0257 0.0281 0.0160
and a vector B where i store the experimental data say B(9:1):
B =
-4.8700
-3.2100
5.1000
5.3400
-1.6200
-8.1700
-0.4700
4.8300
3.0800
my chromosome will be a vector x(4:1)
I use this fitness function:
FitnessFcn = @(x)bsxfun(@minus,abs(bsxfun(@times,A,x)),B)
But when I am using
[x]=ga(FitnessFcn,4)
I get:
??? Subscripted assignment dimension mismatch.
Error in ==> fcnvectorizer at 14
y(i,:) = feval(fun,(pop(i,:)));
Error in ==> makeState at 47
Score = fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in ==> gaunc at 41
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ==> ga at 279
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
Could you please help me resolve the problem.
Thanks
Accepted Answer
More Answers (1)
Andrei Bobrov
on 22 Jun 2012
Can so?
FitnessFcn = @(x)abs(A*x-B) ;
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!