## CS4341 Introduction to Artificial Intelligence. D-2001 SOLUTIONS Exam 2 - May 1, 2001

By Chris Shoemaker, Songting Chen, and Carolina Ruiz
Department of Computer Science
Worcester Polytechnic Institute

#### Instructions

• Ask in case of doubt

#### Problem 1. Decision Trees (20 points)

The following table of contains information on whether patients were sent home the day after an operation.

 PATIENT ID MAJOR OPERATION? FAMILY AT HOME? OLD? SENT HOME? 1. yes no no no 2. yes no yes no 3. no no no yes 4. no no yes no 5. no yes yes yes

1. (15 points) Use information theory to construct a minimal decision tree that predicts whether or not a patient is likely to be sent home the day after an operation.
SHOW EACH STEP OF THE CALCULATIONS.
```                 x      1  1/4  2/3  3/4  1/3  1/2
---------------------------------------
log_2(x)     0   -2 -0.6 -0.4 -1.6  -1
```

• Major Operation:
• Yes: (2/5)*[-(0/2)*lg(0/2) - (2/2)*lg(2/2)] = 0
• No:  (3/5)*[-(2/3)*lg(2/3) - (1/3)*lg(1/3)] = .6*[.4 + .53] = .56
• Total: 0 + .56 = 0.56
• Family at Home:
• Yes: (1/5)*[-(1/1)*lg(1/1) - (0/1)*lg(0/1)] = 0
• No:  (4/5)*[-(1/4)*lg(1/4) - (3/4)*lg(3/4)] = .8*[.5 + .3] = .64
• Total: 0 + .64 = 0.64
• Old:
• Yes: (3/5)*[-(1/3)*lg(1/3) - (2/3)*lg(2/3)] = .6*[.53 + .4] = .56
• No:  (2/5)*[-(1/2)*lg(1/2) - (1/2)*lg(1/2)] = .4*[.5 + .5] = .4
• Total: .56 + .4 = 0.96

Since Major Operation is the attribute with the lowest entropy, we select it as the root node.  we select it.  The partially constructed tree so far is:

Major Operation
/                           \
Yes /                              \ No
1-, 2-                            3+, 4-, 5+

Only the branch corresponding to Major Operation = no needs further processing.

• Family at Home:
• Yes: (1/3)*[-(1/1)*lg(1/1) - (0/1)*lg(0/1)] = 0
• No:  (2/3)*[-(1/2)*lg(1/2) - (1/2)*lg(1/2)] = .66*[.5 + .5] = .66
• Total: 0 + .66 = 0.66
• Old:
• Yes: (2/3)*[-(1/2)*lg(1/2) - (1/2)*lg(1/2)] = .66*[.5 + .5] = .66
• No:  (1/3)*[-(1/1)*lg(1/1) - (0/1)*lg(0/1)] = 0
• Total: 0 + .66 = 0.66

Since both attributes have the same entropy, we select either one, for example, Family at Home.  The partially constructed tree so far is:

Major Operation
/                           \
Yes /                              \ No
1-, 2-                            \    3+, 4-, 5+
Family at Home
/                           \
Yes /                              \ No
5+                              3+, 4-

Only the branch corresponding to Family at home = no needs further processing.  Since Old is the last remaining attribute, we select it.  The resulting tree is:

Major Operation
/                           \
Yes /                              \ No
1-, 2-                            \    3+, 4-, 5+
Family at Home
/                           \
Yes /                              \ No
5+                              \
Old    3+, 4-
/         \
Yes /            \ No
4-              3+

• (5 points) Translate your decision tree into a collection of decision rules.
1. If Major Operation = Yes Then Sent Home = No
2. If Major Operation = No & Family at Home = Yes Then Sent Home = Yes
3. If Major Operation = No & Family at Home = No & Old = Yes Then Sent Home = No
4. If Major Operation = No & Family at Home = No & Old = No Then Sent Home = Yes

