Ec 05 2023
Ec 05 2023
Evolutionary Computation
EE-6950, Fall 2023
Lecture # 5 - EC Representation
Outline
I. HW#03 Solution Review
- Rastrigin tness function & matplotlib stats plotting
II. EC Representation
III. Homework #4
2
fi
I. Homework #03:
Solution Review
HW#03 Solution Review
4
II. EC Representation
Remember me? ☺ Evolutionary Algorithm
/Crossover
6
Representation, Mutation, and Recombination
• Role of representation and variation operators
7
Role of representation & variation operators
• Variation operators:
- Mutation
- Crossover (recombination)
8
Recap:
EC Representation & Variation Components
The 8-queens problem: Representation
External representation:
a board configuration
Internal state:
Possible mapping
a permutation of
the numbers 1–8 1 3 5 2 6 4 7 8
10
Simple 1-D Optimization: Representation
f(x) = 50 − x 2
11
𝑥𝑥
Mutation
• Acts on a single state (Individual) and delivers another (e.g., it’s a point
operator)
12
Mutation
before 1 1 1 1 1 1 1
after 1 1 1 0 1 1 1
13
Recombination (Crossover)
• Hope is that some are better by combining elements of genotypes that lead to
good traits
14
ff
Recombination
Parents
cut cut
1 1 1 1 1 1 1 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0 0 1 1 1 1
Offspring
15
Crossover or Mutation?
16
ff
Crossover or Mutation?
Exploration: Discovering promising areas in the search space, i.e. gaining new
information on the problem
Note: How we de ne this depends somewhat on our perspective as well as how we implement our
variation operators. From Eiben's perspective, the explorative vs exploitative distinction primarily
relates to how close the generated states are to the parent state(s).
17
fi
Crossover or Mutation?
18
Binary Representation
Binary Representation
20
Mutation
• Mutation can cause undesirable non-uniform e ect (can use gray coding)
21
1-Point Crossover
• Choose a random point on the two parents
• Split parents at the crossover point
• Create children by exchanging tails
• pc typically in range (0.6, 0.9)
22
Alternative Crossover Operators
23
n-Point Crossover
24
Uniform Crossover
25
fi
Integer Representation
Integer Representation
27
fl
Integer Representation
Examples:
3 5 6 3 9
1 5 4 2 8
28
Integer Variation Operators
29
Mutation
3 5 6 3 9
3 5 4 3 9
30
Crossover
3 5 6 3 9 3 5 4 3 8
1 5 4 2 8 1 5 6 2 9
31
Real-valued/Floating-Point Representation
Real-Valued or Floating-Point Representation
33
A possible approach (GA): Mapping real values on bit strings
z ∈ [x,y] ⊆ ℜ represented by {a1,…,aL} ∈ {0,1}L
y − x L −1
Γ(a1 ,..., aL ) = x + L ⋅ ( ∑ a L − j ⋅ 2 j ) ∈ [ x, y ]
2 − 1 j =0
• Only 2L values out of in nite are represented
• L determines possible maximum precision of solution
• High precision long chromosomes (slow evolution)
• Note: Used in early GA “universal” problems solvers. Given the power of oating point processors on
modern machines, I don’t recommend this approach unless you’ve got a good reason for using nite-
precision bit-based representation
34
fi
fi
Uniform Mutation
• Uniform Mutation:
xiʹ drawn randomly (uniform) from [LBi ,UBi ]
• Non-uniform mutation:
- Most common method is to add random deviate to each variable separately,
taken from N(0,σ) Gaussian distribution and then restrict to range
x′i = xi + N(0,σ)
36

Self-Adaptive Mutation (Important!)
• Step-sizes are included in the encoding and undergo variation and selection
themselves:
⟨x1, …, xn, σ⟩
• Mutation step size is not set by user but co-evolves with solution
37
ff
Self-Adaptive Mutation
• Mutate σ rst
• Net mutation e ect: ⟨x, σ⟩ → ⟨x′, σ′⟩
• Order is important:
• rst σ → σ′ (see later how)
• then x → x′ = x + N(0,σ′)
• Rationale: new ⟨x′, σ′⟩ is evaluated twice
• Primary: x′ is good if f(x′) is good
• Secondary: σ′ is good if the x′ it created is good
38











fi
fi
ff
Uncorrelated mutation with single σ
40
Uncorrelated mutation with N σ’s
• Boundary rules: σ′i < ϵmin → σ′i = ϵmin , σ′i > ϵmax → σ′i = ϵmax
41










