# Q2 · GA through two generations [3]

Subject: Intelligent Systems II

Exam: M2

Reader: https://deep-learning-study-room.vercel.app/is2/#m2/mocks/m2-paper-v2-2/q2

Canonical: https://deep-learning-study-room.vercel.app/read/is2/m2/mocks/m2-paper-v2-2--q2/

Q1(a)+Q1(b) compulsory; any two of Q2–Q4. Answers immediately below each question.

**Confirmed M2 pattern:** Q1(a) [2] and Q1(b) [2] are compulsory. Attempt any two of Q2, Q3 and Q4, each worth 3 marks. The paper offers 13 marks; you attempt 10. These are newly written practice questions, not claims about the exact upcoming paper. Solutions are directly below each question; the teaching working is deliberately longer than a concise exam answer.

**Q2. Maximise 

$$
f(x)=x^2
$$

 over unsigned 4-bit integers using the supplied GA settings. Perform two complete generations and compare the population fitness.** [3 marks · Practice; complete two-generation solution]

#### Given

Initial ordered population: [1, 6, 9, 14]. Use 4 bits, crossover after bit 2, pair mating-pool slots 1–2 and 3–4. Flip bit 3 of children [1, 2, 3, 4] in every generation. Replace the whole population with the four children; no elitism.

| Generation | Selection instruction |
| --- | --- |
| 1 | Current individual row numbers [3, 4, 4, 3] |
| 2 | Current individual row numbers [2, 3, 2, 3] |

#### To find

Both generations: evaluation, selection, crossover, mutation, decoding and comparison.

#### Formula and why it applies

Encoding represents x; it does not change the objective. Crossover exchanges tails. Mutation flips specified bits. Fitness must be recomputed after mutation. Use exactly the supplied selection rule; replacing the weakest by the strongest is not a universal GA step.

#### Solution

##### Step 1. Generation 1: evaluate and encode the current population

| Individual | x | Binary | Objective calculation |
| --- | --- | --- | --- |
| 1 | 1 | 0001 | 1 × 1 = 1 |
| 2 | 6 | 0110 | 6 × 6 = 36 |
| 3 | 9 | 1001 | 9 × 9 = 81 |
| 4 | 14 | 1110 | 14 × 14 = 196 |

##### Step 2. Generation 1: apply the supplied selection order

The question directly supplies individual numbers [3, 4, 4, 3]. These refer to the current generation’s row numbers, not their x values.

| Mating-pool slot | Chosen individual | x | Chromosome |
| --- | --- | --- | --- |
| 1 | 3 | 9 | 1001 |
| 2 | 4 | 14 | 1110 |
| 3 | 4 | 14 | 1110 |
| 4 | 3 | 9 | 1001 |

##### Step 3. Generation 1: crossover after bit 2

Keep each prefix and exchange the suffixes. Bit positions are counted from the left starting at 1.

| Pool slots paired | Parent A | Parent B | Child A | Child B |
| --- | --- | --- | --- | --- |
| 1 & 2 | 10 | 01 | 11 | 10 | 1010 | 1101 |
| 3 & 4 | 11 | 10 | 10 | 01 | 1101 | 1010 |

##### Step 4. Generation 1: mutate only the specified bits

| Child | Before mutation | Instruction | After mutation |
| --- | --- | --- | --- |
| 1 | 1010 | Flip bit 3 | 1000 |
| 2 | 1101 | Flip bit 3 | 1111 |
| 3 | 1101 | Flip bit 3 | 1111 |
| 4 | 1010 | Flip bit 3 | 1000 |

##### Step 5. Generation 1: decode and evaluate every child

| Chromosome | Decode using place values | Objective |
| --- | --- | --- |
| 1000 | 8 + 0 + 0 + 0 = 8 | 8² = 64 |
| 1111 | 8 + 4 + 2 + 1 = 15 | 15² = 225 |
| 1111 | 8 + 4 + 2 + 1 = 15 | 15² = 225 |
| 1000 | 8 + 0 + 0 + 0 = 8 | 8² = 64 |

##### Step 6. Generation 1: compare and form the next population

Add the objective scores in each population, then divide by its number of individuals.



$$
\overline f_{old}=\frac{1+36+81+196}{4}=\frac{314}{4}=78.5
$$





$$
\overline f_{new}=\frac{64+225+225+64}{4}=\frac{578}{4}=144.5
$$



Best objective: 196 → 225. Higher is better. The next population is [8, 15, 15, 8]. No elitism is imposed, so the best previous individual is not automatically protected.

##### Step 7. Generation 2: evaluate and encode the current population

| Individual | x | Binary | Objective calculation |
| --- | --- | --- | --- |
| 1 | 8 | 1000 | 8 × 8 = 64 |
| 2 | 15 | 1111 | 15 × 15 = 225 |
| 3 | 15 | 1111 | 15 × 15 = 225 |
| 4 | 8 | 1000 | 8 × 8 = 64 |

##### Step 8. Generation 2: apply the supplied selection order

The question directly supplies individual numbers [2, 3, 2, 3]. These refer to the current generation’s row numbers, not their x values.

| Mating-pool slot | Chosen individual | x | Chromosome |
| --- | --- | --- | --- |
| 1 | 2 | 15 | 1111 |
| 2 | 3 | 15 | 1111 |
| 3 | 2 | 15 | 1111 |
| 4 | 3 | 15 | 1111 |

##### Step 9. Generation 2: crossover after bit 2

Keep each prefix and exchange the suffixes. Bit positions are counted from the left starting at 1.

| Pool slots paired | Parent A | Parent B | Child A | Child B |
| --- | --- | --- | --- | --- |
| 1 & 2 | 11 | 11 | 11 | 11 | 1111 | 1111 |
| 3 & 4 | 11 | 11 | 11 | 11 | 1111 | 1111 |

##### Step 10. Generation 2: mutate only the specified bits

| Child | Before mutation | Instruction | After mutation |
| --- | --- | --- | --- |
| 1 | 1111 | Flip bit 3 | 1101 |
| 2 | 1111 | Flip bit 3 | 1101 |
| 3 | 1111 | Flip bit 3 | 1101 |
| 4 | 1111 | Flip bit 3 | 1101 |

##### Step 11. Generation 2: decode and evaluate every child

| Chromosome | Decode using place values | Objective |
| --- | --- | --- |
| 1101 | 8 + 4 + 0 + 1 = 13 | 13² = 169 |
| 1101 | 8 + 4 + 0 + 1 = 13 | 13² = 169 |
| 1101 | 8 + 4 + 0 + 1 = 13 | 13² = 169 |
| 1101 | 8 + 4 + 0 + 1 = 13 | 13² = 169 |

##### Step 12. Generation 2: compare and form the next population

Add the objective scores in each population, then divide by its number of individuals.



$$
\overline f_{old}=\frac{64+225+225+64}{4}=\frac{578}{4}=144.5
$$





$$
\overline f_{new}=\frac{169+169+169+169}{4}=\frac{676}{4}=169
$$



Best objective: 225 → 169. Higher is better. The next population is [13, 13, 13, 13]. No elitism is imposed, so the best previous individual is not automatically protected.

**Final answer.** After two generations the ordered population is [13, 13, 13, 13]. Best final objective = 169 at x = [13].
