0

Here is a very small example I'll give:

Suppose I have my population of size 4. Now, let's say that I sort them based on their fitness and I decide to drop the last 2 (so now my population size is 2). Now I would need to go back to the original size but first I would have to create offspring.

Let's say I have this: (not written in any specific language)

population = [[2.2],[49.7],[34.1],[25.39]] //original population, I would run this under a fitness function
sortedPopulation = [[49.7],[25.39],[2.2],[34.1]] //sorted population based upon their fitness
best = [[49.7],[25.39]] //updated population with the last 2 elements being dropped (because they are the 2 worst)

At this point, I'm trying to figure out how I can crossover and create offspring. After the offspring, I will generate some more Doubles to get back to the original population size (which I already know how to do). What are some ways to crossover? And what would the result of the crossover actually look like?

I also want to make sure that there is a method that will work for any # of elements in the population's elements. For instance, if each of the elements were 2 double's, then how would I create offspring from something like this:

best = [[3.3,92.56],[10.5,15.01]]

1 Answers1

0

if you are working with integers its good idea to work with them as binary... then you can for example swap last 2 bits as crossover, swap every second bit, etc... or even better as Gray code (https://en.wikipedia.org/wiki/Gray_code) or you might get stuck on Hamming's barrier (https://en.wikipedia.org/wiki/Hamming_distance)

hope it helps ^^ Patrik

  • Sorry, I actually am working with doubles but I posed my question with Int's. I fixed it now, I see most GA examples working with bits but I do not see many examples where they work with doubles which is part of why I am asking. – Greg Mowers Oct 24 '20 at 23:33
  • then why not both numbers represent as binary? – Patrik Kula Oct 24 '20 at 23:41
  • I'm trying to create a GA that is dealing with math. Ex: Calculating a max/min value of a function. – Greg Mowers Oct 24 '20 at 23:45
  • 1
    @GregMowers Consider calculating the min/max of a function, using a population of X values. Given parents X1 and X2, a possible crossover function is to randomly choose any value between X1 and X2. That will work like a binary search as long as there are two individuals that have good fitness, and straddle the correct X. To make the crossover more robust, you could widen the range of offspring. For example, if X2-X1=D, then you could choose a value between X1-D and X2+D. That way, if the parents are near, but don't straddle the correct X, the offspring can still move towards it. – user3386109 Oct 25 '20 at 00:47
  • So what would my updated population look like? Would it be [[parent1],[parent2],[offspring]]? I'm confused on what the result of crossover would actually look. – Greg Mowers Oct 25 '20 at 00:56
  • @GregMowers Yup, the confusion is due to the fact that a population of 4 is way too small. If you had a population of 400, and you kept 100 parents, then there would be [100C2 = 4950 possible pairs](https://en.wikipedia.org/wiki/Binomial_coefficient). Choosing 400 of those pairs, you can produce a new generation of 400 offspring. Or you could keep the 100 parents, and produce 300 offspring to bring the population back to 400. – user3386109 Oct 25 '20 at 01:05
  • But I'm assuming there is plenty of freedom within this right? For example, you say if you have pop. of 400 and you get rid of 300. Could I simply create 200 offspring and then add another 100 parents? – Greg Mowers Oct 25 '20 at 01:10
  • @GregMowers Yes, there's lots of freedom here. You can take some of the existing population, and apply a random mutation to them to mix things up. You can also just sprinkle in some freshly minted individuals. But note that freshly minted individuals are unlikely to be able to compete with individuals who have evolved over several generations. – user3386109 Oct 25 '20 at 01:18