109
Stuart Russell & Peter Norvig „ARTIFICIAL INTELLIGENCE: A MODERN APPROACH” 2nd edition Uzdevumu brošūra Brošūrā apkopoti uzdevumi no otrā Rasela un Norviga grāmatas izdevuma (2002.g.).

2nd Edition Broshuura Izlase

Embed Size (px)

DESCRIPTION

2nd Edition Broshuura Izlase

Citation preview

Stuart Russell & Peter Norvig

Stuart Russell & Peter NorvigArtificial Intelligence:A Modern Approach

2nd edition

Uzdevumu brora

Bror apkopoti uzdevumi no otr Rasela un Norviga grmatas izdevuma (2002.g.). Uzdevumi ir oriinlvalod, saglabjot grmat lietoto uzdevumu un attlu numerciju. Bror ir pasvtrotas un ar treknrakstu izceltas nordes uz tm grmatas dam, kuras bror nav iekautas.

Nr.UzdevumsPunktu skaits

Intelligent Agents

2.4.Let us examine the rationality of various vacuum-cleaner agent functions.

a)Show that the simple vacuum-cleaner agent function described in Figure 2.3. is indeed rational under the assumptions listed on page 36.

b)Describe a rational agent function for the modified performance measure that deducts one point for each movement. Does the corresponding agent program require internal state?

c)Discuss possible agent design for the cases in which clean squares can become dirty and the geography of the environment is unknown. Does it make sense for the agent to learn from its experience in these cases? If so, what should it learn?

1

2.5.For each of the following agents, develop a PEAS description of the task environment:

a)Robot soccer player;

b)Internet book-shopping agent;

c)Autonomous Mars rover;

d) Mathematicians theorem-proving assistant.1

2.6.For each of the agent types listed in Exercise 2.5., characterize the environment according to the properties given in Section 2.3. and select a suitable agent design. The following exercises all concern the implementation of environments and agents for the vacuum cleaner world.1

2.8.Uzdevums jizpilda ar datoru.Implement a simple reflex agent for the vacuum environment in Exercise 2.7. Run the environment simulator with this agent for all possible initial dirt configurations and agent locations. Record the agents performance score for each configuration and its overall average score.5 (ar datoru)

2.9.Consider the modified version of the environment in Exercise 2.7. in which the agent is penalized one point for each movement.

a)Can a simple reflex agent be perfectly rational for this environment? Explain.

b)What about a reflex agent with state? Design such an agent.

c)How do you answer to a and b change if the agents percepts give it clean/dirty status of every square in the environment?2

2.10.Uzdevuma ceturtais punkts jizpilda ar datoru.Consider a modified version of the vacuum environment in Exercise 2.7. in which the geography of the environment- its extent, boundaries and obstacles- is unknown, as is the initial dirt configuration. (The agent can go Up and Down as well as Left and Right).

a)Can a simple reflex agent be perfectly rational for this environment? Explain.

b)Can a simple reflex agent with a randomized agent function outperform a simple reflex agent? Design such an agent and measure its performance on several environments.

c)Can you design an environment in which your randomized agent will perform very poorly? Show your results.

d)Can a reflex agent with state outperform a simple reflex agent? Design such an agent and measure its performance on several environments. Can you design a rational agent of this type?3 (4 ja ar datoru)

2.12.The vacuum environments in the preceding exercises have all been deterministic. Discuss possible agent programs for each of the following stochastic versions:

a)Murphys law: twenty-five percent of the time, the Suck action fails to clean the floor if it is dirty and deposits dirt onto the floor if the floor is clean. How is your agent program affected if the dirt sensor gives the wrong answer 10% of the time?

b)Small children: At each time step, each clean square has a 10% chance of becoming dirty. Can you come up with a rational agent design for this case?1

3.3.Suppose that LEGAL-ACTIONS(s) denotes the set of actions that are legal in state s and RESULT (a,s) denotes the state that results from performing a legal action a in state s. Define SUCCESSOR-FN in terms of LEGAL-ACTIONS and RESULT, and vice versa.1

3.5.Consider the n-queens problem using the efficient incremental formulation given on page 67. Explain why the space size is at least and estimate the largest n for which exhaustive exploration is feasible. (Hint: Derive a lower bound on the branching factor by considering the maximum number of squares that a queen can attack in any column.)2

