502 - KRR - June 2012 - Answer - BB

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

EXAMINATION QUESTION PAPER

Faculty of Engineering & IT

Programme : MSc. in Informatics

Module : INF01502-Knowledge Representation and Reasoning

Date: 1 July 2012 Time: 7:45-10:00pm


This includes the reading time from
7:45 pm to 8:00 pm.

Examiner: K. Shaalan

INSTRUCTIONS TO CANDIDATES

Answer ALL questions

Each part of a question carries a weight and the marks are shown at the side of
the respective part. The total marks of the exam are 100.

Write as legibly as possible.

THIS EXAMINATION WILL BE MARKED ANONYMOUSLY


INF502-Knowledge Representation and Reasoning

Model Answer

1 Induction (10 points)

Explain what is meant by each of the following (in one or two sentences each):

a) (2 points) Symbolic logic


b) (2 points) Semantics
c) (2 points) Soundness
d) (2 points) Completeness
e) (2 points) Monotonic Logic

Answer:
a) Symbolic logic is the study of symbolic abstractions that capture the formal
features of logical inference.
b) The facts in the world to which the sentences refer.
c) An inference procedure is sound if it generates only entailed sentences.
d) An inference procedure is complete if it can generate all entailed
sentences.
e) A logic in which adding a sentence to the set of given sentences never
invalidates a previously derived sentence

2 Propositional Inference (10 points)

a) (5 points) Convert the following propositional logic sentence to conjunctive


normal form (CNF):
(C ∧ D) ∨ (E → F)

b) (5 points) Assuming the following formula, which is already in CNF

(¬ A ∨ B) ∧ (¬ B ∨ C) ∧ A

Prove C using resolution.

Answer:
a)
(C ∧ D) ∨ (E → F)
= (C ∧ D) ∨ (¬ E ∨ F)
= (C ∨ (¬ E ∨ F)) ∧ (D ∨ (¬ E ∨ F))
= (C ∨ ¬ E ∨ F) ∧ (D ∨ ¬ E ∨ F)

b)

1
To prove C, we assume that ¬ C and derive a contradiction using the resolution
rule. We therefore have the following:
(¬ A ∨ B) ∧ (¬ B ∨ C) ∧ A ∧¬ C

Resolve (¬ A ∨ B) with (¬ B ∨ C) using B and ¬ B to get (¬ A ∨ C)


Resolve (¬ A ∨ C) with A to get C
Resolve C with ¬ C to get a contradiction ⊥
Therefore, ¬ C cannot hold, and therefore C must be true.

3 First Order Logic (10 points)

Convert the following English sentences to sentences in first-order logic. Assume


that P(x) means x is a person, B(x) means x is a bully, K(x,y) means x is kind to
y, C(x) means x is a child, A(x) means x is an animal, G(x) means x plays golf,
and N(x,y) means x knows y.

1. Everyone knows Rasha.


2. Everyone who is not a bully is kind to children.
3. Bullies are not kind to themselves.
4. Everyone knows someone who plays golf.
5. People who are not kind to animals do not play golf.

Answer:
a) x N(x, Rasha)
b) x (P(x) ∧ ¬ B(x) → y (C(y) → k(x,y)))
c) x (B(x) → ¬ K(x,x))
d) x (P(x) → y (P(y) ∧ N(x,y) ∧ G(y)))
e) x y (P(x) ∧ A(y) ∧ ¬ K(x,y ) → ¬ G(y))

4 Search Techniques (20 points)

Consider the following maze in which the successors of a cell include any
adjacent cell in the directions North, South, East, and West of the current cell,
except at the boundary of the maze or when a barrier (thick line) exists. For
example, successors(m) = {d,n,g}. Assume each type of move (N,S,E,W) has
cost 1.

A B

C D E

F S H K M N
P Q R T G

2
The problem is to find a path from cell S to cell G. Assuming children are always
expanded in the order East, South, West, North, then Breadth-First Search
(without duplicates) would visit cells in the order: SHFKPCQARBTDG. If a search
method needs to break ties, expand first the node corresponding to the letter
closest to the front of the alphabet. Consider the following map (not drawn to
scale)

For parts (a-c) below, what is the order of nodes expanded (plus the goal node if
it is found) by each of the following search methods?

a) (5 points) Depth-First Search. Assume cycles are detected and


eliminated by never expanding a node containing a state that is repeated
on the path back to the root.
b) (5 points) Greedy Search. Use as the heuristic function h(state) =
Manhattan distance from state to G assuming there were no barriers. For
example, h(K)=2 and h(S)=4. Remove redundant states.
c) (10 points) Algorithm A* Search. Use the same heuristic function as in
(b). Remove redundant states.

Answer:
a) Depth first search
A B

C D E

F S H K M N

P Q R T G

S H K C A B DE N M G
b) Greedy Search
A h=4 B h=3

C h=3 Dh=2 E h=3

F h=5 S h=4 H h=3 K h=2 M h=1 N h=2

P h=4 Q h=3 R h=2 T h=1 G h=0

S H K C A B D MG
c) A* Search

3
A h=4 g=4 B h=3

C h=3 g=3 Dh=2 E h=3

F h=5 g=1 S h=4 H h=3 g=1 K h=2 g=2 M h=1 N h=2

P h=4 g=2 Q h=3 g=3 R h=2 g=4 T h=1 g=5 G h=0 g=6

SH KCF PQ RT G
5 Logic Programming (10 points)

a) (5 points) Implement the quick_sort algorithm for integers in Prolog–informally


