35

I would like to have a simple explanation of the differences between genetic algorithms and genetic programming (without too much programming jargon). Examples would also be appreciated.

Apparently, in genetic programming, solutions are computer programs. On the other hand, genetic algorithms represent a solution as a string of numbers. Any other differences?

nbro
  • 15,395
  • 32
  • 113
  • 196
bjrnt
  • 2,552
  • 3
  • 27
  • 38
  • 1
    This answer should have been asked at [Artificial Intelligence Stack Exchange](https://ai.stackexchange.com/), but, unfortunately, it did not exist 10 years ago. – nbro Nov 27 '20 at 15:54

6 Answers6

48

Genetic algorithms (GA) are search algorithms that mimic the process of natural evolution, where each individual is a candidate solution: individuals are generally "raw data" (in whatever encoding format has been defined).

Genetic programming (GP) is considered a special case of GA, where each individual is a computer program (not just "raw data"). GP explore the algorithmic search space and evolve computer programs to perform a defined task.

nbro
  • 15,395
  • 32
  • 113
  • 196
JohnIdol
  • 48,899
  • 61
  • 158
  • 242
  • What do you exactly mean by "individuals are raw data"? What do you mean by "raw data"? How can individuals be "raw data"? Furthermore, what do you mean by "algorithmic search space"? – nbro Jul 04 '18 at 18:19
  • 1
    @nbro They are literally raw data. Without a program to execute them, they are just sequences of numbers or objects. Just like weights of a neural network. – ozgur Nov 06 '18 at 06:29
27

Genetic programming and genetic algorithms are very similar. They are both used to evolve the answer to a problem, by comparing the fitness of each candidate in a population of potential candidates over many generations.

Each generation, new candidates are found by randomly changing (mutation) or swapping parts (crossover) of other candidates. The least 'fit' candidates are removed from the population.

Structural differences

The main difference between them is the representation of the algorithm/program.

A genetic algorithm is represented as a list of actions and values, often a string. for example:

1+x*3-5*6

A parser has to be written for this encoding, to understand how to turn this into a function. The resulting function might look like this:

function(x) { return 1 * x * 3 - 5 * 6; }

The parser also needs to know how to deal with invalid states, because mutation and crossover operations don't care about the semantics of the algorithm, for example the following string could be produced: 1+/3-2*. An approach needs to be decided to deal with these invalid states.

A genetic program is represented as a tree structure of actions and values, usually a nested data structure. Here's the same example, illustrated as a tree:

      -
   /     \
  *       *
 / \     / \
1   *   5   6
   / \
  x   3

A parser also has to be written for this encoding, but genetic programming does not (usually) produce invalid states because mutation and crossover operations work within the structure of the tree.

Practical differences

Genetic algorithms

  • Inherently have a fixed length, meaning the resulting function has bounded complexity
  • Often produces invalid states, so these need to be handled non-destructively
  • Often rely on operator precedence (e.g. in our example multiplication happens before subtraction) which could be seen as a limitation

Genetic programs

  • Inherently have a variable length, meaning they are more flexible, but often grow in complexity
  • Rarely produces invalid states, these can usually be discarded
  • Use an explicit structure to avoid operator precedence entirely
peterjwest
  • 4,294
  • 2
  • 33
  • 46
2

To make it simple, (on the way I see it) Genetic Programming is an application of Genetic Algorithm. The Genetic Algorithm is used to create another solution via a computer program.

Ruel
  • 15,438
  • 7
  • 38
  • 49
  • 2
    Intuitively Genetic Programming seems to be a subset of Genetic Algorithms. But it is interesting to consider that formally GP is more general than GA, since GP is (in theory) able to evolve any program - including a genetic algorithm. – Tom Castle Oct 01 '10 at 12:54
  • @Tom: That doesn't hold, since a genetic algorithm isn't necessarily a program at all. A genetic algorithm could be implemented in silicon or (obviously) organics. GP can't create either of those. – Ben Voigt Jun 11 '11 at 16:20
  • 1
    Genetic Algorithm is by definition an algorithm. Genetic Programming can evolve the logic of that algorithm. The implementation of that logic is a different question. – Tom Castle Jun 12 '11 at 14:10
  • Well, theoretically GP can evolve any algorithm given an appropriate set of functions and terminals - including a GA algorithm. Let's ignore the probability of evolving something that complex for now.. ;-) But of course GP is an application of GA in itself. – Jay Dec 16 '11 at 10:35
0

Practical answer:

GA is when using a population and evolve the generations of population to a better state. (For example how the humans have evolved from animals to people, by breading and get better genes)

GP is when by known definition of the problem generate code into better solve a problem. (GP will usually give a lots of if/else statements, that will explain the solution)

Andreas Mattisson
  • 1,051
  • 2
  • 19
  • 39
  • 2
    Sorry, but that's wrong: You'll use a population of solutions in either case as well as a fitness function to judge the quality of an individual to (hopefully) select them and create even better individuals in upcoming generations. – Jay Dec 16 '11 at 10:37
0

Lots of good partial answers above. As Koza put it in his seminal texts on the subject, "[if a GA was the best solution for a problem then a GP would evolve a GA to solve it]." Simply put, a GP is a type of GA that evolves programs that are evaluated by a cost function. The fact that the genome is a program rather than a collection of inputs for the cost function IMHO is the material difference.

https://en.wikipedia.org/wiki/Genetic_programming

Kenosis
  • 11
  • 2
-2

genetic programming is much more powerful than genetic algorithms. the output of the genetic algorithms is a quantity while the output of the genetic programming is another computer program.

Jyoti
  • 11