3.6.(Adapted from Bender 1996)Does a finite state space always lead to a finite search tree? How about a finite state space that is a tree? Can you be more precise about what types of state spaces always lead to finite search trees? 1

3.8.Consider a state space where the start state is number 1 and the successor function for state n returns two states, number 2n and 2n+1 a)Draw the portion of the state space for states 1 to 15.

b)Suppose the goal state is 11. List the order in which nodes will be visited for breath-first search, depth-limited search with limit 3, and iterative deeping search.

c)Would bidirectional search be appropriate for this problem? If so, describe in detail how it would work.

d)What is the branching factor in each direction of the bidirectional search?

e)Does the answer to (c) suggest a reformulation of that would allow you to solve the problem of getting from state 1 to a given goal state with almost no search?2

3.9.(Amarel, 1968).

The missionaries and cannibals problem is usually stated as follows. Three missionaries and three cannibals are on one side of the river, along with a boat that can hold one or two people. Find a way to get everyone to the other side, without ever leaving a group of missionaries in one place outnumbered by the cannibals in that place. This problem is famous in AI because it was the subject of the first paper that approached problem formulation from an analytical viewpoint.1

3.10.Implement two versions of the successor function for the 8-puzzle: one that generates all the successors at once by copying and editing the 8-puzzle data structure, and one that generates one new successor each time it is called and works by modifying the parent state directly (and undoing the modifications as needed) Write versions of iterative deeping depth-first search that use these functions and compare their performance.4

3.11.On page 79 we mentioned iterative lengthening search, an iterative analog of inform cost search. The idea is to use increasing limits on path cost. If a node is generated whose path cost exceeds the current limit, it is immediately discarded. For each new iteration, the limit is set to the lowest path cost of any node discarded in the previous iteration.

a)Show that this algorithm is optimal for general path costs.

b)Consider a uniform tree with branching factor b, solution depth d and unit step costs. How many iterations will iterative lengthening require?

c)Now consider step costs draw from the continuous range [0,1] with a minimum positive cost e. How many iterations are required in the worst case?

d)Implement the algorithm and apply it to instances of the 8-puzzle and traveling salesperson problem. Compare the algorithms performance to that of uniform-cost search, and comment on your results.3 (ja nav izpildts d punkts)/5 (ja visi punkti ir izpildti)

3.14.Write a program that will take as input two Web page URLs and find a path of links from one to the other. What is an appropriate search strategy? Is bidirectional search a good idea? Can a search engine be used to implement a predecessor function?3

3.15.Consider the problem of finding the shortest path between two points on a plane that has convex polygonal obstacles as shown in Figure 3.22. This is an idealization of the problem that a robot has to solve to navigate its way around a crowded environment.

a)Suppose the state space consists of all positions (x,y) in the plane. How many states are there? How many paths are there on the goal?

b)Explain briefly why the shortest path from one polygon vertex to any other in the scene must consist of straight-line segments joining some of the vertices of the polygons. Define a good state space now. How large is this state space?

c)Define the necessary functions to implement the search problem, including a successor function that takes a vertex input and returns the set of vertices that can be reached in a straight line from the given vertex. (Do not forget the neighbors on the same polygon) Use the straight-line distance for the heuristic function).d)Apply one or more of the algorithm in chapter 3 solve a range of problems in the domain and comment on their performance.

4

3.16.We can turn the navigation problem in Exercise 3.15. into an environment as follows:

The percept will be a list of the position relative to the agent, of the visible vertices. The percept does not include the position of the robot! The robot must learn its own position from the map; for now you can assume that each location has a different view.

Each action will be a vector describing a straight-line path to follow. If the path is unobstructed, the action succeeds otherwise, the robot stops at the point where its path first intersects an obstacle. If the agent returns zero motion vector and is at the goal (which is fixed and known), then the environment should teleport the agent to a random location (not inside an obstacle). The performance measure charges the agent 1 point for each unit of distance traversed and awards 1000 points each time the goal is reached.

a)Implement this environment and a problem solving agent for it. The agent will need to formulate a new problem after each teleportation, which will involve discovering its current location.

