Logical Agent Wrapup

Finally after much work (and admittedly glossing over some details), we have enough to build an agent for the Wumpus World

Step one: allow the agent to derive the state of the world (as far as needed) by its percept history.

(This requires a logical model of how actions affect the environment)

Step two: Allow the agent to keep track of the state of the world without recomputing the percept sequence.

Step three: Allow the agent to construct plans that are sure to work (provided its knowledge is true)

Current state of the world

As a knowledge-based agent, all we have to go on is our KB.

All that’s in our KB are either “axioms” – general knowledge about the world, or our percept sequence.

What are things relevant to know?

Give me some examples of axioms

We know things like: (\(\lnot P_{1,1}\)) and (\(\lnot W_{1,1}\))

We also know that if we smell a stench, then the Wumpus has to be nearby and if we feel a breeze, then there must be a pit nearby. We populate our KB with lots of these sentences:

\[ B_{1,1}\iff\ (P_{1,2}\lor P_{2,1})\\ S_{1,1}\iff\ (W_{1,2}\lor W_{2,1})\\ ... \]

We also know there’s exactly one Wumpus,

how might we say that, logically?

That is to say, there’s at least one Wumpus:

\[ W_{1,1}\lor W_{1,2}\lor\ ...\lor\ W_{4,3}\lor W_{4,4} \]

and there’s at most one Wumpus:

\[ \lnot W_{1,1} \lor \lnot W_{1,2}\\ \lnot W_{1,1} \lor \lnot W_{1,3}\\ ...\\ \lnot W_{4,3} \lor \lnot W_{4,4}\\ \]

Now we have to deal with the percepts…

If we detect a stench in space \([1,1]\), how might we denote that?

  • \(S_{1,1}\) or \(Stench\)
  • Except… no we can’t

If we detect \(Stench\) now, but hadn’t in the last step \(\lnot Stench\) would already be asserted, causing a contridiction.

How can we deal with this

You cannot have meaningful Artificial Intelligence if strict timekeeping is not kept

If the timestep (as given to \(MakePerceptSequence\)) is \(4\), then \(Stench^4\) would be added, not conflicting with \(\lnot Stench^3\)

This goes for all percepts

E.g. at time step 0, the knowledge added to our KB is \(L_{1,1}^0, FacingEast^0,HaveArrow^0, WumpusAlive^0\).

Fluent, “state variable”, describes any aspect of the world that changes.

Anything that doesn’t change with time is called atemporal and doesn’t need a superscript.

This observation allows us to link percepts that were collected in time with features of the square that don’t change.

For any time step \(t\), and square \([x,y]\), we can assert:

\[ L_{x,y}^t \implies (Breeze^t \iff\ B_{x,y})\\ L_{x,y}^t \implies (Stench^t \iff\ S_{x,y})\\ \]

We need axioms to help keep track of fluents (which change as result of our actions) like \(L^t_{x,y}\), so we need to write down a transition model…

Now we need proposition symbols for actions (indexed by time). \(Forward^0\) means the agent moves \(Forward\) at time \(0\).

Effect axioms specify the outcome of an action (next time step). What might this axiom mean?

\[ L^0_{1,1}\land FacingEast^0\land Forward^0 \implies\ (L^1_{2,1}\land \lnot L^1_{1,1}) \]

We would need one of these per time step and each square and each direction.

Let’s say that the agent decides to move \(Forward\) at time \(0\)what happens?

If I ask \(Ask(KB,L^1_{2,1})\) what do I get back?

  • \(true\)

What about \(Ask(KB,HaveArrow^1)\)?

  • \(false\)
  • We can’t prove we have it, can’t prove we don’t have it.

This gives rise to the frame problem, what things remain unchanged from an action?

One solution is frame axioms: \[ Forward^t \implies\ (HaveArrow^t \iff HaveArrow^{t+1})\\ Forward^t \implies\ (WumpusAlive^t \iff WumpusAlive^{t+1})\\ ... \]

Though this has solved the problem… the number of frame axioms is making me sad.

Given \(m\) actions and \(n\) fluents, our set of frame axioms is of size \(O(mn)\). Specifically, this is the representational frame problem (and is historically significant)

