using genetic algorithm for optimization
조회 수: 2 (최근 30일)
이전 댓글 표시
i have this error message
??? 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, ...
Error in ==> main at 11
[x,fval,exitflag,output,final_pop]=ga(FitnessFcn,nvar,options);
Caused by:
Failure in user-supplied fitness function evaluation. GA cannot continue.
댓글 수: 0
채택된 답변
Alan Weiss
2013년 3월 29일
Apparently there is an error in your fitness function. If it isn't too long, please post it so we can see what might be the problem.
And please include your gaoptimset calls and your function call to ga (e.g., x = ga(@main,4,A,b) )
Alan Weiss
MATLAB mathematical toolbox documentation
댓글 수: 0
추가 답변 (3개)
Walter Roberson
2013년 3월 29일
Your fitness function is returning your input values x_pop as its first return value. It should not be doing that. The documentation indicates,
fitnessfcn
Handle to the fitness function. The fitness function should accept a row vector of length nvars and return a scalar value.
When the 'Vectorized' option is 'on', fitnessfcn should accept a pop-by-nvars matrix, where pop is the current population size. In this case fitnessfcn should return a vector the same length as pop containing the fitness function values. fitnessfcn should not assume any particular size for pop, since ga can pass a single member of a population even in a vectorized calculation.
So your fitnessfcn should only be returning a single variable, not two variables, and (unless you have Vectorized turned on) return a scalar such as fx_val .
mado
2013년 3월 29일
편집: Walter Roberson
2013년 3월 29일
댓글 수: 9
Walter Roberson
2013년 3월 29일
Put a breakpoint at the fx_val assignment. Run the program. When it stops, show us
size(ISE)
size(sys_overshoot)
size(ISE*beta+sys_overshoot*alpha)
If those values look reasonable, use the command
dbcont
to continue. See if you again stop at the same line, or if you get an error first. If you again stop at the same line then the problem is not triggered immediately so you should test those sizes and continue executing until you see something odd.
My speculation is that at some point an empty matrix is being generated.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!