b)Document your agents performance (by having the agent generate suitable commentary as it moves around) and report its performance over 100 episodes.

c)Modify the environment so that 30% of time the agent ends up at an unintended destination (chosen randomly from the other visible vertices if any, otherwise no move at all). This is a crude model of the motion errors of a real robot. Modify the agent so that when such an error is detected it finds out where it is and then constructs a plan to get back to where it was and resume the old plan. Remember that sometimes plan getting back to where it was might also fail! Show an example of the agent successfully overcoming two successive motion errors and still reaching the goal.

d)Now try two different recovery schemes after an error: (1) Head for the closest vertex on the original route; and (2) replan a route to the goal from a new location. Compare the performance in three recovery schemes. Would the inclusion of search costs affect the comparison?

e)Now suppose that there are locations from which the views is identical (For example, suppose the world is a grid with square obstacles) What kind of problem does the agent now face? What do solutions look like?5

3.17.On page 62 we said that we would not consider problems with negative path costs. In this exercise, we explore this in more depth.

a)Suppose that action can have arbitrary large negative costs; explain why this possibility would force any optimal algorithm to explore the entire state space.

b)Does it help if we insist that step costs must be greater than or equal to some negative constant c? Consider both trees and graphs.

c)Suppose that there is a set of operators with high negative cost, even in domain such as route finding. For example, some stretches of road might have such beautiful scenery as to far outweight the normal costs in terms of time and fuel. Explain, in precise terms, within the context of state-space search, why humans do not drive round scenic loops indefinitely, and explain how to define the state space and operators for route finding so that artificial agents can also avoid looping.

e)Can you think of a real domain in which step costs are such as to cause looping?2

3.19.Consider the vacuum-world problem defined in Figure 2.2.

a)Which of the algorithms defined in chapter 4 would be appropriate for this problem? Should the algorithm check for repeated states?

b)Apply your chosen algorithm to compute an optimal sequence of actions for 3 ( 3 world whose initial state has dirt in the three top squares and the agent in the center.

c)Construct a search agent for the vacuum world, and evaluate its performance in a set of 3 ( 3 worlds with probability 0.2 of dirt in each square. Include the search cost as well as path cost in the performance measure, using a reasonable exchange rate.

d)Compare your best search agent with a simple randomized reflex agent that sucks if there is dirt and otherwise moves randomly.

e)Consider what would happen if the world were enlarged to n ( n. How does the performance of the search agent and of the reflex agent vary with n?5

4.1.Trace the operation A* search applied to the problem of getting to Bucharest from Lugoj using the straight-line distance heuristic. That is show the sequence of nodes that the algorithm will consider and the f, g, and h score for each node.1

4.2.The heuristic path algorithm is a best-first search in which the objective function is f(n)=(2-w)g(n)+wh(n). For what values of w is this algorithm guaranteed to be optimal? What kind of search does this perform when w=0? When w=1? When w=2?2

4.3.Prove each of the following statements:

a)Breadth-first search is a special case of uninform-cost search.

b)Breadth-first search, depth-first search, and uniform-cost search are special cases of best-first.

c)Uniform-cost search is a special case of A* search.2

5.7.Figure 5.5. tests out various algorithms on the n-queens problem. Try these same algorithms on map-coloring problems generated randomly as follows: scatter n points on the unit square; selecting a point X at random, connect X by a straight line to the nearest point Y such that X is not already connected to Y and the line crosses no other line; repeat the previous step until no more connections are possible. Construct the performance table for the largest n you can manage, using both d=3 and d=4 colors. Comment on your results.

3

5.13.Consider the following logic puzzle: In five houses, each with a different color, live 5 persons of different nationalities, each of whom prefer a different brand of cigarette, a different drink and own a different pet. Given the following facts, the question to answer is Where does the zebra live, and in which house do they drink water? The Englishman lives in the red house.

The Spaniard owns the dog.

The Norwegian lives in the first house on the left.

Kools are smoked in the yellow house.

The man who smokes Chesterfields lives in the house next to the man with the fox.

The Norwegian lives next to the blue house.

The Winston smoker owns snails.

The Lucky Strike smoker drinks orange juice.

The Ukrainian drinks tea.

The Japanese smokes Parliament.