Uncorrelated mutation with N σ’s
Ellipse (hyper-ellipsoid): Each dimension has its own mutation probability “scale”
42
Correlated mutation
43
fi
Correlated mutation
The mutation mechanism is then:
No free lunch!
• Representation may now be more “accurate”
• But we have also substantially increased the
problem size by including N σ’s and k α’s
45
Crossover operators
• Discrete:
• Each value in o spring z comes from one of its parents (x, y) with equal
probability: zi = xi or yi
• Could use n-point or uniform crossover, similar to binary or integer cases
3.2 5.1 6.5 3.3 9.7 3.2 5.1 4.2 3.3 8.8
1.8 5.6 4.2 2.6 8.8 1.8 5.6 6.5 2.6 9.7
46
ff
Crossover operators
• Intermediate/Arithmetic
• Create children “between” parents (hence a.k.a. arithmetic recombination)
zi = α xi + (1 − α) yi where α : 0 ≤ α ≤ 1
• The parameter α can be:
- Constant: uniform arithmetical crossover
- Variable (e.g. depend on the age of the population)
- Picked at random every time
Parent 1 Parent 2
Child
xi zi yi
47
Single arithmetic crossover
• Child1 is (reverse for Child2): with di erent value for each child
αx + (1 − α)y
50
ff
Blend Crossover
51
Multi-parent recombination
• Been around since 1960s, still rare but studies indicate can be useful
52
Multi-parent recombination, type 1
• Idea: Segment and recombine parents
• Example: diagonal crossover for n parents:
• Choose n-1 crossover points (same in each parent)
• Compose n children from segments of parents along a “diagonal”, wrapping around
54
Permutation Representation
Permutation Representations
56
Permutation Representation:
TSP example
• Problem:
- Given n cities
- Find a complete tour with minimal length
• Encoding:
- Label the cities 1, 2, … , n
- One complete tour is one permutation (e.g. for
n=4 [1,2,3,4], [3,4,2,1] are OK)
57
Mutation
• Mutation now re ects the probability that some operator is applied once to
the whole string, rather than individually in each position
58
fl
Swap mutation
59
Insert Mutation
60
fi
Scramble mutation
61
Inversion mutation
• Pick two slots at random and then invert the substring between them.
• Preserves most adjacency information (only breaks two links) but disruptive of
order information
62
Crossover operators
12345 12321
54321 54345
63
Order 1 Crossover
64
fi
Order 1 Crossover
65
fi
Partially Mapped Crossover (PMX)
• Typically used for “adjacency” type problems (e.g., TSP-like problems)
67
Cycle Crossover
Basic idea: Each value comes from one parent together with its position.
Informal procedure:
1. Make a cycle of values from P1 in the following way.
(a) Start with a random slot in P1.
(b) Look at the value at the same position in P2.
(c) Go to the position with the same value in P1.
(d) Add this value to the cycle.
(e) Repeat step b through d until you arrive at the initial slot you started with in P1.
2. Put values of cycle from the rst child on positions they have from rst
parent.
68
fi
Cycle Crossover
• Step 1: identify cycles
69
ff
Tree Representation
Tree Representation
• Trees are a universal form, good for symbolic expressions, e.g. consider:
• Arithmetic formula:
( 5 + 1)
y
2π + (x + 3) −
71
Tree Representation
( 5 + 1)
y
2π + (x + 3) −
72
Tree Representation
73
Tree Representation
i=1;
while (i < 20)
{
i=i+1;
}
74
Tree Representation
• In GA, ES, EP representations are linear structures (bit strings, integer string,
real-valued vectors, permutations)
75
Tree Representation
• LISP-like “syntax”, has traditionally often been used in elds such as AI,
easier programmatic structure to manipulate computationally
76
Mutation
77
Mutation
• The size of the child can exceed the size of the parent
78
Recombination
79
ff
Recombination
Parent 1 Parent 2
Child 1 Child 2
80
A few final thoughts
Self-Adaptivity
83
Variation & Other Representations
84
III. Homework #4
- Due by Oct 12 @ noon
- Submit to iLearning
Homework assignment #4 –EV2
EV2 – Let’s upgrade & improve EV1 a bit:
1. Modify EV1 mutation operator to be self-adaptive:
- Use single-σ uncorrelated adaptive mutation rate
- Hint 1: No longer need mutationProb and mutationStddev parameters from EV1
- Hint 2: Eqns 4.2 & 4.3 Eiben’s book, or my slides 39-41 “Uncorrelated mutation with
single σ”
86
Homework assignment #4 – EV2
- Create 5 children per generation (crossover & mutate). As in EV1, continue to use random parent
selection, 2 parents per child (note in the case of purely random selection, parents could
potentially participate in reproduction multiple times)
- As in EV1, continue to use "replace-worst" survivor selection, however in EV2, use this selection
process to allow both the parents and children to compete against each other for survival. (Hint:
create all of the children rst, then sequentially run replace-worst selection for each child)
87
fi
Homework assignment #4 – EV2
4. Improve code structure, better use of OO:
• Move mutation and crossover to Individual class:
- Hint 1: def crossover(self, other) -> returns new Individual
- Hint 2: def mutate(self) -> mutates internal state of existing Individual
5. Test your EV2 program using the two tness functions from our previous
self-study exercise (Parabola & Rastrigin functions)
88
Homework assignment #4
• Suggested (optional):
- Use matplotlib to plot the adaptive mutation strength vs. generation count.
How does it behave? Does it eventually decrease with time?
89
Homework #4: Recommended reading
• Recommended reading:
- Eiben Chapter 4
90
Next up…
EC Fitness, Selection,
and Population Management