Genetic Algorithm - Fitness function value differences...
显示 更早的评论
Hello everybody,
I am currently using a genetic algorithm thanks to the "ga" function in MatLab 2012a, and I am encountering an issue whom I have no idea how to solve...
I have my fitness function that i'm trying to minimize. Let's call her myfun :
function merit = myfun(x,...,...,...)
A=x(1);
B=x(2);
C=x(3);
... some boring stuff ...
merit=...;
% I save the current parameters values and the figure of merit in a txt file
param=[A B C merit];
save parameters.txt param -append -ascii
end
Until that point, everything is fine. Each individual is written in my txt file...
BUT: When I'm looking at my current best individual in my txt file, and I recompute the figure of merit of my function, I don't get the same value than the one in the txt file.
Example:
My best individual in my txt file:
A = 9.9488952e-01
B = 7.7381392e+01
C = 3.2928992e+07
merit = 3.9479605e+00
If I recompute the performance manually (with the same code, just evaluating the code line by line) and I write the result in my txt file, I get:
A = 9.9488952e-01
B = 7.7381392e+01
C = 3.2928992e+07
merit = 3.5089634e+00
The same problem occurs in the totally different program of one of my colleague... And I don't understand why... Hope that I was clear enough and I apologize for my weak english skills...
Thank you in advance
回答(3 个)
Sean de Wolski
2013-11-4
编辑:Sean de Wolski
2013-11-4
0 个投票
What is the boring stuff? The secret likely lies in there.
*Some specific things to look for:
- Anything random?
- Anything that relies on persistent variables, global variables or nested functions with persistent states?
- What options are you passing into ga?
- Have you tried using ga with a 'HybridFcn' so that the genetic algorithm may find the basin of the global minimum and then a gradient based solver can finish it?
- Have you tried using patternsearch, when integer constraints aren't necessary, this is generally recommended over ga.
Vialla
2013-11-5
0 个投票
1 个评论
Sean de Wolski
2013-11-5
编辑:Sean de Wolski
2013-11-5
This could be. MATLAB uses double precision so about 16 digits. It seems reasonable to me that for some problems a loss of nine digits of precision could cause serious errors and for errors to propagate.
Ben Petschel
2013-11-6
fpeek = @(x)peek(myfun(x,...),x);
and then run the genetic algorithm with fpeek as the objective function, then extract the points and function values with
[fval,xval] = peek()
If the function is deterministic then you should have fval{i} equal to myfun(xval{i}).
If myfun just involves simple arithmetic operations then you should check whether catastrophic cancellation is occurring by subtracting two nearly equal values. Try to algebraically simplify the expressions where possible to avoid subtraction, or replace expressions such as exp(x)-1 with expm1(x).
类别
在 帮助中心 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!