it can be formulated as follows:
Given a list, split the list into two - one part containing elements less than a
given element (e.g. the first element in the list) and one part containing
elements greater than or equal to this element. Then sort the two lists and
append the results.

Answer:

quick_sort([X|Xs],Ys):-
partition(Xs,X,Littles,Bigs),
quick_sort(Littles,Ls),
quick_sort(Bigs,Bs),
append(Ls,[X|Bs],Ys).
quick_sort([],[]).

partition([X|Xs],Y,[X|Ls],Bs):-
X =<Y,
partition(Xs,Y,Ls,Bs).
partition([X|Xs],Y, Ls, [X|Bs]):-
X >Y,
partition(Xs,Y,Ls,Bs).
partition([],Y, [], []).

b) (5 points) Define the predicate pre_order(Tree, List) which, given a binary tree
Tree, returns the pre-order traversal of Tree as List. The pre-order traversal of
the tree of the empty tree nil is the empty list []. The pre_order traversal of the
tree tree(Value, Left, Right) is obtained by concatenating the one-element list
[Value], the traversal of Left and the traversal of Right, in this order. For example,
?- pre_order( tree(4, tree(6, nil, tree(5, nil, nil )), tree(1, nil, tree(2, nil, nil ))), List).
List = [4,6,5,1,2]

4
Answer:
pre_order(nil, []).
pre_order(tree(Root, LT, RT), [Root | Rest]) :-
pre_order(LT, LTNodes),
pre_order(RT, RTNodes),
append(LTNodes, RTNodes, Rest).

6 Constraint Satisfaction (20 points)

Consider the simple map colouring problem described in the figure below. Each
node represents a country, which can take one of the colours: red, blue, or green
(or r, b and g for short). A constraint between two nodes requires that no two
linked countries can be assigned the same colour.

X1

X2 X3 X4

Show how this problem can be solved using the minimum remaining value (MRV)
heuristic. When multiple variables have the same number of remaining values,
use the degree heuristic as a tie-breaker. When this is not enough, choose
variables according to numerical order (e.g. x1 before x2). When selecting values
to assign to variables, use the following order of preference: r, g, b. Show the
final solution as well as all intermediate steps, explaining why each value
assignment has been made.

Answer
The MRV heuristic chooses the variable with the least number of remaining
values. The degree heuristic chooses the variable with the biggest number of
constraints. We start with all variables having full domains.

X1 X2 X3 X4
Degree 2 Degree 2 Degree 3 Degree 1
Step RV RV RV RV
1 r,g,b r,g,b r,g,b r,g,b
2 r,g,b r,g,b r r,g,b
3 g,b g,b r g,b
4 g g,b r g,b
5 g b r g,b
6 g b r g,b
7 g b r g

5
Here's an explanation of the various steps:
1. This is our starting point.
2. Each variable has the same domain size, so we cannot apply the MRV
heuristic. So we use the degree heuristic. Variable x3 is involved in most
number of constraints (it is of degree 3). We assign it value r (since this
value is higher in the order of preference).
3. Update the remaining values (RV) of other variables, eliminating r from all
variables connected to x3 (i.e. all other variables).
4. Now, variables x1, x2 and x4 all have 2 remaining values. Among those,
x1 and x2 have degree 2, while x4 is of degree 1. Among x1 and x2, we
choose x1 according to numerical order, and assign it value g.
5. Update the RVs of other variables, eliminating g from those connected to
x1, namely x2.
6. Now, the only remaining value for x2 is b. No change needed.
7. Finally, x4 is assigned the value g.

7 Uncertainty (10 points)

Consider a domain described by the following boolean random variables, i.e.


propositions: smart (the student is smart), prepared (the student is prepared),
and catch (the student studies the lesson). Suppose you are given the full joint
probability distribution described in the following table:

smart ¬smart
study ¬study study ¬study
Prepared .432 .16 .084 .008
¬ prepared .048 .16 .036 .072
Full joint distribution for the dentist domain

Calculate the following:


a) (3 points) P(smart)
b) (3 points) P(prepared ∧ smart)
c) (4 points) P(prepared | smart)

Answer:
This question tests the students' understanding of random variables, full joint
distributions, and conditional probability:
a) P(smart) = .432 + .016 + .016 + .048
b) P(prepared ∧ smart) = .432 + .016
c) P(prepared | smart) = P(prepared ∧ smart) / P(smart)
= (.432 + .016) / (.432 + .016 + .016 + .048)

6
8 Bayesian Networks (10 points)

Consider the belief network in the figure below.

a) (5 points) Which, if any, of the following are asserted by the network


structure (ignoring the conditional probability tables (CPTs) for now)?
(NOTE: Any subset of these may be correct)
i. P(H; S) = P(H)P(S)
ii. P(EjB;H) = P(EjB)
iii. P(E) ≠ P(EjH)
b) (5 points) Calculate the value of P(h ∧ s ∧ ¬b ∧ ¬e)

Answer:
a)
i. No, since H and S are linked by an arc
ii. Yes, asserted by the local semantics: a node is conditionally
independent of its nondescendants given its parents.
iii. No, because arcs alone do not deny independence (the CPT can deny
it, however).
b) Using the Chain rule:
P (x1, . . . , xn) = ∏in= 1 P(xi|parents(Xi))

P(h ∧ s ∧ ¬b ∧ ¬e) = P(h)P(s|h)P(¬b|h, s)P(¬e|¬b)


= 0.1 x 0.3 x 0.1 x 0.9 = 0.00027

You might also like