Put plainly, our world has a lot of fluents… so what can we do?

Fortunately, in the real world, only so many things actually affect other things (no more than \(k\) other things), there’s locality.

Solving our representational frame problem forces us to reconsider our transition model to only use a set of size \(O(mk)\) rather than \(O(mn)\).

Separately, there’s the inferential frame problem, that is, projecting forward the results of a \(t\)-step plan in time \(O(kt)\) instead of \(O(nt)\).

We’ll have to change our thought process to look at this problem “inside-out”.

Instead of fixating on actions we’ll focus on fluents.

For each fluent \(F\), define an axiom that defines the truth of \(F^{t+1}\) in terms of the time \(t\) and actions that may of happened at \(t\).

We can consider the truth of \(F^{t+1}\) in one of two ways:

  1. The action at time \(t\) causes \(F\) to be true at \(t+1\)
  2. \(F\) was already true at \(t\) and an action at \(t\) doesn’t cause it to become \(false\)

These are called successor-state axioms and look like: \[ F^{t+1} \iff ActionCausesF^t \lor (F^t \land \lnot ActionCausesNotF^t) \]

A simple example of this in the Wumpus World is:

\[ HaveArror^{t+1} \iff (HaveArrow^t \land \lnot Shoot^t) \]

The location is a little bit trickier but not too bad…

\[ L_{1,1}^{t+1} \iff (L^t_{1,1} \land (\lnot Forward \lor Bump^{t+1}))\\ \lor (L^t_{1,2}\land (FacingSouth^t\land Forward^t))\\ \lor (L^t_{2,1} \land (FacingWest^t \land Forward^t)). \]

Given a full set of successor-state axioms, we could \(Ask\) any answerable question about the world.

\[ \lnot Stench^0 \land \lnot Breeze^0 \land \lnot Glitter^0 \land \lnot Bump^0 \land \lnot Scream^0\ ;\ Forward^0\\ \lnot Stench^1 \land \lnot Breeze^1 \land \lnot Glitter^1 \land \lnot Bump^1 \land \lnot Scream^1\ ;\ TurnRight^1\\ \lnot Stench^2 \land \lnot Breeze^2 \land \lnot Glitter^2 \land \lnot Bump^2 \land \lnot Scream^2\ ;\ TurnRight^2\\ \lnot Stench^3 \land \lnot Breeze^3 \land \lnot Glitter^3 \land \lnot Bump^3 \land \lnot Scream^3\ ;\ Forward^3\\ \lnot Stench^4 \land \lnot Breeze^4 \land \lnot Glitter^4 \land \lnot Bump^4 \land \lnot Scream^4\ ;\ TurnRight^4\\ \lnot Stench^5 \land \lnot Breeze^5 \land \lnot Glitter^5 \land \lnot Bump^5 \land \lnot Scream^5\ ;\ Forward^5\\ \lnot Stench^6 \land \lnot Breeze^6 \land \lnot Glitter^6 \land \lnot Bump^6 \land \lnot Scream^6 \]

We now have enough information to ask: \[ Ask(KB,L^6_{1,2})=true\\ Ask(KB,W_{1,3})=true\\ Ask(KB,P_{3,1})=true \] Since it’s important and useful, we could add another axiom to see if a square is safe: \[ OK^t_{x,y} \iff \lnot P_{x,y} \land \lnot(W_{x,y} \land WumpusAlive^t). \]

So now we can now ask: \[ Ask(KB,OK^6_2,2)=true \] Is this all we need to solve the Wumpus World?

There’s one more thing… we need to confirm that all the necessary preconditions of an action hold (so the result is what we expect).

What if our agent trips? Is attacked by roaming kobolds? Set upon by a lurker above?

This is called the qualification problem and has no complete solution within logic…

Hybrid Agents

Now that we can deduce the state of the world, we can join this with the search and pathfinding algorithms from previous chapters to achieve our goal in the environment.

Hybrid Agent

There’s more do be done here! As time progresses, it becomes more expensive to \(Ask\), as more symbols are needed to infer information…

What can be done?