Answers.Body: <p>Quoting the <a href="https://dl.acm.org/doi/10.1023/A%3A1008202821328" rel="nofollow noreferrer">original paper</a>:</p>
  <blockquote>
  <p>For each target vector <span class="math-container">$x_{i,G}$</span> ,a mutant vector is generated according to
  <span class="math-container">$$ v_{i,G+1} = x_{r_1,G} + F\left(x_{r_2,G} + x_{r_3,G}\right)$$</span></p>
  </blockquote>
  <p>And later</p>
  <blockquote>
  <p>To decide whether or not it should become a member of generation <span class="math-container">$G + 1$</span>, the trial vector <span class="math-container">$v_{i,G+1}$</span> is compared to the target vector <span class="math-container">$x_{i,G}$</span> using the greedy criterion.</p>
  </blockquote>
  <p>I'd say it is pretty unambiguous that author's intent was to split evolving agents' populations into &quot;generations&quot; indexed by <span class="math-container">$G$</span>. A new generation <span class="math-container">$G+1$</span> is created by applying the DE algorithm to the previous generation <span class="math-container">$G$</span>. No agents are changed within the generation <span class="math-container">$G$</span>.</p>
  <p>So, it looks like the answer to your question is &quot;no&quot; - the population of the current generation <span class="math-container">$G$</span> is not mutated. Your second approach is the correct one.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-17T20:44:56.343Z
Answers.Text: Some metaheuristics, like particle swarm optimization and bat algorithm, mutate their populations during the current generation; however, some like genetic algorithm doesn't. Thanks for clarifying, it seemed like it's closer in metaphor to the ones that do but it's nice having a declarative answer.
Answers.UserDisplayName: gator
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-17T18:33:51.260Z
Answers.LastActivityDate: 2021-04-17T18:33:51.260Z
Answers.UserDisplayName: Kostya
Body: <p>I'm implementing a differential evolution algorithm and when it comes to evolving a population, the page I am referencing is vague on how the new population is generated.</p>
  <p><a href="https://en.wikipedia.org/wiki/Differential_evolution#Algorithm" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Differential_evolution#Algorithm</a></p>
  <p>The algorithm looks like the population is mutated during evolution.</p>
  <pre><code># x, a, b, c are agents in the population
  # subscriptable to find position in specific dimension
  # pop is filled with Agent objects
  for i, x in enumerate(pop):
    [a, b, c] = random.sample(pop[:i]+pop[i+1:], 3)
    ri = random.randint(0, len(x))
    new_position = []
    for j in range(len(x)):
      if random.uniform(0, 1) &lt; CR or j == ri:
        new_pos.append(a[j] + (F * (b[j] - c[j])))
      else:
        new_pos.append(x[j])
    # Agent() class constructor for agent, takes position as arg
    new_agent = Agent(new_pos)
    if fitness(new_agent) &lt;= fitness(x):
      pop[i] = new_agent # replace x with new_agent
  </code></pre>
  <p>But I wonder if instead it means a new population is made and then populated iteratively:</p>
  <pre><code>new_pop = []
  for i, x in enumerate(pop):
    [a, b, c] = random.sample(pop[:i]+pop[i+1:], 3)
    ri = random.randint(0, len(x))
    new_position = []
    for j in range(len(x)):
      if random.uniform(0, 1) &lt; CR or j == ri:
        new_pos.append(a[j] + (F * (b[j] - c[j])))
      else:
        new_pos.append(x[j])
    new_agent = Agent(new_pos)
    if fitness(new_agent) &lt;= fitness(x):
      new_pop.append(new_agent)
    else:
      new_pop.append(x)
  pop = new_pop
  </code></pre>
  <p>Note <code>new_pop</code> is made, and filled with agents as the <code>for</code> loop continues.</p>
  <p>The first allows previously evolved agents to be used again in the same generation; in other words, the population is changed during the evolution. The second doesn't allow updated agents to be re-used, and only at the end is the original population changed.</p>
  <p>Which is it?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-04-15T10:21:52.273Z
