Genetic Algorithm - Order of variables in a chromosome - genetic-algorithm

Using the concept of crossover points, the order of variables in a chromosome does seem to matter: Variables directly next to each other will have a higher chance to remain together in the children's chromosomes compared to variables far away from each other. What does this mean for my gene encoding? How should I order variables?

You can improve a crossover little. You may shuffle parents, and than make crossover. You must applied on child an inversion process to shuffling. With this procedure, the genes far from each other may be together in child and genes next to each other do not have lay next to each other in child.

Related

How does Genetic Algorithm Crossover work when my output contains only 2 states?

I'm currently working on a project where I am using a basic Cellular Automata and a Genetic Algorithm to create dungeon-like maps. Currently, I'm having an incredibly hard time understanding how exactly crossover works when my output can only be two states: DEAD or ALIVE (1 or 0).
I understand crossover conceptually - you find two fit members of the population and they exchange genetic material, hopefully producing a fitter offspring. I also understand this is usually done by performing k-point crossover on bit strings (but can also be done with real numbers).
However, even if I encode my Dead/Alive cells into bits and cross them over... What do I end up with? The cell can ONLY be Dead or Alive. Crossover will give me some random value that is outside this range, right? And even if I were to work on floating point numbers, wouldn't I just end up with a 1 or 0 anyway? In that case, it seems like it would be better to just randomly mutate Dead cells into Alive cells, or vice versa.
I've read several papers on the topic but none seem to explain this particular issue (in language I can understand, anyway). Intuitively, I thought maybe I can perform crossover on NEIGHBOURHOODS of cells - so I find 2 fit neighbourhoods, and then they exchange members (Neighbourhood A gives 4 of it's neighbours to Neighbourhood B for example). However, I have not seen this idea anywhere, which leads me to believe it must be fundamentally wrong.
Any help would be greatly appreciated, I'm really stuck on this one.
A lover of dungeon games and Genetic programming here :)
I think you misunderstood the concept of crossover. On your Cellular Automata, you must have genetic information (chromosomes) in such a way your system decides if the matching cell is Dead or Alive. The state of the cell is the output of your system.
You perform the crossover genetic operator between two-parent chromosomes by mixing their genetic information. As a result, you obtain a new chromosome that encodes the map in a way similar to both parents. The new state of your cells is obtained by running the new chromosome to re-map your scenery.
The crossover gets you a new chromosome to map your dungeon, it does not give you new states for the cells. To get the new states, just run your new chromosome.
The state of your cells would be the phenotype, the way your chromosome is manifested. Your chromosome is the model that decides if your cell is dead or alive. I am not concerned about the model you are using. For instance, you are using a Neural Network with two input nodes. One input node receives the X coordinate of the cell in the grid, and the other node receives the Y coordinate. The output node is a binary value: DEAD or ALIVE. This Neural Network has a certain number of hidden layers and weights that are encoded in your chromosome. By performing the crossover operator you create a new way to connect the neurons, which is in between both parents. But in order to know the new state of each cell, you need to pass the coordinates again to the Neural Network. Maybe checking NEAT algorithm by Stanley clarifies the crossover process: http://nn.cs.utexas.edu/downloads/papers/stanley.ec02.pdf
In case you do not have any model that encodes the state of each cell in the map, your genetic information is directly the state of each cell. In this situation, you could split your parent grids into smaller ones, 10x10 grids for instance. Then run through the map in tiles of 10x10 and choose randomly if you pick the matching tile from parent1 or parent2.
I hope this helps!
Alberto

Grammatical Evolution (GE)

