Mid 2
Mid 2
Lahore Campus
Artificial Intelligence (CS/DS 2002) Sessional-II
th
Date: April 6 2024 Total Time: 1 Hours Course Instructors Total Marks: 35
Dr. Asma Ahmad, Dr. Hajra Waheed, Dr. Mirza Mubasher Baig, Total Questions: 03
Dr. Sadaf Jabeen, Ms. Bushra Rashid, Ms. Maham Naeem, Semester: SP-2024
Ms. Saba Tariq, Mr. Saif Ul Islam Campus: Lahore
8 1 2 9
Page 1 of 7
National University of Computer and Emerging Sciences
Lahore Campus
Part a) Which chromosome will be selected if fitness proportionate selection is used? Show complete
working.
Fitness Proportionate Count
8 0.4 2
1 0.05 0
2 0.1 0
9 0.45 2
Part b) Assume that single point crossover is to be used to compute two new solutions using the first
and third chromosome. Show complete working and the resulting chromosomes obtained after the
crossover.
HINT: To determine a crossover point you can map the random number R between 0 and 1 to a random
number between 1 and N using simple product of R with N i.e. ceiling(R*N).
100000000
010100111
Part c) Assume that the chromosome 100101010 has already been selected for mutation using a mutation
rate of 0.01. Show the resulting chromosome after mutation.
0.86 0.59 0.67 0.14 0.34 0.08 0.11 0.29 0.85
1 0 0 1 0 1 0 1 0
Since all random numbers generated are less than 0.01 no mutation occur
Part d) What is the concept of elitism in the context of genetic algorithm? How would it help in finding
a good solution?
In genetic algorithms, elitism ensures the best individuals from each generation are carried over to the next. By
keeping good solutions around, elitism avoids getting stuck in suboptimal solutions and makes sure each new
generation is more optimal with respect to fitness.
Page 2 of 7
National University of Computer and Emerging Sciences
Lahore Campus
Part e) You are given 10 unique numbers. You have to divide these numbers into 2 sets. Set 1 must have
numbers such that their product is as close to 240 as possible. Set 2 must contain numbers such that
their sum is as close to 40 as possible. You need to solve this problem using genetic algorithms.
i. Briefly explain how you would represent the solution as a chromosome.
We can represent in binary string of 0s and 1s, one bit for each number. A 0 signifies the number belongs to
Set 1, while a 1 indicates Set 2.
Chromosome: 0100110110
Numbers 1, 3, 5, 7, and 9 belong to Set 1 and Numbers 2, 4, 6, 8, and 10 belong to Set 2
OR
Another solution is a unique arrangement (permutation) of the 10 numbers. The first 4 numbers define Set 1,
and the remaining 6 belong to Set 2.
Chromosome: (3, 7, 1, 9, 5, 2, 8, 4, 10, 6)
ii. Based on your representation, what is the chromosome for the for the solution in which Set 1
contains 2, 3, 4, 10 and Set 2 has 1, 5, 6, 7, 8, 9.
Chromosome: (2, 3, 4, 10, 1, 5, 6, 7, 8, 9)
OR
Chromosome: (1,0,0,0,1,1,1,1,1,0)
iii. What should be the fitness function for this problem? Provide mathematical representation
only.
Page 3 of 7
National University of Computer and Emerging Sciences
Lahore Campus
CLO 1: [Demonstrate understanding of basic AI based search techniques]
Q. No 2: In this question you are required to attempt exactly one part i.e. either attempt the
local search problem or attempt or the game tree question but not both
A solution to the knapsack problem for a set of n items can be represented as a binary string of length n with
a bit value of 0 means the corresponding item of the set is not included in the knapsack and a bit value of 1
means the item is included. Value of solution is sum of the values of items included in that solution if the
total weight of the items do not exceed the capacity W of the sack and the value is 0 if the sum of weights
exceed the knapsack capacity.
Item Number 1 2 3 4
Value 7 6 4 1
For the set of four items shown above and a knapsack with capacity 10, use the starting solution 0 0 0 0 to
find the best solution using the hill-climbing (local search algorithm) You must show all intermediate
solutions generated in each iteration. Furthermore, you must assume that the successor/neighbors of a
solution are created by setting exactly one of the zero bit to 1 so that the solution 0 0 0 0 has four neighbors.
Page 4 of 7
National University of Computer and Emerging Sciences
Lahore Campus
Compute the value of each intermediate node that will be assigned by minimax with prunning. On the
figure also mark all branches that will be pruned by α-β prunning strategy and specify the corresponding
values of α and β at the time of prunning.
Page 5 of 7
National University of Computer and Emerging Sciences
Lahore Campus
CLO 2: [Use dominant Machine Learning paradigms to design solutions] Question No 3 [Neural
Networks] [5 + 5 Points]
Part a) A multi-layer perceptron, also called the feed-forward neural network, has 2 inputs, a single
hidden layer of 3 neurons and an output layer consisting of 2 neurons. The network uses linear
activation function in the hidden layer and sigmoid activation at the output layer. Weights of the
hidden layer and output layer neurons are given in the following table with the first weight being
that of the bias term.
Hidden Layer Weights Output Layer Weights
W0 W1 W2 W0 W1 W2 W3
1 0 1 1 1 0 1
0 0 1 -1 1 1 1
1 0 0
Compute the output of the neural network if the input (1 1) is applied to the network. Assume that
input to bias term is +1 and W0 is weight of the bias term
Page 6 of 7
National University of Computer and Emerging Sciences
Lahore Campus
Part b) Consider the dataset consisting of 4 points shown in the following table. Use a single iteration
of perceptron learning rule to learn all parameters of the model. Take all initial weight to be zero
and take the bias term or weight of the bias term to be zero as well
Inputs Output
1, 1 +1
1, -1 -1
-1, -1 -1
-1 1 +1
Page 7 of 7