#### Problem 2. Genetic Algorithms (20 points)

Consider a genetic algorithm in which individuals are represented using a 5-bit string of the form b1b2b3b4b5. An example of an individual is 001001 for which b1=0, b2=0, b3=1, b4=0, b5=1.

The fitness function is defined over these individuals as follows:
f(b1b2b3b4b5) = b1 + b2 + b3 + b4 + b5 + AND(b1,b2,b3,b4,b5),

where AND(b1,b2,b3,b4,b5)=1 if b1=b2=b3=b4=b5=1; and AND(b1,b2,b3,b4,b5)=0 otherwise.

1. (10 points) Selection Complete the following table showing the probabilities of selecting each of the individuals below according to the standard selection method.
NOTE: Following Winston's notation, below I'm calling "fitness" (in quotes) the probability that an individual has of being selected under a selection method.
```
Individual     Fitness               Standard "fitness"
or quality            or probability of
being selected

00101          0+0+1+0+1+0 = 2       2/14 = .14

11101		 1+1+1+0+1+0 = 4       4/14 = .29

00000		 0+0+0+0+0+0 = 0       0/14 = 0

10010		 1+0+0+1+0+0 = 2       2/14 = .14

11111  	 1+1+1+1+1+1 = 6       6/14 = .43

-------
14
```
2. (5 points) Crossover Suppose that a single crossover point will be used for crossover. This point has been chosen as the point between the 2nd and the 3rd bits (i.e. between b2 and b3). Show the two offspring that will result from crossing over the following two individuals:

```     PARENTS                     OFFSPRING:

First parent:  00.101       First offspring:  00111

Second parent: 10.111       Second offspring: 10101

```
3. (5 points) Mutation Explain how the standard mutation method is applied after selection and crossover to form the "next" generation of a population.

For each individual, a bit of the individual will be randomly selected and it will be flipped with a given "mutation rate" probability.

#### Problem 3. Logic-based Systems (20 points)

Consider the following set of axioms:
1. Every investor bought stocks.
forall x [investor(x) -> bought(x,stocks)]

2. If the Dow-Jones Average crashes, then all stocks fall.
crashes(dow-jones) -> fall(stocks)

3. Every person who bought something that falls is not happy.
forall y [forall z [[bought(y,z) && fall(z)] -> !happy(y)]]

4. Ralph is an investor.
investor(ralph)

5. Conclusion: If the Dow-Jones Average crashes then Ralph is not happy.
crashes(dow-jones) -> !happy(ralph)

here:

• constants symbols: dow-jones, stocks, ralph.
• relation symbols: investor, bought, crashes, fall, happy.
• variable symbols: x, y, z.

Prove the conclusion from the axioms by refutation using resolution:

1. (10 points) Translate the axioms and the negation of the conclusion into clausal form. Show each step of the translation (remember that the order in which you apply the steps is crucial).

• Negate conclusion:
• !(crashes(dow-jones) -> !happy(ralph))
• Eliminate implications:
• forall x [!investor(x) || bought(x,stocks)]
• !crashes(dow-jones) || fall(stocks)
• forall y [forall z [![bought(y,z) && fall(z)] || !happy(y)]]
• investor(ralph)
• !(!crashes(dow-jones) || !happy(ralph))
• Move negations to atomic formulae:
• forall x [!investor(x) || bought(x,stocks)]
• !crashes(dow-jones) || fall(stocks)
• forall y [forall z [[!bought(y,z) || !fall(z)] || !happy(y)]]
• investor(ralph)
• crashes(dow-jones) && happy(ralph)
• Eliminate universal quantifiers and split conjunctions
• A1:   !investor(x) || bought(x,stocks)
• A2:   !crashes(dow-jones) || fall(stocks)
• A3:   !bought(y,z) || !fall(z) || !happy(y)
• A4:   investor(ralph)
• A5a: crashes(dow-jones)
• A5b: happy(ralph)