In the Grammatical Evolution (GE) algorithm (here the web: grammatical-evolution.org) there is the option to make the length of the individuals self-adaptive. I would like to know:
What is the most common strategy used when the individual's length is self-adaptive. In other words, how does the the length of the individual evolve.
Does it increase and decrease the size or just increase.
Is there any well documented or illustrative example.
Thanks in advance.
In GE, the individuals are necessary variable-length in order to be able to encode programs (structures) of variable length.
Initialization
The initial population already consists of individuals of varying size. The initialization procedures may vary, but the one I'm familiar the most uses the grammar to create the individuals. You basically do the same thing as when you want to decode the individual into the program (using the grammar) but instead of choosing the grammar expansions using the individual, you do it the other way around - you choose the expansions randomly and record these random decisions. When the expansion is finished, your recorded decisions form an individual.
Crossover
The crossover operator in GE already modifies length of the indiviuals. It's a classical single-point crossover, but the crossover points are chosen completely randomly in both parents (in contrast to the classical single-point crossover from GAs where the parents are of the same length and the crossover point is aligned). This mechanism is capable of both growing and shrinking of the individuals.
Example on crossover: suppose you have two individuals and you have randomly chosen the crossover points
parent 1: XXXXXXXXXXXX|XXXX
parent 2: YYY|YYYYYYYYYYYYYYYYYYYYYY
After crossover, the children look like this
parent 1: XXXXXXXXXXXX|YYYYYYYYYYYYYYYYYYYYYY
parent 2: YYY|XXXX
As you can see, the length of the individuals was changed dramatically.
Pruning
However, there is a second mechanism that is used for length reduction only. It is the pruning operator. This operator, when invoked (with a probability, in the same way e.g. the mutation is invoked), deletes the non-active part (i.e. if the grammar expansion finished before all codons were used, the remaining part is the non-active part) of the genotype.

Crossmode in different length genes

I have two genes with different sizes and I want to produce offspring from them. The position of the chromosome doesn't make difference in the gene.
I want to know what is common to do in this situation
Gene1:
123456789
Gene2:
ABCDEFGHIJKL
I can use a single cross point in each
12345.6789
ABCD.EFGHIJKL
And with this I have 8 possible combinations
1. 12345ABCD
2. 12345EFGHIJKL
3. 6789ABCD
4. 6789EFGHIJKL
5. ABCD12345
6. ABCD6789
7. EFGHIJKL12345
8. EFGHIJKL6789
Is it okay to create all the 8 offsprings, or should I just make 1, if so, do I need to randomize the method or just pick one and stick with it?
Genetic algorithms are mocking biological processes where chromosomes crossover at one point and exchange their parts after the crossover point if we are talking about single point crossover.
As you can see in picture above parents exchange "tail" parts of the chromosome after the crossover point. Therefore you have only 2 offspring/children produced by crossover. That's how crossover occurs in nature, how biologists describe it.
If you refer to any literature dealing with topic of Genetic Algorithms they also state this convention that when using single point crossover parent chromosomes are split into head and tail denoted as H/T like that (see citation below):
H T
123456.789
H T
ABCDEF.GHI
Therefore offspring produced with this crossover will be:
123456GHI
ABCDEF789
Following this convention is much better than creating all possible combinations and then selecting random or fittest of the offspring as it is computationally more efficient. If you want to solve more complex problems you just simply increase size of the population to allow more diversity.
"Single point crossover: A single random cut is made, producing two head sections and two tail sections. The two tail sections are then swapped to produce
two new individuals (chromosomes)".
Genetic Algorithms and Genetic Programming:
Affenzeller, Michael
Wagner, Stefan
Winkler, Stephan,
ISBN: 1584886293
Alternatively you can use multipoint crossover which follows similar convention where chromosomes are split into sections and parents exchange parts in a way that offspring chromosome is just alternation of parents chromosomes so if you have parents with chromosomes:
A1.A2.A3.A4
B1.B2.B3.B4
|
| this will produce offspring
|
A1 B2 A3 B4
and
B1 A2 B3 A4
This answer might help you as well:
Crossover of chromosomes with different length
It seams you use Gene instead of Chromosome and vice versa.
In this case and if different size of chromosome is okay, you can create all 8 offspring. But your population increases in each iteration and you should control this. For example keep 2 of the best offspring or 2 random offspring and replace their parents by.

What is the correct way to execute selection procedure in a genetic algorithm?

