Answers.Body: <p>As far as I know, there isn't a "specified correct way". The whole idea is that you want the population to converge and increase the sample rate in that more optimal looking place. What works best all depends upon your fitness landscape.</p>
  
  <p>You could also crossover by doing something like </p>
  
  <pre><code>crossover_point = random_number_size_genome
  child[:] = parent_a[:crossover_point] + parent_b[crossover_point:]
  </code></pre>
  
  <p>Or have multiple points of crossover or more exotic types of crossover.
  As far as I know, the impact on your algorithm because of the different crossover algorithms shouldn't be that different. </p>
  
  <p>Fitness function and how you select the fittest has a way bigger impact.
  You have understood the crossover step correctly, looking at your example.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-09T14:31:22.070Z
Answers.Text: What does "in that more optimal looking place" mean? Please, clarify your answer.
Answers.UserDisplayName: nbro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-09T20:16:11.513Z
Answers.Text: The position algorithm has chosen to converge to using crossover that time step. What is hopefully a more optimal place than the initial one.
Answers.UserDisplayName: hal9000
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-08T17:19:07.777Z
Answers.LastActivityDate: 2020-02-09T14:31:01.260Z
Answers.LastEditDate: 2020-02-09T14:31:01.260Z
Answers.UserDisplayName: hal9000
Body: <p>If I had the weights of a certain number of "parents" that I wanted to crossbreed, and I used whatever method to pick out the "best parents" (I used a roulette wheel option, if that's any relevant), would I be doing this correctly?</p>
  
  <p>For example, suppose I have picked the following two parents.</p>
  
  <p><span class="math-container">\begin{align}
  P_1 &amp;= [0.5, -0.02, 0.4, 0.1, -0.9] \\
  P_2 &amp;= [0.42, 0.55, 0.18, -0.3, 0.12]
  \end{align}</span></p>
  
  <p>When I'm iterating through each index (or gene) of the parents, I am selecting a weight from one parent only. I called this rate the "cross-rate", which in my case is <span class="math-container">$0.2$</span> (i.e. with <span class="math-container">$20$</span>% chance, I will switch to choosing the other parents' weight).</p>
  
  <p>So, using our example above, this is what would happen:</p>
  
  <p><span class="math-container">\begin{align}
  P_1 &amp;=[\mathbf{0.5}, \mathbf{-0.02}, 0.4, 0.1, \mathbf{-0.9}] \\
  P_2 &amp;= [0.42, 0.55, \mathbf{0.18}, \mathbf{-0.3}, 0.12]
  \end{align}</span></p>
  
  <p>So the child would be</p>
  
  <p><span class="math-container">$$C = [0.5, -0.02, 0.18, -0.3, -0.9]$$</span></p>
  
  <p>I would choose <span class="math-container">$0.5$</span> from <span class="math-container">$P_1$</span>, but for every time I choose a weight from <span class="math-container">$P_1$</span>, there's a 20% chance that I actually choose the corresponding gene from <span class="math-container">$P_2$</span>. But, for the first weight, I end up not landing on that 20% chance. So I move onto the second weight, <span class="math-container">$-0.02$</span>. This time, we hit the 20% chance, so now we swap over. Our next weight is now from <span class="math-container">$P_2$</span>, which is <span class="math-container">$0.18$</span>. And so on, until we hit another 20% chance.</p>
  
  <p>We keep doing this until we hit the end of the indexes (<span class="math-container">$P_1$</span> and <span class="math-container">$P_2$</span> have the same number of indexes, of course).</p>
  
  <p>Is this the correct way to form a child from 2 parents? Is this the correct "crossbreeding" method when it comes to genetic algorithms?</p>
  
Tags: <genetic-algorithms><definitions><crossover-operators>
Title: How does crossover work in a genetic algorithm?
UserDisplayName: Jonathan Brown
ThreadText: # How does crossover work in a genetic algorithm?
  
  (Asked by: username_0 on 2020-02-08)
  
  If I had the weights of a certain number of "parents" that I wanted to crossbreed, and I used whatever method to pick out the "best parents" (I used a roulette wheel option, if that's any relevant), would I be doing this correctly?
  
  For example, suppose I have picked the following two parents.
  
  \begin{align}
  P\_1 &= [0.5, -0.02, 0.4, 0.1, -0.9] \\
  P\_2 &= [0.42, 0.55, 0.18, -0.3, 0.12]
  \end{align}
  
  When I'm iterating through each index (or gene) of the parents, I am selecting a weight from one parent only. I called this rate the "cross-rate", which in my case is $0.2$ (i.e. with $20$% chance, I will switch to choosing the other parents' weight).
  
  So, using our example above, this is what would happen:
  
  \begin{align}
  P\_1 &=[\mathbf{0.5}, \mathbf{-0.02}, 0.4, 0.1, \mathbf{-0.9}] \\
  P\_2 &= [0.42, 0.55, \mathbf{0.18}, \mathbf{-0.3}, 0.12]
  \end{align}
  
  So the child would be
  
  $$C = [0.5, -0.02, 0.18, -0.3, -0.9]$$
  
  I would choose $0.5$ from $P\_1$, but for every time I choose a weight from $P\_1$, there's a 20% chance that I actually choose the corresponding gene from $P\_2$. But, for the first weight, I end up not landing on that 20% chance. So I move onto the second weight, $-0.02$. This time, we hit the 20% chance, so now we swap over. Our next weight is now from $P\_2$, which is $0.18$. And so on, until we hit another 20% chance.
  
  We keep doing this until we hit the end of the indexes ($P\_1$ and $P\_2$ have the same number of indexes, of course).
  
  Is this the correct way to form a child from 2 parents? Is this the correct "crossbreeding" method when it comes to genetic algorithms?
  
  **Tags:** genetic-algorithms, definitions, crossover-operators
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-02-08. Score: 3
  
  As far as I know, there isn't a "specified correct way". The whole idea is that you want the population to converge and increase the sample rate in that more optimal looking place. What works best all depends upon your fitness landscape.
  
  You could also crossover by doing something like
  
  ```
  crossover_point = random_number_size_genome
  child[:] = parent_a[:crossover_point] + parent_b[crossover_point:]
  
  ```
  
  Or have multiple points of crossover or more exotic types of crossover.
  As far as I know, the impact on your algorithm because of the different crossover algorithms shouldn't be that different.
  
  Fitness function and how you select the fittest has a way bigger impact.
  You have understood the crossover step correctly, looking at your example.
  
  > **Comments:**
  > **username_2**: What does "in that more optimal looking place" mean? Please, clarify your answer.  
  > **username_1**: The position algorithm has chosen to converge to using crossover that time step. What is hopefully a more optimal place than the initial one.  
  
  ---
  
  