Comments.Text: It may be a good idea to provide the sources of these pseudocodes.
Comments.UserDisplayName: nbro
Tags: <search><evolutionary-algorithms><meta-heuristics><pseudocode>
Title: Does a differential evolution algorithm mutate its population during a generation?
UserDisplayName: gator
ThreadText: # Does a differential evolution algorithm mutate its population during a generation?
  
  (Asked by: username_0 on 2021-04-14)
  
  I'm implementing a differential evolution algorithm and when it comes to evolving a population, the page I am referencing is vague on how the new population is generated.
  https://en.wikipedia.org/wiki/Differential_evolution#Algorithm
  The algorithm looks like the population is mutated during evolution.
  # x, a, b, c are agents in the population
  # subscriptable to find position in specific dimension
  # pop is filled with Agent objects
  for i, x in enumerate(pop):
    [a, b, c] = random.sample(pop[:i]+pop[i+1:], 3)
    ri = random.randint(0, len(x))
    new_position = []
    for j in range(len(x)):
      if random.uniform(0, 1) < CR or j == ri:
        new_pos.append(a[j] + (F * (b[j] - c[j])))
      else:
        new_pos.append(x[j])
    # Agent() class constructor for agent, takes position as arg
    new_agent = Agent(new_pos)
    if fitness(new_agent) <= fitness(x):
      pop[i] = new_agent # replace x with new_agent
  
  But I wonder if instead it means a new population is made and then populated iteratively:
  new_pop = []
  for i, x in enumerate(pop):
    [a, b, c] = random.sample(pop[:i]+pop[i+1:], 3)
    ri = random.randint(0, len(x))
    new_position = []
    for j in range(len(x)):
      if random.uniform(0, 1) < CR or j == ri:
        new_pos.append(a[j] + (F * (b[j] - c[j])))
      else:
        new_pos.append(x[j])
    new_agent = Agent(new_pos)
    if fitness(new_agent) <= fitness(x):
      new_pop.append(new_agent)
    else:
      new_pop.append(x)
  pop = new_pop
  
  Note new_pop is made, and filled with agents as the for loop continues.
  The first allows previously evolved agents to be used again in the same generation; in other words, the population is changed during the evolution. The second doesn't allow updated agents to be re-used, and only at the end is the original population changed.
  Which is it?
  
  **Tags:** search, evolutionary-algorithms, meta-heuristics, pseudocode
  > **Comments:**
  > **username_1**: It may be a good idea to provide the sources of these pseudocodes.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-04-17. Score: 2 | Accepted answer
  
  Quoting the [original paper](https://dl.acm.org/doi/10.1023/A%3A1008202821328):
  
  > For each target vector $x\_{i,G}$ ,a mutant vector is generated according to
  > $$ v\_{i,G+1} = x\_{r\_1,G} + F\left(x\_{r\_2,G} + x\_{r\_3,G}\right)$$
  
  And later
  
  > To decide whether or not it should become a member of generation $G + 1$, the trial vector $v\_{i,G+1}$ is compared to the target vector $x\_{i,G}$ using the greedy criterion.
  
  I'd say it is pretty unambiguous that author's intent was to split evolving agents' populations into "generations" indexed by $G$. A new generation $G+1$ is created by applying the DE algorithm to the previous generation $G$. No agents are changed within the generation $G$.
  
  So, it looks like the answer to your question is "no" - the population of the current generation $G$ is not mutated. Your second approach is the correct one.
  
  > **Comments:**
  > **username_0**: Some metaheuristics, like particle swarm optimization and bat algorithm, mutate their populations during the current generation; however, some like genetic algorithm doesn't. Thanks for clarifying, it seemed like it's closer in metaphor to the ones that do but it's nice having a declarative answer.  
  
  ---
  
  