I am working on a genetic algorithm for symmetric TSP in VB.NET. I want to know what is the correct way go execute selection procedure. There seems to be at least two different possibilities:
1)
-create a "reproduction pool" of size R by using SELECTION(pop) function
-do offspring creation cycle
-randomly (uniformly) select two parents from that pool for each offspring
that needs to be created in each iteration
2)
-do offspring creation cycle
-use modified SELECTION(pop) function that will return two different parents from pop
-perform crossover to produce a child
Bonus question: After selecting two parents it is possible to produce two different offsprings (if the crossover operator is mot commutative): CROSS(p1, p2) and CROSS(p2, p1).
Should I insert both offsprings immediately or produce them one by one ? Will this make a difference?
Currently I am producing them one by one because I think it will give more variance in the population.
In genetic algorithms you don't use a separate reproduction pool, but sample from the population (|N| until you have 2*|N| parents out of which you create |N| children). If your reproduction pool R is of size 2*|N| and you sample randomly out of that pool it's essentially the same behavior, but you need more random numbers and it's more expensive to compute (depending on your RNG). Note, that there is no need to care about getting two different parents. A parent mated by itself will produce a child that is the same as the parent (if the crossover is idempotent). It's similar to using crossover probability. Also the check if two parents are different may be quite expensive if you compare them structurally. You could also compare them by fitness, but often you can have very different solutions of the same quality.
Regarding your second question: I would say that it doesn't matter much. I would choose to return only one child for simplicity reasons: A method that takes two solutions and returns one solution is easier to deal with than one that returns an array of solutions. I would say that returning both is only interesting in those cases where you can create two distinct solutions. This is the case of binary or real-valued encoding. With permutations however you cannot guarantee this property and some genetic information will be lost in the crossover anyway.
It depends on the codification.
You can consider the two fittest individuals of the current population.
Or you can use roulette whell selection (Google it) to associate each individual with a reproduction rate, this is the usual way.

Choosing parents to crossover in genetic algorithms?

First of all, this is a part of a homework.
I am trying to implement a genetic algorithm. I am confused about selecting parents to crossover.
In my notes (obviously something is wrong) this is what is done as example;
Pc (possibility of crossover) * population size = estimated chromosome count to crossover (if not even, round to one of closest even)
Choose a random number in range [0,1] for every chromosome and if this number is smaller then Pc, choose this chromosome for a crossover pair.
But when second step applied, chosen chromosome count is equals to result found in first step. Which is not always guaranteed because of randomness.
So this does not make any sense. I searched for selecting parents for crossover but all i found is crossover techniques (one-point, cut and slice etc.) and how to crossover between chosen parents (i do not have a problem with these). I just don't know which chromosomesi should choose for crossover. Any suggestions or simple example?
You can implement it like this:
For every new child you decide if it will result from crossover by random probability. If yes, then you select two parents, eg. through roulette wheel selection or tournament selection. The two parents make a child, then you mutate it with mutation probability and add it to the next generation. If no, then you select only one "parent" clone it, mutate it with probability and add it to the next population.
Some other observations I noted and that I like to comment. I often read the word "chromosomes" when it should be individual. You hardly ever select chromosomes, but full individuals. A chromosome is just one part of a solution. That may be nitpicking, but a solution is not a chromosome. A solution is an individual that consists of several chromosomes which consist of genes which show their expression in the form of alleles. Often an individual has only one chromosome, but it's still not okay to mix terms.
Also I noted that you tagged genetic programming which is basically only a special type of a genetic algorithm. In GP you consider trees as a chromosome which can represent mathematical formulas or computer programs. Your question does not seem to be about GP though.
This is very late answer, but hoping it will help someone in the future. Even if two chromosomes are not paired (and produced children), they goes to the next generation (without crossover) but after some mutation (subject to probability again). And on the other hand, if two chromosomes paired, then they produce two children (replacing the original two parents) for the next generation. So, that's why the no of chromosomes remain same in two generations.

Resources