9.3 Sequential Decisions

The third edition of Artificial Intelligence: foundations of computational agents, Cambridge University Press, 2023 is now available (including full text).

9.3.3 Variable Elimination for Decision Networks

Fortunately, an agent does not have to enumerate all of the policies; variable elimination (VE) can be adapted to find an optimal policy. The idea is first to consider the last decision, find an optimal decision for each value of its parents, and produce a factor of these maximum values. This results in a new decision network, with one less decision, that can be solved recursively.

1: procedure VE_DN(D⁢N):
2:      Inputs
3:          D⁢N a decision network      
4:      Output
5:          An optimal policy and its expected utility
6:      Local
7:          D⁢F⁢s: a set of decision functions, initially empty
8:          F⁢s: a set of factors      
9:      Remove all variables that are not ancestors of the utility node
10:      Create a factor in F⁢s for each conditional probability
11:      Create a factor in F⁢s for the utility
12:      while there are decision nodes remaining do
13:          Sum out each random variable that is not a parent of a decision node
14:          Let D be the last decision remaining
15:          ▷ D is only in a factor F⁢(D,V1,…⁢Vk) where V1⁢…⁢Vk are parents of D
16:          Add maxD⁡F to F⁢s.
17:          Add arg⁡maxD⁡F to D⁢F⁢s.      
18:      Sum out all remaining random variables
19:      Return D⁢F⁢s and the product of remaining factors
Figure 9.13: Variable elimination for decision networks

Figure 9.13 shows how to use variable elimination for decision networks. Essentially, it computes the expected utility of an optimal decision. It eliminates the random variables that are not parents of a decision node by summing them out according to some elimination ordering. The ordering of the random variables being eliminated does not affect correctness and so it can be chosen for efficiency.

After eliminating all of the random variables that are not parents of a decision node, in a no-forgetting decision network, there must be one decision variable D that is in a factor F where all of the variables, other than D, in F are parents of D. This decision D the last decision in the ordering of decisions.

To eliminate that decision node, V⁢E⁢_⁢D⁢N chooses the values for the decision that result in the maximum utility. This maximization creates a new factor on the remaining variables and a decision function for the decision variable being eliminated. This decision function created by maximizing is one of decision functions in an optimal policy.

Example 9.19.

In Example 9.13, there are three initial factors representing P⁢(W⁢e⁢a⁢t⁢h⁢e⁢r), P⁢(F⁢o⁢r⁢e⁢c⁢a⁢s⁢t∣W⁢e⁢a⁢t⁢h⁢e⁢r), and u⁢(W⁢e⁢a⁢t⁢h⁢e⁢r,U⁢m⁢b⁢r⁢e⁢l⁢l⁢a). First, it eliminates W⁢e⁢a⁢t⁢h⁢e⁢r by multiplying all three factors and summing out W⁢e⁢a⁢t⁢h⁢e⁢r, giving a factor on F⁢o⁢r⁢e⁢c⁢a⁢s⁢t and U⁢m⁢b⁢r⁢e⁢l⁢l⁢a,

F⁢o⁢r⁢e⁢c⁢a⁢s⁢t U⁢m⁢b⁢r⁢e⁢l⁢l⁢a Value
s⁢u⁢n⁢n⁢y t⁢a⁢k⁢e⁢_⁢i⁢t 12.95
s⁢u⁢n⁢n⁢y l⁢e⁢a⁢v⁢e⁢_⁢i⁢t 49.0
c⁢l⁢o⁢u⁢d⁢y t⁢a⁢k⁢e⁢_⁢i⁢t 8.05
c⁢l⁢o⁢u⁢d⁢y l⁢e⁢a⁢v⁢e⁢_⁢i⁢t 14.0
r⁢a⁢i⁢n⁢y t⁢a⁢k⁢e⁢_⁢i⁢t 14.0
r⁢a⁢i⁢n⁢y l⁢e⁢a⁢v⁢e⁢_⁢i⁢t 7.0

