AI Suiss 03 PracticalReasoningAndSearches
AI Suiss 03 PracticalReasoningAndSearches
Introduzione
all’intelligenza artificiale
e al machine learning
-
Lezione 3
Agenti logici e agenti pratici e
soluzione di problemi di ricerca
Logic agents
Logic agents: Knowledge base and representation
The KB just provide answers to queries, does not tell the action to perform
In logic agents logic inference (symbolic reasoning) is used to choose the best
action given the KB (action is a logic consequence of the KB)
3
Two issues for logic based agents
5
Formal language
Formal language:
Set of sentences (aka words or formulas) built from a fixed set of letters or
symbols. Sentences are also called well formed formulas (wff)
the inventory from which the latter are taken is the alphabet on which
the language is defined.
language is defined without reference to any meanings of its
expressions, i.e. it exists before any interpretation is assigned
Example:
A formal language ℒ can be defined with the alphabet a={▲,▼}, and with
a word being in ℒ if it begins with ▲and is composed solely of the symbols
▲ and ▼.
A possible interpretation of ℒ could assign the decimal digit '1' to ▲ and '0'
to ▼. Then ▲▼▲ would mean 101 under this interpretation of ℒ.
6
Symbols for predicate logic
7
Symbols for predicate logic
8
Some additional nomenclature
Term:
– a variable, a constant, or if f is symbol of a function and X,Y,Z,… are terms
, f(X,Y,Z,…) is a term
– e.g. maria, f(X)
9
Logic grammar
Formal grammar :
a precise description of the well-formed formulas (wff) of a formal
language, i.e. anything describing the set of strings over the alphabet of
the formal language which constitute wff
it does not describe the semantics (i.e. the meaning) of the wff
11
Formal proof
E.g.
Teoria T: axioms (can be interpreted as a theory of ≤)
(A1) p(0,0)
(A2) ∀X ∀Y (p(X,Y) ⇒ p(X,s(Y)))
(A3) ∀X p(X,X)
12
Interpretation, semantics, model
Interpretation
• assignment of meanings to symbols and truth values to predicates
Semantics
• the investigation of possible interpretations
Model
• for a wff s, I is a model for s, iff s is true in I
• A sentence true in all interpretations is valid
13
Intepretation examples
Interpretation I1 Domain: ℕ
– “0” represent 0
– “s()” represent the successor of a natural number
– “p()” represent the relation “≤”
Interpretation I2 Domain: negative integer numbers
– “0” represent 0
– “s” represent the predecessor of a natural number
– “p” represent the relation “≤”
14
Formal derivation and Logic entailment
Syntactic consequence
• a formula ℬ is a syntactic consequence within the formal system ℱ of a
set of formulas Γ if there is a formal proof in ℱ of ℬ from the set Γ: Γ├ℱ ℬ
• syntactic consequence does not depend on any interpretation of the
formal system,
• i.e. ℬ can be formally derived from Γ
Semantic consequence
• a formula ℬ is a semantic consequence within the formal system ℱ of a
set of statements Γ : Γ╞ℱ ℬ ; if and only if there is no model in which all
members of Γ are true while ℬ is false. i.e. the set of interpretations that
make all members of Γ true is a subset of the set of interpretations that
make ℬ true
• i.e. ℬ is logically entailed by Γ
15
Soundness and completeness
True
propositio
Axiom
n s
Models Inference
Soundnes rules
s
Theorem
s
16
Completenes
Deductive Reasoning agents
Let:
ρ be this formal theory (typically a set of rules);
∆ be a logical database that describes the current state of the world;
Ac be the set of actions the agent can perform;
∆ ⊢ρ φ means that φ can be proved from ∆ using ρ.
17
Deductive Reasoning agents
18
Action function
19
An example: The Vacuum World
NB: with the predicate logic it is much more convenient to represent the environment. In
propositional logic we should have added several propositions In0,0, In0,1,…
Still may not be obvious in most real cases how to achieve a full logic representation of
the environment
20
The Vacuum World
21
An example: The Vacuum World
Rules ρ for determining what to do. We can define a predefinite schema to move into the
Vacuum World
Using these rules and starting at (0, 0) the robot will clear up dirt
22
Agents that plan ahead
«Goal based agents»
Agent pro-active behaviour
Now we deal with the “pro-active” part, showing how we can design agents to
have goal-directed behaviour and plan ahead
Paolo Meridiani 24
Practical reasoning
Deliberation:
§ deciding what states of affairs we want to achieve
§ the outputs of deliberation are intentions
Means-ends reasoning:
§ deciding how to achieve these states of affairs
§ the outputs of means-ends reasoning are plans
Paolo Meridiani 25
Intentions are stronger than desire
Paolo Meridiani 26
Planning
Planning is the design of a course of action
that will achieve some desired goal
↵0 ↵1 ↵2 ↵n
e0 ! e1 ! e2 ! e3 ! · · · ! eg
Paolo Meridiani 27
A simple planning agent
Deliberate: define an
intention/goal based on the
agent’s beliefs
Paolo Meridiani 28
Means-end reasoning:
planning and search
problems
Paolo Meridiani
Search problems
Remember:
A search problem consists of:
§ A state space
§ A successor function (with
actions and potential costs)
§ A start and a goal state
Solution: a sequence of
actions (a plan) which
transforms the start state to a
goal state
Paolo Meridiani 30
Example: travelling in Romania
State space:
Cities in Romania
Successor function:
Roads: Go to adjacent city
with cost = distance
Start state:
Arad
Goal test:
Is state == Bucharest?
Paolo Meridiani 31
Example: vacuum world as a search problem
goal stateS
start state
8x8y ¬Dirt(x, y)
<latexit sha1_base64="+GYHPdxsiL5DeKZT2ACwZwPUK4U=">AAACC3icbZDLSgMxFIbPeK31NurSTWgRKkiZEVGXRV24rGAv0A4lk6ZtaCYzJBnpUOraja/ixoUibn0Bd76NaTuCtv4Q+PjPOeSc3484U9pxvqyFxaXlldXMWnZ9Y3Nr297ZraowloRWSMhDWfexopwJWtFMc1qPJMWBz2nN71+O67U7KhULxa1OIuoFuCtYhxGsjdWyc81OKDHnaIB+KLlvCtpFV0zqwuAoOWzZeafoTITmwU0hD6nKLfuz2Q5JHFChCcdKNVwn0t4QS80Ip6NsM1Y0wqSPu7RhUOCAKm84uWWEDozTRmYV84RGE/f3xBAHSiWBbzoDrHtqtjY2/6s1Yt0594ZMRLGmgkw/6sQc6RCNg0FtJinRPDGAiWRmV0R6WGKiTXxZE4I7e/I8VI+L7mnRvTnJly7SODKwDzkogAtnUIJrKEMFCDzAE7zAq/VoPVtv1vu0dcFKZ/bgj6yPb9HfmkM=</latexit>
{
<latexit sha1_base64="gRkLF/8GQhmCxuxt1NbQbx39AfI=">AAAB6XicbVBNS8NAEJ3Ur1q/qh69LBbBU0lEqseiF49V7Ae0oWy2k3bpZhN2N0IJ/QdePCji1X/kzX/jts1BWx8MPN6bYWZekAiujet+O4W19Y3NreJ2aWd3b/+gfHjU0nGqGDZZLGLVCahGwSU2DTcCO4lCGgUC28H4dua3n1BpHstHM0nQj+hQ8pAzaqz00Mv65Ypbdecgq8TLSQVyNPrlr94gZmmE0jBBte56bmL8jCrDmcBpqZdqTCgb0yF2LZU0Qu1n80un5MwqAxLGypY0ZK7+nshopPUkCmxnRM1IL3sz8T+vm5rw2s+4TFKDki0WhakgJiazt8mAK2RGTCyhTHF7K2EjqigzNpySDcFbfnmVtC6qXq3q3V9W6jd5HEU4gVM4Bw+uoA530IAmMAjhGV7hzRk7L86787FoLTj5zDH8gfP5A518jWs=</latexit>
,
<latexit sha1_base64="0Eq8646ny07DmpZwqsk0gJbBCn4=">AAAB6HicbVBNS8NAEJ34WetX1aOXxSJ4kJKIqMeiF48t2A9oQ9lsJ+3azSbsboQS+gu8eFDEqz/Jm//GbZuDtj4YeLw3w8y8IBFcG9f9dlZW19Y3Ngtbxe2d3b390sFhU8epYthgsYhVO6AaBZfYMNwIbCcKaRQIbAWju6nfekKleSwfzDhBP6IDyUPOqLFS/bxXKrsVdwayTLyclCFHrVf66vZjlkYoDRNU647nJsbPqDKcCZwUu6nGhLIRHWDHUkkj1H42O3RCTq3SJ2GsbElDZurviYxGWo+jwHZG1Az1ojcV//M6qQlv/IzLJDUo2XxRmApiYjL9mvS5QmbE2BLKFLe3EjakijJjsynaELzFl5dJ86LiXVW8+mW5epvHUYBjOIEz8OAaqnAPNWgAA4RneIU359F5cd6dj3nripPPHMEfOJ8/dQGMtg==</latexit>
Paolo Meridiani 32
Vacuum world: how many world states?
Paolo Meridiani 33
How to represent search problems: state space graph
Paolo Meridiani 34
Search tree
A search tree:
§ A “what if” tree of plans and their
outcomes
§ The start state is the root node
§ Children nodes correspond to
successors
§ Nodes show states, but correspond
to PLANS that achieve those states
Paolo Meridiani 35
Search problem general algorithm for solution
Paolo Meridiani 36
A search example
Paolo Meridiani 37
Depth-first search (DFS)
Paolo Meridiani 38
Search algorithms properties
Paolo Meridiani 39
DFS properties
Is it complete?
§ If m is finite yes
Is it optimal?
§ No, it finds the “leftmost” solution,
regardless of depth or cost
Paolo Meridiani 40
Breadth-First Search (BFS)
Paolo Meridiani 41
BFS properties
Is it complete?
§ s must be finite if a solution exists, so
yes
Is it optimal?
§ Only if costs are all 1 (more on costs
later)
Paolo Meridiani 42
DFS vs BFS
Paolo Meridiani 43
Cost-sensitive searches
BFS finds the shortest path in terms of number of actions. It does not find
the least-cost path.
We will now discuss a similar algorithm which does find the least-cost path
Paolo Meridiani 44
Uniform Cost Search (UCS)
Paolo Meridiani 45
UCS properties
Is it complete?
§ Assuming best solution has a finite cost yes!
Is it optimal?
§ Yes
The bad:
Explores options in every “direction”.
We can see the UCS as a slow/diligent turtle
that will always bring you to the optimal
Paolo Meridiani solution 46
Can we make the search faster? Informed searches
To pick the which nodes to expand first we would need to know how close we
are to the goal
Not always easy to find a good heuristic. A good heuristic can drastically change
the number of nodes on the fringe which needs to be expanded
Paolo Meridiani 47
Heuristics in path problems
Paolo Meridiani 48
Another example of heuristics: the 8-puzzle
Possible heuristics:
§ total number of
misplaced tiles
§ better: total
Manhattan distance
(minimum number of
moves to the goal)
We can imagine a good heuristics as the cost needed to reach the goal in a
“relaxed problem” i.e. in this case as if we can move the tiles independently and
place them where we want
Paolo Meridiani 49
Greedy Search
Paolo Meridiani 50
Greedy search
Normally
§ Greedy takes you fast to (some) goal
§ However greedy search is not guaranteed
to be optimal (unless you have a perfect
heuristic)
Worst-case
§ like a badly-guided DFS for poor heuristics
Paolo Meridiani 51
A* search: combining UCS and greedy
Paolo Meridiani 52
A* optimal?
Paolo Meridiani 53
Admissible heuristics
Paolo Meridiani 54
UCS vs A*
Paolo Meridiani 55
More complex planning
We have only looked at search problems in deterministic and accessible
environments. An optimal search algorithm in this context produces an optimal
plan (assuming infinite deliberation/planning time)
Standard search algorithm into spate space cannot cope with these conditions.
Need more complex planners e.g. create sub-plans/intermediate goals
Paolo Meridiani 56
Planning by looking at the plan space
Search into the plan space and not into the state space:
STRIPS planner
The Stanford Research Institute Problem
Solver (1971) Used by Shakey
Paolo Meridiani 57
Agent commitment
An agent is committed to
§ ends
the state of affairs it wishes to bring about
§ means
the mechanism via which the agent wishes to achieve the state of affairs
Degrees of commitment:
§ Blind commitment
Agent that will continue to maintain an intention no matter what. Blind
commitment is also referred to as fanatical commitment
§ Single-minded commitment
Agent that will continue to maintain an intention until it believes it is achieved or
it is believed to be impossible
§ Open-minded commitment
An open-minded agent to reconsider its intentions after each action
Paolo Meridiani 58
Agent’s commitment: an experiment
Paolo Meridiani 59
Agent’s commitment: experiment results
Paolo Meridiani 60