0

I am encoding the interval [x:y] to binary codes like 10101111, so for population, it is like [[1,0,1,1],[0,1,0,1]].

I defined the fitness function directly using the value of the function (sin(x)^2).

For selection, i am using tournament selection and for crossover, only simple exchange part of the chromosome like this: 1(10)0 and 0(01)1 -> 1(01)0 and 0(10)1.

For mutation, using Bit inversion.

The algorithm kind of works, it can generate the global minimum sometimes, and sometimes local ones. but I don't see the function of crossover in this problem, because the feature of the 'x' is being broken every time (i think), I don't know why, and if it is even right way to code the crossover or maybe the encoding part.

manlio
  • 18,345
  • 14
  • 76
  • 126
YoarkYANG
  • 303
  • 2
  • 18
  • at least some comments please. – YoarkYANG Dec 15 '15 at 09:07
  • 1
    Note that with binary encoding, crossover (as well as single bit inversion for mutation) can result in sometimes too large changes in the chromosomes. In such a scenario, you might want to switch to another encoding, say, Grey Encoding. In binary encoding, a bitswap "1 0 0 0" to "0 0 0 0" is quite a significant change, whereas in grey encoding, the difference in these two bit strings is not as large. See https://en.wikipedia.org/wiki/Gray_code – dfrib Dec 15 '15 at 15:56

1 Answers1

2

I'm afraid that there isn't a "right way" to crossover.

There are many crossover operator (e.g. Comparison of a Crossover Operator in Binary-coded Genetic Algorithms - STJEPAN PICEK, MARIN GOLUB) that can be used in binary coded genetic algorithm, but:

  • depending on the properties of a problem one or another crossover operator will have better result.
  • every crossover operator has its advantages and downfalls, so choosing one ultimately represents the question of someone's requirements and experiments undergone.
  • in many situations uniform and two-point crossover are good choices.

Crossover is the major exploratory mechanism of the genetic algorithm, but the driving force behind GA is the cooperation between selection, crossover and mutation (mutation prevents convergence of the population and introduces variation).

Usually a mutation-only approach doesn't have enough exploration strength to reach to the minimum and the success is largely due to distribution of solutions in the initial population.

For continuous function optimization you should also check differential evolution.

manlio
  • 18,345
  • 14
  • 76
  • 126