2. (10 points) Apply resolution (state explicitly what clauses are resolved and which substitutions are made) until the empty clause is found.

• A1:  !investor(x) || bought(x,stocks)
• A4:  investor(ralph)
• ---------------------------------------------  substituting x by ralph
• A6:  bought(ralph, stocks)
• A3:  !bought(y,z) || !fall(z) || !happy(y)
• ---------------------------------------------  substituting y by ralph; z by stocks
• A7:  !fall(stock) || !happy(ralph)
• A2:  !crashes(dow-jones) || fall(stocks)
• ---------------------------------------------
• A8:  !happy(ralph) || !crashes(dow-jones)
• A5b: happy(ralph)
• ---------------------------------------------
• A9:  !crashes(dow-jones)
• A5a: crashes(dow-jones)
• ---------------------------------------------
• empty clause

#### Problem 4. Planning (20 points)

Consider the following planning problem. Fred is in his living room with his robot by his side and his beer is in the kitchen. The target is to have the beer with him in the living room, AND THE ROBOT IN THE KITCHEN. More precisely,
• Initial State
{at(robot,living_room), at(beer,kitchen),at(fred,living_room), door_closed(kitchen,living_room)}

• Goal State
{at(beer,living_room),at(fred,living_room), door_open(kitchen,living_room),at(robot,kitchen)}

• Operators
1. Operator 1: open(R1,R2)
```        IF at(robot,R1)
door_closed(R1,R2)
DELETE door_closed(R1,R2)
```
2. Operator 2: close(R1,R2)
```        IF at(robot,R1)
door_open(R1,R2)
DELETE door_open(R1,R2)
```
3. Operator 3: move(R1,R2)
```        IF at(robot,R1)
door_open(R1,R2)
DELETE at(robot,R1)
```
4. Operator 4: carry(R1,R2,Obj)
```        IF door_open(R1,R2)
at(robot,R1)
at(Obj,R1)
at(Obj,R2)
DELETE at(robot,R1)
at(Obj,R1)
```
• (20 points) Assume that door_open(X,Y) is equal to door_open(Y,X). Follow in detail the backward chaining algorithm described in Chapter 15 of your textbook to construct a plan to go from the initial situation to the goal situation. You must show all establishes, threatens, and before links.

Note: In the diagram above, B stands for beer, F for Fred, R for robot, K for kitchen, L for living room. Lower case letters would have been better choice for denoting those constants.

#### Problem 5. Machine Vision (20 points)

Suppose that during the analysis of an image, you have found an unknown object in the image. You want to determine what kind of object it is by matching it against a database of templates that you have at hand.
1. Suppose that you know that the unknown object could have been rotated with respect to only the y-axis and has not been translated. Answer the questions below.

1. (2 points) How many templates per model are needed to determine if the unknown object matches that model?

Two (2)

2. (4 points) Write down the equation that describes the x-coordinate of a point on the unknown object in terms of the x-coordinates of the corresponding points on the templates.

xIo = alpha * xI1 + beta * xI2

3. (4 points) How many corresponding points are needed to do the matching? Explain your answer precisely in terms of the equation you provided above.

Two (2). Given that the equation above has two variables (alpha and beta) then we need two equations to be able to solve the system for those variables.

2. Suppose that you know that the unknown object could have been rotated and translated with respect to all of the 3-D axes. Answer the questions below.

1. (2 points) How many templates per model are needed to determine if the unknown object matches that model?

Three (3).

2. (4 points) Write down the equation that describes the x-coordinate of a point on the unknown object in terms of the x-coordinates of the corresponding points on the templates.

xIo = alphax*xI1 + betax*xI2 + gammax*xI3 + deltax

3. (4 points) How many corresponding points are needed to do the matching? Explain your answer precisely in terms of the equation you provided above.

Four (4). Given that the equation above has four variables (alphax, betax, gammax, and deltax) then we need four equations to be able to solve the system for those variables.