To maximize over U⁢m⁢b⁢r⁢e⁢l⁢l⁢a, for each value of F⁢o⁢r⁢e⁢c⁢a⁢s⁢t, V⁢E⁢_⁢D⁢N selects the value of U⁢m⁢b⁢r⁢e⁢l⁢l⁢a that maximizes the value of the factor. For example, when the forecast is s⁢u⁢n⁢n⁢y, the agent should leave the umbrella at home for a value of 49.0.

V⁢E⁢_⁢D⁢N constructs an optimal decision function for U⁢m⁢b⁢r⁢e⁢l⁢l⁢a by selecting a value of U⁢m⁢b⁢r⁢e⁢l⁢l⁢a that results in the maximum value for each value of F⁢o⁢r⁢e⁢c⁢a⁢s⁢t:

F⁢o⁢r⁢e⁢c⁢a⁢s⁢t U⁢m⁢b⁢r⁢e⁢l⁢l⁢a
s⁢u⁢n⁢n⁢y l⁢e⁢a⁢v⁢e⁢_⁢i⁢t
c⁢l⁢o⁢u⁢d⁢y l⁢e⁢a⁢v⁢e⁢_⁢i⁢t
r⁢a⁢i⁢n⁢y t⁢a⁢k⁢e⁢_⁢i⁢t

It also creates a new factor that contains the maximal value for each value of F⁢o⁢r⁢e⁢c⁢a⁢s⁢t:

F⁢o⁢r⁢e⁢c⁢a⁢s⁢t V⁢a⁢l⁢u⁢e
s⁢u⁢n⁢n⁢y 49.0
c⁢l⁢o⁢u⁢d⁢y 14.0
r⁢a⁢i⁢n⁢y 14.0

It now sums out F⁢o⁢r⁢e⁢c⁢a⁢s⁢t from this factor, which gives the value 77.0. This is the expected value of the optimal policy.

Example 9.20.

Consider Example 9.15. Before summing out any variables it has the following factors:

M⁢e⁢a⁢n⁢i⁢n⁢gF⁢a⁢c⁢t⁢o⁢rP⁢(T⁢a⁢m⁢p⁢e⁢r⁢i⁢n⁢g)f0⁢(T⁢a⁢m⁢p⁢e⁢r⁢i⁢n⁢g)P⁢(F⁢i⁢r⁢e)f1⁢(F⁢i⁢r⁢e)P⁢(A⁢l⁢a⁢r⁢m∣T⁢a⁢m⁢p⁢e⁢r⁢i⁢n⁢g,F⁢i⁢r⁢e)f2⁢(T⁢a⁢m⁢p⁢e⁢r⁢i⁢n⁢g,F⁢i⁢r⁢e,A⁢l⁢a⁢r⁢m)P⁢(S⁢m⁢o⁢k⁢e∣F⁢i⁢r⁢e)f3⁢(F⁢i⁢r⁢e,S⁢m⁢o⁢k⁢e)P⁢(L⁢e⁢a⁢v⁢i⁢n⁢g∣A⁢l⁢a⁢r⁢m)f4⁢(A⁢l⁢a⁢r⁢m,L⁢e⁢a⁢v⁢i⁢n⁢g)P⁢(R⁢e⁢p⁢o⁢r⁢t∣L⁢e⁢a⁢v⁢i⁢n⁢g)f5⁢(L⁢e⁢a⁢v⁢i⁢n⁢g,R⁢e⁢p⁢o⁢r⁢t)P⁢(S⁢e⁢e⁢_⁢s⁢m⁢o⁢k⁢e∣C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e,S⁢m⁢o⁢k⁢e)f6⁢(S⁢m⁢o⁢k⁢e,S⁢e⁢e⁢_⁢s⁢m⁢o⁢k⁢e,C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e)u⁢(F⁢i⁢r⁢e,C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e,C⁢a⁢l⁢l)f7⁢(F⁢i⁢r⁢e,C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e,C⁢a⁢l⁢l)

