School of Computer Science
COMPSCI 367 Assignment 3
Due: by 11:59pm on the due date. This is a hard due date. Late assignments will not be marked.
Total marks: 15.
Weighting: This assignment counts toward 15% of your final mark.
Question 1 [4 marks]
Suppose that you are training a very simple naïve Bayes sentiment classifier, with add-one (Laplace) smoothing. You have the following five training documents (one sentence each), two from class – and three from class +.
Class | Documents |
- | Sad and bad service |
- | Sad cake service and I will not return at all |
+ | Delicious soup and not at all bad |
+ | Nothing bad about the service |
+ | Sad service but worth it for the soup |
(a) Create a table of counts for each word in the training data above (including a “total” column). Include details for add-one (Laplace) smoothing. (1 mark)
(b) Calculate the probability estimated, by your naïve Bayes estimator, for Class + and Class – for the sentence “Bad soup and cake”. Show your working. (2 marks)
(c) What class would your classifier choose for the sentence “Bad soup and cake”. (1 mark)
Question 2 [6 marks]
For this question, you are asked to program a game of Mū Tōrere using PDDL. Read the description carefully and create PDDL code to play this game.
Here is the Mū Tōrere playing board in the starting configuration. There are nine positions on the board. For the purposes of this assignment, I have labelled the positions as follows (0 through 8):
Fig 1. Numbering the nine board positions.
There are two players: green and white. The game uses eight playing pieces and each player has four pieces assigned to them (playerpiece). Each of the pieces is at a position on the board. There is one vacant position. Each player takes a turn to move one of their pieces into the vacant position on the board. (No jumping over pieces is allowed!) After one player has moved, it is the next player’s turn.
A validmove represents a path between one position to another position on the board that a piece might travel. The destination position for any move must not have a piece at that position (i.e., the destination position must be vacant).
The list of possible valid moves includes, firstly, the move of a piece to a position on the outer ring of the board from either one of its neighbour positions on the outer ring or else from the centre position and, secondly, a move of a piece from any of the outer positions to the centre. Consequently, there are two action schemas: moveouter and movetocentre. Note that a move from the outer ring position to the centre can only occur if there is one piece in a neighbouring position that belongs to the opponent player (i.e., this is an additional precondition for the movetocentre action schema).
Fig 2. Labels for each of the player pieces. The white pieces belong to Tūī. The green pieces are Daniel’s. Green has the first move.
The green player has the first turn. Game play continues with each player taking a turn to move one of their pieces until one player is unable to move. The winner is the person who prevents their opponent from being able to make a move.
For this assignment, you will reenact a game between Tūi (white) and Daniel (green). The initial state is shown in Figure 1. The end state of the game is shown in Figure 3 below. Daniel won this game after moving the g3 piece to position 2 on the board, hence blocking white from being able to move. For your project, the image below is the goal state that you need to reach. (Note: your game reconstruction might have a different winning move but it must reach the goal configuration represented in the picture below.)
Fig 3. The game has ended. Green has won as they have prevented White from being able to move a piece.
Have a play of Mū Tōrere on the following website to get a feel for the gameplay: https://www.heihei.nz/game/165/m%C5%AB-t%C5%8Drere
(a) Write a PDDL domain file muu_toorere_domain.pddl that specifies the two action schemas: moveouter and movecentre. (3 marks)
You need to use the PDDL syntax starting from the following:
(define (domain muutoorere)
(:requirements :strips)
(:predicates
(at ?piece ?position) (position ?pos) (piece ?piece)
(playerpiece ?piece ?player) (vacant ?v)
(validmove ?position1 ?position2)
(turn ?player) (player ?player) (different ?player1 ?player2)
(outerpos ?pos) (centrepos ?pos)
)
…//fill in the description here//
)
Tip 1: I would suggest treating vacant as an entity that is at a particular position to indicate an empty position.
Tip 2: Configure the predicate different to allow you to check that you are referring to two different players.
Tip 3: For position 0, centrepos is true. For all other positions, outerpos is true.
(b) Write a PDDL problem file muu_toorere_task.pddl that defines all components of the task, including specifying the initial state and the goal state. (3 marks)
Submit the two files muu_toorere_domain.pddl and muu_toorere_task.pddl.
You may use the PDDL Editor to test your code: http://editor.planning.domains/
Question 3 [5 marks total]
We are analysing the expression of various genes and their relationships to one another.
The following facts are found: The expression of GeneA and/or GeneB regulates the expression of GeneC. The expression of GeneC regulates the expression of GeneD.
(a) Draw the Bayesian Network diagram for these facts. (1 mark)
(b) Consider the following facts:
P(GeneA) = 0.5
P(GeneB) = 0.5
P(GeneC | GeneA, GeneB) = 0.9
P(GeneC | GeneA, ¬GeneB) = 0.15
P(GeneC | ¬GeneA, GeneB) = 0.25
P(GeneC | ¬GeneA, ¬GeneB) = 0
P(GeneD | ¬GeneC) = 0.9
P(GeneD | GeneC) = 0.05
A gene may be in a state of “on” (=1) or “off (=0). Given this information, draw the full conditional probability tables for the following probability distributions: P(GeneA), P(GeneB), P(GeneC), and P(GeneD). (1 mark)
(c) Use the variable elimination algorithm to calculate the probability that gene A is “on” given that we have found that gene D is “on”. I.e., What is P(GeneA | GeneD)? Show all working. (3 marks)