Genetic Algorithm - Relation between Population and Fitness Function

When using a Custom Population Function and specifically Custom Binary Population. How does the population relate to the Fitness Function?
I have both coded out but and have somewhat knowledge but lack the critical understanding of how they work together. Should my fitness function have a input variable which takes in the population and computes the fitness of the individuals?
I have not found and detailed reading material on this relation. Are there any such reading materials available on these relations or could anyone explain them please.
Thanks.

 Respuesta aceptada

Alan Weiss
Alan Weiss el 27 de En. de 2014
Editada: Alan Weiss el 27 de En. de 2014
As described in the documentation, the creation function creates a population, and the fitness function evaluates how good each member of the population is. There is a specific syntax for the creation function, and there is a syntax for the fitness function. There is more information about fitness functions here.
For the creation function, the syntax is
function population = creationfcn(nvars,fitnessfcn,options)
GA passes the arguments nvars, fitnessfcn, and options to your creation function. What you do with those arguments is up to you. You will certainly need the nvars argument so that your population has the right number of elements, but you can use the other two arguments or ignore them as you see fit.
I hope this helps.
Alan Weiss MATLAB mathematical toolbox documentation

12 comentarios

Hello Alan. thanks for your reply. it is informational and i had gone through all but 1 of the above links prior to starting my work.
Also, i am sorry i have to re-phrase the question a little as i created a custom CHROMOSOME FUNCTION (not a custom population) where i compute the required chromosome length and applied some constraints to it and formed out a desired chromosome in binary population.
The thing i am lost in is the formulated chromosome to be evaluated by the fitness function? if so then what has the population has to do with all these?
When all these happens should i let GA evaluate the fitness scores of a bad gene / chromosome or if i were to constrain the chromosome to be perfect by restricting everything so that the chromosome generated always has a good fitness score would it still be advisable?
Thanks for your time and advise!
I am sorry, I do not understand you. I do not know what a chromosome function is, or is supposed to be.
It is somewhat unfortunate that MATLAB solvers force you to put your problem into the syntax they expect, instead of one that seems natural to you. But if you want to use our solvers, you have to somehow use our syntax.
So, if you want to use GA, I suggest that you try to reformulate your problem our way. Write a fitness function that either takes a single individual and computes its fitness, or takes an entire population and returns a vector of the fitness of all the individuals. Separate your constraints into bounds, linear constraints, and nonlinear constraints, and put those into the expected places in the GA syntax.
I hope you understand what I am suggesting. Yes, it can seem unnatural to go through all these extra steps, and possibly to take your "chromosome function" apart and distribute its functionality across a bunch of different things (ftness function, constraints, maybe population creation too). But I believe that is what you need to do.
Of course, it is possible that I misunderstand you entirely. If so, I apologize.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Hi Alan. no worries! thanks for your reply either way!
I understand what you are proposing. i might have a workaround but need to do some tinkering..... Can i check this with you then,
I understand GA Flows through this process..
1. Initialize the population.
2. Calculate fitness for each individual in the population.
3. Reproduce selected individuals to form a new population.
4. Perform crossover and mutation on the population.
5. Loop to step 2 until some condition is met.
Say now i have a random population and @ Step 2, say i feed in a constraint matrix and do some cross checking with the currently generated random number. If the current value exceeds the current constraint i would award it a bad fitness score and if it does not exceed the current limit then i do nothing to it. So the big question will be is there a manual way i can play with the fitness score assigning?
Thanks for your advise!
Again, I suggest that you use our tools the way they are designed. If you have a nonlinear constraint function that you want to use as a penalty, well, just write it as a nonlinear constraint function in the correct syntax. You can tune the penalty function using options.
That said, you are free to use a custom fitness scaling function if you like. If you look through the available options for GA, I think you will find that you have a lot of control over the algorithm.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Thank you alan!
HI Alan! I really have to thank you very much for entertaining my queries all this while... they have been extremely helpful and has steepened my learning curve!
I have successfully completed my problem formulation and have managed to Optimize using GA. I do have 1 more query though to which i would hope to get some advice from you on..
I am currently running GA in which my Population is a Double Vector as i had issues with my creation function. But, i am not getting an ideal result since the values are purely stochastic... i can control them to a certain extent with the use of Upper & Lower Bounds but it is not sufficient.
I realize i will certainly obtain a better fitness if i use a custom population since i can supply further constraints within the custom data type to generate an ideal pseudo random integer.
I currently have my Creation Function written out but not sure how i am to pass it through GA yet. Could you kindly explain please. Specifically on the Syntax you had supplied in your answer.
Currently I have
function result = cust_pop()
The variable 'result' will hold a value of 1x100 where 100 is my nVars also. My current implementation is not following your guide as above. Please advise on what i need to change to make it work.
Thanks!
If you want to have some components of your population be integer-valued, then by far the easiest thing to do is to use the automatic ga mixed integer optimization.
But if you really insist on using your own custom creation function, then you can try to follow this recommendation. You need to follow the syntax for custom creation functions carefully. There is some explanation here (I might have already pointed you to this). And I already pointed you to our example of custom data type in ga.
I am sorry if this didn't address your question.
Alan Weiss
MATLAB mathematical toolbox documentation
Sam
Sam el 20 de Feb. de 2014
Editada: Sam el 20 de Feb. de 2014
wow.. the biggest mistakes are all the small small things... i was not sending in arguments but computed them within the population since i am running a very specific task.. but I am able to use my custom population now! thanks for your reference materials!!!
I had went through the IntCon segment but i need all my optimized values to be an Integer, and my reason for not using it is as follows..
My population is unique in the sense the 100 values (aka 100 nVars) are split into 4 segments of 25 each. So the values of column 1 + 26 + 51 + 76 should not exceed a specific value and the same for columns 2 + 27 + 52 + 77 should not exceed a predetermined value and so on for the rest of the values.
Once optimized they cannot breach this constraint of all 4 segments being added together.
i have 1 more query but i guess it will be better if i post it as another question for the benefit of anyone else searching for that specific item.
Sam, you should look carefully at linear constraints. If you want, for example,
x(1) + x(26) + x(51) + x(76) <= 37
then you can write this as a linear inequality constraint. You really don't need a custom population. I am afraid that you are making a lot of extra work for yourself.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
OH WOW!
I had left this segment blank since my population takes care of this (some Sort).. thanks! i'm convinced... I will change my code to suit Matlab's conventional way of doing things..
Can i check how could i write this for my problem.. Should i follow what you had highlighted or what your link had highlighted?
I don't yet see how i am to feed your constraints within the GUI of gatool. I see how i can do it using your example given in your link but.....
if i have a matrix of 1x100 which i want to apply the constraint on, i will write it as you have specified and feed it in as a function file (similar to feeding in a non-linear constraint) or how should i feed this in?
Thanks!
Sam, I suggest that you try going through the introductory documentation on how to set up an optimization in Optimization Problem Setup. The link I gave to Linear Inequality Constraints should show you how to include these constraints. Here is an extensive example in the context of linear programming.
Basically, to make a linear inequality constraint
A*x <= b
you simply pass the A matrix and b vector in the solver. For ga,
x = ga(objective,numvariables,A,b,...)
Then ga will automatically ensure that the constraints are satisfied. Please do not use any custom creation, mutation, or crossover functions, or ga might not keep the linear inequalities.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
ohh sorry let me rephrase.. i am aware of this and have done this more than a few times now... i meant to ask how should the constraints be sent in since i need to write it in A & b format...
but after going through the documentation links for awhile now it is clearer i had confused myself by accident...
Thanks much!

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

Sam
el 26 de En. de 2014

Comentada:

Sam
el 21 de Feb. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by