The expected utility is the product of the probability and the utility, as long as the appropriate actions are chosen.

V⁢E⁢_⁢D⁢N sums out the random variables that are not parents of a decision node. Thus, it sums out T⁢a⁢m⁢p⁢e⁢r⁢i⁢n⁢g, F⁢i⁢r⁢e, A⁢l⁢a⁢r⁢m, S⁢m⁢o⁢k⁢e, and L⁢e⁢a⁢v⁢i⁢n⁢g. After these have been eliminated, there is a single factor, part of which (to two decimal places) is:

R⁢e⁢p⁢o⁢r⁢t S⁢e⁢e⁢_⁢s⁢m⁢o⁢k⁢e C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e C⁢a⁢l⁢l Value
t⁢r⁢u⁢e t⁢r⁢u⁢e y⁢e⁢s y⁢e⁢s -1.33
t⁢r⁢u⁢e t⁢r⁢u⁢e y⁢e⁢s n⁢o -29.30
t⁢r⁢u⁢e t⁢r⁢u⁢e n⁢o y⁢e⁢s 0
t⁢r⁢u⁢e t⁢r⁢u⁢e n⁢o n⁢o 0
t⁢r⁢u⁢e f⁢a⁢l⁢s⁢e y⁢e⁢s y⁢e⁢s -4.86
t⁢r⁢u⁢e f⁢a⁢l⁢s⁢e y⁢e⁢s n⁢o -3.68
… … … … …

From this factor, an optimal decision function can be created for C⁢a⁢l⁢l by selecting a value for C⁢a⁢l⁢l that maximizes V⁢a⁢l⁢u⁢e for each assignment to R⁢e⁢p⁢o⁢r⁢t, S⁢e⁢e⁢_⁢s⁢m⁢o⁢k⁢e, and C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e.

Consider the case when R⁢e⁢p⁢o⁢r⁢t=t⁢r⁢u⁢e, S⁢e⁢e⁢_⁢s⁢m⁢o⁢k⁢e=t⁢r⁢u⁢e, and C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e=y⁢e⁢s. The maximum of -1.33 and -29.3 is -1.33, so for this case, the optimal action is C⁢a⁢l⁢l=y⁢e⁢s with value -1.33. This maximization is repeated for the other values of R⁢e⁢p⁢o⁢r⁢t, S⁢e⁢e⁢_⁢s⁢m⁢o⁢k⁢e and C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e.

An optimal decision function for C⁢a⁢l⁢l is

R⁢e⁢p⁢o⁢r⁢t S⁢e⁢e⁢_⁢s⁢m⁢o⁢k⁢e C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e C⁢a⁢l⁢l
t⁢r⁢u⁢e t⁢r⁢u⁢e y⁢e⁢s y⁢e⁢s
t⁢r⁢u⁢e t⁢r⁢u⁢e n⁢o y⁢e⁢s
t⁢r⁢u⁢e f⁢a⁢l⁢s⁢e y⁢e⁢s n⁢o
… … … …

The value for C⁢a⁢l⁢l when R⁢e⁢p⁢o⁢r⁢t=t⁢r⁢u⁢e, S⁢e⁢e⁢_⁢s⁢m⁢o⁢k⁢e=t⁢r⁢u⁢e and C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e=n⁢o is arbitrary. It does not matter what the agent plans to do in this situation, because the situation never arises. The algorithm does not need to treat this as a special case.

The factor resulting from maximizing C⁢a⁢l⁢l contains the maximum values for each combination of R⁢e⁢p⁢o⁢r⁢t, S⁢e⁢e⁢_⁢s⁢m⁢o⁢k⁢e, and C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e:

R⁢e⁢p⁢o⁢r⁢t S⁢e⁢e⁢_⁢s⁢m⁢o⁢k⁢e C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e Value
t⁢r⁢u⁢e t⁢r⁢u⁢e y⁢e⁢s -1.33
t⁢r⁢u⁢e t⁢r⁢u⁢e n⁢o 0
t⁢r⁢u⁢e f⁢a⁢l⁢s⁢e y⁢e⁢s -3.68
… … … …

Summing out S⁢e⁢e⁢_⁢s⁢m⁢o⁢k⁢e gives the factor

R⁢e⁢p⁢o⁢r⁢t C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e Value
t⁢r⁢u⁢e y⁢e⁢s -5.01
t⁢r⁢u⁢e n⁢o -5.65
f⁢a⁢l⁢s⁢e y⁢e⁢s -23.77
f⁢a⁢l⁢s⁢e n⁢o -17.58

Maximizing C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e for each value of R⁢e⁢p⁢o⁢r⁢t gives the decision function

R⁢e⁢p⁢o⁢r⁢t C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e
t⁢r⁢u⁢e y⁢e⁢s
f⁢a⁢l⁢s⁢e n⁢o

and the factor

R⁢e⁢p⁢o⁢r⁢t Value
t⁢r⁢u⁢e -5.01
f⁢a⁢l⁢s⁢e -17.58

Summing out R⁢e⁢p⁢o⁢r⁢t gives the expected utility of -22.60 (taking into account rounding errors).

Thus, the policy returned can be seen as the rules

c⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e←⁢r⁢e⁢p⁢o⁢r⁢t.
c⁢a⁢l⁢l←⁢s⁢e⁢e⁢_⁢s⁢m⁢o⁢k⁢e.
c⁢a⁢l⁢l←⁢r⁢e⁢p⁢o⁢r⁢t∧⁢¬⁢c⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e∧⁢¬⁢s⁢e⁢e⁢_⁢s⁢m⁢o⁢k⁢e.

The last of these rules is never used because the agent following the optimal policy does check for smoke if there is a report. It remains in the policy because V⁢E⁢_⁢D⁢N has not determined an optimal policy for C⁢h⁢e⁢c⁢k⁢_⁢s⁢m⁢o⁢k⁢e when it is optimizing C⁢a⁢l⁢l.

Note also that, in this case, even though checking for smoke has an immediate negative reward, checking for smoke is worthwhile because the information obtained is valuable.

The following example shows how the factor containing a decision variable can contain a subset of its parents when the VE algorithm optimizes the decision.

Example 9.21.

Consider Example 9.13, but with an extra arc from W⁢e⁢a⁢t⁢h⁢e⁢r to U⁢m⁢b⁢r⁢e⁢l⁢l⁢a. That is, the agent gets to observe both the weather and the forecast. In this case, there are no random variables to sum out, and the factor that contains the decision node and a subset of its parents is the original utility factor. It can then maximize U⁢m⁢b⁢r⁢e⁢l⁢l⁢a, giving the decision function and the factor:

W⁢e⁢a⁢t⁢h⁢e⁢r U⁢m⁢b⁢r⁢e⁢l⁢l⁢a
n⁢o⁢r⁢a⁢i⁢n l⁢e⁢a⁢v⁢e⁢_⁢i⁢t
r⁢a⁢i⁢n t⁢a⁢k⁢e⁢_⁢i⁢t
W⁢e⁢a⁢t⁢h⁢e⁢r V⁢a⁢l⁢u⁢e
n⁢o⁢r⁢a⁢i⁢n 100
r⁢a⁢i⁢n 70

Note that the forecast is irrelevant to the decision. Knowing the forecast does not give the agent any useful information. Summing out F⁢o⁢r⁢e⁢c⁢a⁢s⁢t gives a factor where all of the values are 1.

Summing out W⁢e⁢a⁢t⁢h⁢e⁢r, where P(Weather=norain)=0.7, gives the expected utility 0.7*100+0.3*70=91.