Genetic Algorithm and Local Optimization Options

Hi Everybody,
I have an issue with optimization procedure. I got a function which requires the optimization of 19 free variables to fit a wide range of experimental data. As it is, I am running first a global optimization based on the genetic algorithm application to avoid local minima, followed by a local optimization of such nvars (and using the output of the g.a. as initial guess of my fmincon local optimization).
I would like to check the evolution of my 19 variables within the optimization, separately one from the other. As it is built in MatLab I can only acces the final value of my Objective Function on a plot, but non for specific nvar. I could somehow do this with previous Matlab requests/answers, but as it is these methods created 1 excel file every iteration for every variable. In my case this means 19variables*(>)10000iteration=non feasible solution.
Can you please help me solve this problem?
Thank you very much

 Accepted Answer

I'm not sure exactly what would satisfy you. Do you want 19 plot functions to run, one for each variable? Or maybe you'd like 19 text files of values? Whatever you want, you can get it using a custom plot function or custom output function for the ga portion of your procedure. For the fmincon portion, you'll need custom plot or output functions in a different syntax.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

5 Comments

Hi,
yes, I would like to get either 19 functions to plot my 19 indipendent variables, or else a txt file in which I record my 19 variables over the optimization procedure and check how they indipendently evolve in my (most importantly) genetic algorithm. Unfortunatelly I have also tried with custom plots and I cannot access my 19 free variable
The example I linked of a custom output function shows how you can record the history to an array. Instead of a 3-D array recorded every 10th iteration, make a 2-D array recorded every single iteration. In the 'init' segment, set
history = state.Population;
In the 'iter' portion, set
history = [history;state.Population];
At the end you'll get a big matrix with 19 columns, representing your 19 variables. Export this matrix to a file.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Hi,
thank you again for the help. This is actually kind of working. I am finally able to save these variables.
But I would still have an issue, cause i am not too familiar with this coding formulation with the "persisten" option. As i have modified the code making it a 2D, the problem that i see is that I am not actually saving my 19 variables at every iteration, but what I get is an array being size (Iteration*PopulationSize)-by-nvars. So if I set PopSize=200, and I stop after 10 iterations, I would get an array of 2000-by-19 which is not exactly what I am looking for.
I understand that my population at every generation lies in state.Population, and it is what I then recall to history. So the thing would be to save the "best" set of data of my population at every iteration, so to have an output array corresponding to Iterations-by-nvars.
Thank you again for your feedback and help
regards.
Marco
Oh, you just want the best member of the population at each iteration, not the entire population at each iteration? Then I think that you need to choose the row in the population matrix that has largest score. Something like
[~,thebest] = max(state.Score);
thepop = state.Population(thebest,:);
history = [history;thepop];
If I have it wrong (because I am typing fast) then use min instead of max.
Alan Weiss
MATLAB mathematical toolbox documentation
Thank you a lot!
It is now working perfectly!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!