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.
Related
The genetic algorithm which has
'parent1 1111|0101
parent2 0000|1010
offspring 11110000'
comes under which kind of crossover genetic algorithm?
Thanks in advance.
It could be a lot of different ones, you have to specify more examples. To me it looks like a varation of a single point crossover. In the first 4 bits, the bits of parent1 are taken.
In the next 4 bits, we have either of the following (logical) options:
AND (the offspring will only have a 1 if both parents have 1)
UNIFORM (the offspring takes a bit randomly from their parents, so it took 4 0's randomly)
But it is hard to say. The first part could also have been UNIFORM for example You need to specify more test cases for us to accurately given an answer.
i am trying to select 3 feature from a data set of 24*461. my problem is in generation part. after cross-over, new chromosome can have more than three 1 and therefore more than three variable. in mutation step, when a zero is changed to one, number of selected feature is more than 3. Any help will be greatly appreciated
A common technique to solve this problem is to impose a "penalty", wherein, any chromosome that have more than three 1 have a penalty added. For example if a chromosome have five 1, add 2x to chromosome fitness score. In this case any chromosome that have more than three 1, gradually Remove from population and permitting other (that have three or less 1) individuals to be maintained in the population.
I'm writing genetic program, but it's been a while so I'm a little rusty.
If I start with a population size of 100 individuals, and select 50 through tournament selection for reproduction, and after crossover each pair produces 50 next-generation individuals, I'm left with 100 1st-gen individuals (which will no longer reproduce, no longer part of the "population") and 50 current-gen individuals. So my tournament selection of 50 won't really work. Should the tournament selected individuals also go on to the next generation? Or should they reproduce 2:1 somehow?
Thanks for the refresher!
There are many ways to perform selection and crossover in a Genetic Algorithm but generally, if you're using tournament selection you're best to select as many individuals as your population and have them produce the same number of offspring.
There are a number of ways to produce the same number of offspring as parents but, as an example, if performing a straight forward one point crossover each half of the initial parent would carry forward with the other half of the other parent. That way two parents produce two offspring. For example
Parent 1: 00000000
Parent 2: 11111111
With a crossover point after the third bit.
Offspring 1: 00011111
Offspring 2: 11100000
Afterwards you can discard your entire initial population and replace them with all the offspring.
Note: This doesn't take into account any specialised operator you may want to include which can help to carry the best individuals forward every population. But that's another story....
Im just learning about genetic algorithm when i was given a task to design a genetic algorithm that learns rules that predicts if a person will vote yes or no given a data set.
I've been reading in book and internet about GA and GP for 2 days straight. So now i kind of understand the concept of GA about the population management, genetic operators, fitness functions and crossover with the different types of crossover masks. But i'm still nowhere near making my own GA for a given data set. I just don't get how to start or with what and i'm kind of getting desperate since i get a feeling i'm to stupid for this.
So any kind of help, such as hints, tips or pseudo code, will be much appreciated!
The given data set is as follows (groups):
G1 | G2 | G3 | G4
A1 | B1 | C1 | None
A2 | B2 | C2 | D2
A3 | B3 | C3 | D3
A4 | B4 | C4 | D4
A5 | - | - | D5
Well the data are not a,b,c's. They are something else much longer, but i'm kind of lazy so yea :P The - means there is no more attributes. Note that none is an attribute.
Thanks for any sort of help guys!
First, and foremost, you'll have to determine what you're trying to solve with your data set in the first place. You generally use a genetic algorithm to tackle non-deterministic problems: problems that take a long time to solve, but whose answers are easily verifiable.
So the first question is: what does your dataset represent?
The second question: what are you trying to solve and is a genetic algorithm a fitting method to solve your problem?
Anyway, creating a genetic algorithm is done through the following steps:
Represent the problem variable domain as a chromosome of a fixed length, choose the size of the population N, the crossover probability p(c) and the mutation probability p(m)
Define a fitness function f(x) to measure the performance, or fitness, of an individual chromosome in the problem domain. The fitness function establishes the basis for selecting chromosomes that will be mated during reproduction
Randomly generate an initial population of chromosomes of size N: x1, x2, ..., xn
Calculate the fitness of each individual chromosome: f(x1), f(x2), ..., f(xn)
Select a pair of chromosomes for mating from the current population. Parent chromosomes are selected with a probability related to their fitness. Highly fit chromosomes have a higher probability of being selected for mating than less fit chromosomes.
Create a pair of offspring chromosomes by applying the genetic operators - crossover and mutation
Place the created offspring chromosomes in the new population
Repeat step 5 until the size of the new chromosome population become equal to the size of the initial population N
Replace the initial (parent) chromosome population with the new (offspring) population
Go to step 4 and repeat the process until the termination criterion is satisfied.
So, you have to find a notation for your solution (such as an array of bits or a string) that allows you to swap parts of chromosomes easily. Then you have to identify the crossover and mutation operations.
If you're dealing with ordered chromosomes, then depending on the applied crossover strategy you may have to repair your chromosomes afterwards. An ordered chromosome is a chromosome where the order or the genes matter. If you preform a standard crossover on two solution that represent the cities that the travelling salesman has to visit, you might end up with a chromosome where he visits some cities twice or more and some not at all!
There's no clear description on how to translate each problem in a genetic algorithm, because it's different for each problem. The above steps don't change, but you may need to introduce several different crossover and mutation operations to prevent premature convergence.
Well, I do not fully understand the description of the dataset, so my answer is based on the following assumptions:
We have a set of attributes, say n different one. Each attributes have a set of different possible symbolic (=non numeric) values, say m(i) different possibilities. Each person have the same attributes, but some of them might be missing or None.
If these assumptions are correct and the set of attributes and possible values are not too high, then one of these might work:
if these two sets are really small you could have an n dimensional array as an individual/genotype. Each dimension would have the size m(i) and each value of this structure would be the yes/no answer. It would be the generalization (=more dimensions) of a fixed size (bit) vector. How to create random/mutate/crossover should be easy. Fitness would be how often it makes a good prediction.
if they are bigger then you will need something more complicated. One possibility is to have lists of rules. Each rule could be an vector with length n + a yes/no flag. In each position of the vector you would have a possible value of the related attribute. You could also have a jolly joker attribute accepting everything.
Interpretation of a rule (p:person, r:rule) : if p1=r1 and p2=r2 and ... pn=rn then the result is the flag of the rule.
You will have to evaluate rules until you find a matching one. You will also need a default.
Genetic operators are a bit more tricky in this case, but I think you will find something if you search for variable length encoding.
I've used a similar encoding (for a different problem) and it worked fine.
to make it more general (but also more complicated) you can represent your rules as trees where the internal nodes are and/or/not and possibly other logical operators, leafs are predicates like pi=ri. This would be a kind of genetic programming, google for that if you like this solution.
To be honest I'm not 100% sure if a genetic algorithm is the best choice for this problem, especially if the values are not symbolic, but numeric. It seems to be a pattern matching problem, and for that there are much better solutions. I would look for some alternatives, e.g. neural networks in the numeric case.
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.