Transcript
Page 1: Solution February 2014 Intelligent Systems

E.T.S.I. Informática Intelligent Systems

Surname, Given name: _________________________________________________ Degree: ______________________________________________________________ Exercise 1 (2.5 points): The purpose of the Fore and Aft puzzle is to swap the dark and light tokens. The figure below depicts the initial state. The dark tokens can only be moved down or to the right. The light tokens can only be moved up or to the left. A token can be moved to an adjacent empty square or over an opposite colored token. No diagonal moves are allowed. You must model this situation as a search problem.

Solution: A state is a 5x5 matrix with the current arrangement of the blocks, where 8 cells are unused (the 2x2 blocks at the lower left and upper right corners). A dark token can be identified by number 1, the empty cell by number 0, and a light token by number 2, for example. The state space is the set of all 5x5 matrices where the used cells contain a total of 8 ones, 8 twos and one zero. The step cost is always 1. The available actions in a certain state are (provided that they are possible): -Move a dark token down, to an adjacent empty square. -Move a dark token down, over a light token. -Move a dark token right, to an adjacent empty square. -Move a dark token right, over a light token. -Move a light token up, to an adjacent empty square. -Move a light token up, over a dark token. -Move a light token left, to an adjacent empty square. -Move a light token left, over a dark token. Please note that these actions can be reformulated in terms of moves of the empty square. The goal test consists in checking whether the current state has all the light tokens in the upper left corner and all the dark tokens in the lower right corner.

Page 2: Solution February 2014 Intelligent Systems

It is not possible to go back to a previously visited state, so we can use tree search for this problem. There is only one goal state.

An admissible heuristic is the number of cells which are occupied in the goal

state, and are either empty or occupied by a token of the opposite color in the current state. Only one token can be moved on one step, and the step cost is one, so this heuristic is admissible because it is lower or equal than the number of steps needed to reach the goal state.

The A* algorithm would be suitable for this problem, given the admissible

heuristic we have just presented.

Exercise 2 (2.5 points):

Translate the following argument from natural language to the language of first order logic: The enemy of your enemy is your friend. Everyone has an enemy. _____________________________________ John has a friend. Solution: ∀x∀y∀z ( Enemy(x,y) ∧ Enemy(y,z) ⇒ Friend(x,z) ) ∀x ∃y Enemy(y,x) ____________________________________ ∃x Friend(x,John) where Enemy(x,y) stands for 'x is an enemy of y', and Friend(x,y) stands for 'x is a friend of y'. Exercise 3 (2.5 points):

Given the following inference, convert it into conjunctive normal form and use the resolution algorithm to determine whether it is correct: P ⇒ Q M ⇒ P ∨ Q |= M ⇒ Q Solution: The conversion to CNF produces the following clauses: C1. ¬P ∨ Q C2. ¬M ∨ P ∨ Q C3. M C4. ¬Q

Page 3: Solution February 2014 Intelligent Systems

The execution of the propositional resolution algorithm on the above clauses produces the following clauses: C5. P ∨ Q (2,3) C6. Q (1,5) C7. False (4,6) Since the empty clause is produced, the argument is correct. Exercise 4 (2.5 points):

Let us consider the Wine data set. The data set consists of the chemical analyses of 178 samples of Italian wines belonging to three classes named A, B and C. The number of available samples for each class is: 59, 71, and 48, respectively. Thirteen chemical features were measured from each sample. All of the features are expressed as real numbers. We have to design a system which, given a new unseen sample with its thirteen features, classifies it into one of the three wine classes. Solution:

We can use a nearest neighbor model for this classification problem. In general,

given a query point xq in an input space Rn, our task is to estimate yq=h(xq) from a set of examples {(x1,y1),…, (xN,yN)} of size N. In our case: –Each query point is of the form xq=(f1,…, f13), i.e. the chemical features of a previously unseen wine. Note that xq∈ R13. –The range of the function to be estimated h is {A, B, C}, that is, h(xq)∈ { A, B, C }. –The input space dimension is n=13, since there are thirteen features. –The size of the example set (also called training set) is N=178, since we have 178 wine samples. –The set of examples is formed by tuples (f1,i ;…; f13,i ; Classi), where i∈{1, 2, …, 178} is the index of the sample wine. Please note that Classi∈{ A, B, C } is the class that the i-th sample wine belongs to.

–In order to compute yq=h(xq) for a previously unseen wine, we take the plurality vote of the k nearest neighbors, i.e. the output class is the value of h(x) which appears the most times in NN(k,xq).

–We should select the neighborhood size k such that the number of classification successes is maximized. We must use another set of samples for this purpose, which does not have any sample in common with the training set. This second set is called the validation set. Question 1 (1 point):

Compute the following performance measures from the confusion matrix given below:

a) Accuracy. b) True positives, true negatives, false positives, false negatives.

Page 4: Solution February 2014 Intelligent Systems

c) Precision, fallout, recall, F-measure.

Actual class Positive Negative

Positive 182 31

Predicted class Negative 12 245

FNFPTNTPTNTPAccuracy

++++

= ; FNTP

TPRecall+

= ; TNFP

FPFallout+

=

FPTPTPPrecision+

= ; RecallPrecision

RecallPrecision·measureF+

=− 2

Solution:

a)

=+++

+=

22211211

2211

nnnnnnAccuracy

0.90852451231182

245182≈

++++

b)

18211 == nTP 24522 == nTN 3112 == nFP 1221 == nFN

c)

0.854531182

182≈

+=Precision

0.112324531

31≈

+=Fallout

0.938112182

182≈

+=Recall

0.89449381.08545.09381.08545.02 =

+⋅

=− measureF

Question 2 (1 point): Design a single layer perceptron which computes the NAND Boolean function:

x1 x2 F(x1,x2) 0 0 1 0 1 1 1 0 1 1 1 0

Page 5: Solution February 2014 Intelligent Systems

Solution:

where the activation function f is the step function and w1, w2 = -0,25; θ = -0,4.

f(x1,x2) X1

X2

θ


Top Related