The genetic algorithm is not returning the minimum of my function?

I am attempting to optimize the locations of transducers in a set-up by maximizing the sensitivity within the imaging volume. The function I am feeding to the GA takes the x and y coordinates of the transducer and returns 1/(sensitivity+1) to maximize the sensitivity and avoid dividing by zero. The sensitivity is always a positive number and I have restricted the variables to integers.
In an imaging volume of 5x5x5, optimizing the 5th (top) z plane, we would assume that the best place to put the transducer is the middle [3,3,0] (I have restricted the z position of the transducer to 0 for now), however, the GA returns [0,3,0]. I have run this several times with different population sizes and initial populations and it consistently returns [0,3,0]. When I manually calculate the result of the function that the GA is working with, I get a higher value for [0,3,0] than [3,3,0]. My understanding is that the GA should be finding the minimum of my function and there are many more positions that return a lower value than [0,3,0] because they are closer to the centre of the imaging space (such as [1,3,0] [2,3,0]).
Is there any reason that the GA would be unable to return the minimum of my function?

9 Kommentare

Matt J
Matt J am 31 Okt. 2012
Bearbeitet: Matt J am 31 Okt. 2012
What happens when you choose an initial population concentrated near the center of the imaging space? If you know this is where the solution is likely to lie, that's what you would do. What happens when [3,3,0] is included in the initial population?
Is there a particular reason you chose the cost function like that? What would happen if you used -sensitivity instead, or -log(sensitivity) or so? I'm asking, because the selection stage in a GA can be somewhat sensitive to how you chose your cost function, and it interacts with the way you assign fitness to individuals etc.
But first do what Matt suggested, add the optimum to your initial population, and if that is available to you, enable Elitism in your GA. If it again comes up with the wrong solution, then there is a deeper issue.
Thank you both for your suggestions.
I have tried assigning the initial population to [3,3,0] and it still gives me a result of [0,3,0]. I also just tried changing the cost function to -sensitivity and -log(sensitivity) and although -sensitivity also returned [0,3,0], using -log(sensitivity) gave [3,3,0]! I honestly don't understand why this would work when other methods did not but thank you for the suggestion!
If [3,3,0] is in your initial population, [3,3,0] is the optimum, and you have elitism enabled, then it is impossible that your GA would return anything but [3,3,0], no matter which form of the cost function you are using. So there must be something wrong with the cost function evaluation.
I assume you pass the cost function to your GA as a function handle, like
cost = @(individual) code...
What happens if you call that exact function with [3,3,0] and [0,3,0]?
cost([3,3,0])
Another thought: For the GA, you probably have to represent [3,3,0] etc as a bit string. How do you do that? Maybe there's a mix-up in how you go from the vector to a binary representation?
What is the difference between the two cost levels
cost([0 3 0]) - cost([3,3,0])
I'm currently using the optimization toolbox GUI so there shouldn't be a problem with how I'm passing the function or variables to the GA. However, I don't have elitism enabled as I am unsure how to do that with the GUI.
The difference between the two cost levels when I had 1/sensitivity was 0.0109, now with it set as -log(sensitivity) the difference is still 0.0109 (between the [0,3,0] and [3,3,0] points at least).
That is a very odd coincidence... Are you sure you are comparing cost and not fitness? (fitness is a transformed version of cost, in the right column of the optimtool you can select what kind of scaling is applied)
Elitism can also be enabled in the middle column, "Elite Count" under "Selection." However, it is at 2 by default, at least in my version, so it should have been on all along and I am at a loss.
I'm comparing cost, I manually calculated with Matlab using [0,3,0] and [3,3,0] as inputs through my function to get those values.
Should I try setting the Elite Count to another value?
Yeah, try and set the EliteCount manually. I don't expect it to change anything, but might as well try. Apart from that I don't think we have enough info to find what's wrong. All I know is this: Elitism means that the best individuals in Population i are going to be in Population i+1, too, so that if the minimizer is in your initial population already, there should be no way that you get any other result.
So the error must happen somewhere else, the objective as the GA evaluates it must be different from the objective if you manually call it from Matlab.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Gefragt:

am 31 Okt. 2012

Community Treasure Hunt

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

Start Hunting!

Translated by