Genetic Algorithm fitness function for failing parameters

1 view (last 30 days)
I'm attempting to analyse a strongly nonlinear system using GA. The fitness function evaluates a time-domain comparison between the modelled (estimated) and measured data, and sums the squared error across the duration of the signal. The model that runs uses an optimised/robust variation of Newton's method to solve the nonlinear behaviour, but some of the parameter settings can cause non-convergence, resulting in an Inf value being returned by the fitness function.
Ideally I would like to be able to discard this set of parameters and generate a new set (possibly repeatedly) that yields a working model, but I don't know how to change the population from the fitness function. The parameter set is not necessarily a bad set, just the combination of parameters yields a non-functioning model, and when this happens the parameters are seen as unfit, which is not necessarily true. The parameters are all bound to realistic regions.

Accepted Answer

jgg
jgg on 22 Jan 2016
I think you probably want an output function.
Basically, you can create a function which is called after every iteration of the solver, and can do things to the population. Create a function like:
function [state,options,optchanged] = ga_output_function(options,state,flag)
if strcmp(flag,'iter') %if ga is in iteration
p = state.Population;
s = state.Score;
%test and change things
else
%something else
end
end
The state object is explained in the link, but it's basically a structure with all the components of the GA optimizer at the current iteration. So, in your problem you could have it check if you've reached one of those bad parameter values then change the population so that it's excluded (however you choose to do this), passing back the new state with the new population.
Then, create an option structure like:
options = gaoptimset('OutputFcns',@ga_output_function);
and pass it to your GA solver.
You'll have to play around with this a little bit to get it to work in your situation, but I think this solves your basic problem ("I want to change the population of the GA solver when something happens").
  2 Comments
Ben Holmes
Ben Holmes on 22 Jan 2016
I think you're right! Do you know the order in which this is all called? Hopefully something like:
Evaluate Current Generation -> Output Function -> Generate Next Generation
jgg
jgg on 22 Jan 2016
I'm pretty sure that's how it works. You can confirm this by doing some testing though (get it to save the population at each stage before changing it); I'm not 100% sure.

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!