# Genetic Algorithm fitness function for failing parameters

1 visualización (últimos 30 días)
Ben Holmes el 22 de En. de 2016
Comentada: jgg el 22 de En. de 2016
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.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuesta aceptada

jgg el 22 de En. de 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 comentariosMostrar NingunoOcultar Ninguno
Ben Holmes el 22 de En. de 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 el 22 de En. de 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.

Iniciar sesión para comentar.

### Categorías

Más información sobre Genetic Algorithm en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by