<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>

CC BY-SA 4.0
2021-04-17T20:44:56.343Z
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.
gator
CC BY-SA 4.0
2021-04-17T18:33:51.260Z
2021-04-17T18:33:51.260Z
Kostya
<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>

CC BY-SA 4.0
2021-04-15T10:21:52.273Z
It may be a good idea to provide the sources of these pseudocodes.
nbro
<search><evolutionary-algorithms><meta-heuristics><pseudocode>
Does a differential evolution algorithm mutate its population during a generation?
gator
# 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.  

---

