liveBook · Manning

Crossover chance

As explained in Evolutionary Deep Learning: Genetic algorithms and neural networks

Crossover rate is a genetic-algorithm configuration that controls the likelihood, location, or extent of recombination between parents.

Crossover chance is a genetic-algorithm setting that controls how often selected parents share genetic material. Depending on the design, it can also specify whether crossover occurs, where recombination happens, or how much sequence is exchanged. section 2.5.9 section 2.6

A simple crossover operation works like this:

  • Copy both parent chromosomes to create initial children. section 2.5.6
  • Draw a random value and perform crossover when it falls below crossover_rate. section 2.5.6
  • Choose a point along the gene sequence, split both parents there, and exchange their suffixes. section 2.5.6
  • Treat the rate differently when crossover is assumed: it may then select the crossover point or exchanged amount. section 2.5.9

Experiment with the rate

Rerun the evolutionary notebook after increasing or decreasing crossover_rate, then compare whether evolution performs better for the chosen problem. Also vary mutation rate to inspect the balance between population variety and specialization. section 6.2.1 section 2.5.9

Listing 2.17 EDL_2_5_Genetic_Algorithms.ipynb: Crossover and reproduction
def crossover(parent1, parent2, crossover_rate):  
  child1, child2 = parent1.copy(), parent2.copy()             #1
 
  if random.random() < crossover_rate:                        #2
    
    pt = random.randint(1, len(parent1)-2)                    #3
    
    child1 = np.concatenate((parent1[:pt], parent2[pt:]))     #4
    child2 = np.concatenate((parent2[:pt], parent1[pt:]))     #4
 
  return [child1, child2]
 
crossover(pop[parent[0]],pop[parent[1]], .5)                  #5

Inspect the Python crossover function, including its probability test, random split point, and NumPy child construction. section 2.5.6

How Evolutionary Deep Learning: Genetic algorithms and neural networks covers it

How deep it goes
Explains probability testing and one-point recombination, while deferring balanced and structure-preserving crossover strategies.
Examples
Uses a Python crossover function, NumPy chromosomes, a random split point, and notebook experiments varying crossover and mutation rates.
What you can do after
Apply it via Python by tuning crossover_rate and recombining parent chromosomes at a randomly selected point.
How it connects
Links genetic algorithms with reproduction, mutation, fitness evaluation, evolutionary computation, and neuroevolution.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Evolutionary Deep Learning: Genetic algorithms and neural networks. The section links point to the parts of the book it draws on.