How to access the intermediate calculation in genetic algorithm optimisation?
Ältere Kommentare anzeigen
Hi, I would like to use my own data instead of a function when using the genetic algorithm optimisation. In other words, instead of defining a mathematical function, I would like to enter for each generation the values for the fitness manually. I would like to plot how thi fitness is improving over the generation. I am also trying to see and plot the solutions that Aspen is testing for each generation. The reason for doing this is that I am doing experimental work with no known matematica model and the netic algorithm is guiding me to choose the right x solutions and the f(x) is the output of the experiment that I need to enter manually.
Antworten (1)
Alan Weiss
am 5 Jul. 2018
You can do this by writing a fitness function that prints the location x and waits for your input:
function y = myfun(x)
disp(x)
y = input('What is f(x)?')
HOWEVER, I think that you will find it much better to use patternsearch instead of ga. If you look at the comparison of several solvers, you see that patternsearch finds a minimum in many, many fewer function evaluations. And if, as in the example, you want to find a better minimum, then start patternsearch from initial random positions, as indicated in the documentation. And patternsearch is much easier to tune than ga, if you should decide to do so.
Alan Weiss
MATLAB mathematical toolbox documentation
3 Kommentare
Zied
am 5 Jul. 2018
Alan Weiss
am 6 Jul. 2018
Typically, x is a row vector (for ga, it can be any orientation for patternsearch). So you don't have three inputs, you just have one, a vector whose first part can be x1, the next part x2, the last part x3.
I don't understand what you mean when you ask if it will be run n times. MATLAB will ask you for function evaluations many times. Take a look at the examples in the documentation to get an idea of how many times. It may ask you for the same point more than once, so you might want to record the points and have them available, or use the patternsearch 'Cache' option, set to 'on', to avoid repeated evaluations of a point.
Yes, of course it is applicable to patternsearch. As to why ga is more popular than patternsearch, I don't know, but it is not a sensible thing, as patternsearch is usually much better in almost every respect.
Alan Weiss
MATLAB mathematical toolbox documentation
Kategorien
Mehr zu Genetic Algorithm finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!