Kools are smoked in the house next to the house where the horse is kept.

Coffee is drunk in the green house.

The Green house is immediately to the right (your right) to the ivory house.

Milk is drunk in the middle house.

Discuss different representations of this problem as CSP. Why would one prefer one representation over another?3

6.3.Consider the two player game description in Figure 6.14.a)Draw the complete game tree, using the following conventions:

Write each state as (sA, sB) where sA and sB denote the token in a circle.

Put each terminal state in a square boxes and write its game value in a circle.

Put loop states (states that already appear on the path to the root) in double square boxes. Since it is not clear how to assign values to loop states, annotate each with a ? in a circle.

b)Now mark each node with its backed-up minimax value (also in a circle). Explain how you handle the ? values and why.c)Explain why the standard minimax algorithm would fail on this game tree and briefly sketch how you might fix it, drawing on your answer to (b). Does your modified algorithm give optimal decisions for all games with loops?

d)This 4-square game can be generalized to n squares for any n>2. Prove that A wins if n is even and loses if n is odd.

3

6.7.Prove that with a positive linear transformation of leaf values (i.e., transforming a value x to ax+b where a>0), the choice of move remains unchanged in a game tree, even when there are chance nodes.1

6.9.Describe and implement a real-time, multiplayer game- playing environment, where time is part of the environment state and players are given fixed time allocations.1(ja uzdevums izpildts ar roku)/3(ja uzdevums izpildts ar datoru)

6.12.The minimax algorithm assumes that players take turns moving, but in card games such as whist and bridge, the winner of the previous trick plays on the next trick.

a)Modify the algorithm to work properly for these games. You may assume that a function WINNER (trick) is available that reports which card wins a given trick.zb)Draw the game tree for the first pair of hands shown on page 179.2

7.2.Suppose the agent has progressed to the point shown in Figure 7.4.(a), having perceived nothing in [1,1], a breeze in [2,1] and a stench in [1,2], and is now concerned with the contents of [1,3], [2,2], [3,1]. Each of these can contain a pit and at most one can contain a wumpus. Following the example of Figure 7.5. construct the set of possible worlds (You should find 32 of them) Mark the worlds in which the KB is true and those in which each of the following sentences is true:

a2=There is no pit in [2,2]

a3=There is no wumpus in [1,3]

Hence show that KB |= a2 and KB |= a3

2

7.5.Consider a vocabulary with only four propositions, A, B., C and D. How many models are there for the following sentences?a)(A(B)((B(C)

b)A(B

c)A(B(C1

7.11.Minesweeper, the well-known computer game, is closely related to the wumpus world. A minesweeper is a rectangular grid of N squares with M invisible mines scattered among them. Any square may be probed by the agent; instant death follows if a mine is probed. Minesweeper indicates the presence of mines by revealing, in each probed square, the number of mines that are directly or diagonally adjacent. The goal is to have probed every unmined square.

a)Let Xij be true if square [i,j] contains a mine. Write down the assertion that there are exactly two mines adjacent to [1,1] as a sentence involving some logical combination or Xij propositions.

b)Generalize your assertion from (a) by explaining how to construct a CNF sentence asserting that k of n neighbors contain mines.

c)Explain precisely how an agent can use DPLL to prove that a given square does (or does not) contain a mine, ignoring the global constraint that there are exactly M mines at all.

d)Suppose that the global constraint is constructed via your method from part (b). How does the number of clauses depend on M and N? Suggest a way to modify DPLL so that the global constraint does not need to be represented explicitly.

e)Are any conclusions derived by the method in part (c) invalidated when the global constraint is taken into account?

f)Give examples of configurations of probe values that induce long-range dependencies such that the content of a given unprobed square would give information about the contents of far-distant square[Hint: consider an N ( 1 board].3

7.12.This exercise looks into the relationship between clauses and implication sentences.a)Show that the clause ((P1(((Pm(Q) is logically equivalent to the implication sentence (P1(( Pm)(Q.

b)Show that every clause (regardless of the number of positive literals) can be written in the form (P1(( Pm)((Q1(( Qn), where the Ps and Qs are proposition symbols. A knowledge base consisting of such sentences is in implicative nominal form or Kowalski form.

c)Write down the full resolution rule for sentences in implicative nominal form.2

8.6.Represent the following sentences in first-order logic, using a consistent vocabulary (which you must define):

a)Some students took French in spring 2001.

b)Every student who takes French passes it.

c)Only one student took Greek in spring 2001.

d)The best score in Greek is always higher than the best score in French.e)Every person who buys a policy is smart.

f)No person buys an expensive policy.

g)There is an agent who sells policies only to people who are not insured.

h)There is a barber who shaves all men in town who do not shave themselves.

i)A person born in the UK each of whose parents is a UK citizen or a UK resident, is a UK citizen by birth.

j)A person born outside the UK, one of whose parents is a UK citizen by birth, is a UK citizen by descent.

k)Politicians can fool some of the people all of the time, and they can fool all of the people some of the time, but they cant fool all of the people all of the time.3

8.8.What axioms is needed to infer the fact Female(Laura) given the fact Male(Jim) and Spouse(Jim, Laura)?1

8.9.Write a general set of facts and axioms to represent the assertion Wellington heard about Napoleons death and to correctly answer the question Did Napoleon hear about Wellingtons death?1

8.16.Write out the axioms required for reasoning about the wumpuss location, using a constant symbol Wumpus and a binary predicate In(Wumpus, Location). Remember that there is only one wumpus.1

8.19.Obtain a passport application for your country, identify the rules determining eligibility for passport, and translate them into first-order logic, following the steps outlined in Section 8.4.1

9.3.Suppose a knowledge base contains just one sentence, (x AsHighAs(x, Everest). Which of the following are legitimate results of applying Existential Instantiation:

a)AsHighAs(Everest, Everest).

b)AsHighAs(Kilimanjaro, Everest).

c)AsHighAs(Kilimanjaro, Everest) ( AsHighAs(BenNevis, Everest) (after two applications).1

9.5.Consider the subsumption lattices shown in Figure 9.2.a)Construct the lattice for the sentence Employs (Mother(John), Father(Ritchard)).

b)Construct the lattice for the sentences Employs(IBM, y)(Everyone works for IBM). Remember to include every kind of query that unifies with the sentence.

c)Assume that STORE indexes each sentence under every node in its subsumption lattice. Explain how FETCH should work when some of these sentences contain variables; use as examples the sentences in (a) and (b) and the query Employs(x, Father(x)).

2

10.2.Within situation calculus write an axiom to associate time 0 with the situation S0 and another axiom to associate the time t with any situation that is derived form S0 by a sequence of t actions.1

10.6.Write definitions for the following:a)ExhaustivePartDecomposition

b)PartPartition

c)PartwiseDisjointThese should be analogous to those for ExhaustiveDecomposition, Partion and Disjoint.

Is it the case that PartPartition(s, BunchOf(s))? If so, prove it; if not, give a counterexample and define sufficient conditions under which it does hold.1

10.14.One part of the shopping process that was not covered in chapter 10 is checking for compatibility between items. For example if a customer orders a computer, is it matched with the right peripherals? If a digital camera is ordered, does it have the right memory card and batteries? Write a knowledge base that will decide whether a set of items is compatible and that can be used to suggest replacements or additional items if they are not compatible. Make sure that the knowledge base works with at least one line of products, and is easily extensible to other lines.2

10.15.Add rules to extend the definition of the predicate Name(s,c) so that string such as laptop computer matches against the appropriate category names from a variety of stores. Try to make your definition general. Test it by looking at ten online stores, and at the category names they give for three different categories. For example, for the category of laptops, we found the names Notebooks, Laptops, Notebook Computers, Notebook, Laptops and Notebooks and Notebook PCs. Some of these can be covered by explicit Name facts, while others could be covered by rules for handling plurals, conjunctions, etc.2

10.16.A complete solution to the problem of inexact matches to the buyers description in shopping is very difficult and requires a full array of natural language processing and information retrieval techniques (See Chapter 22 and 23) One small step is to allow the user to specify minimum and maximum values for various attributes. We will insist that the buyer use the following grammar for product descriptions:

Description ( Category| Connector Modifier |*

Connector ( with | and | .

Modifier ( Atribute | Atribute Op Value

Op ( =|>|2.5 GHz and price