Professional Documents
Culture Documents
V05 LogicPlanning
V05 LogicPlanning
Based on material by
• Stuart Russell, UC Berkeley
• Peter Ljunglöf, U Gothenburg / Chalmers
• Malte Helmert, U Basel
“In which we design agents that can form representations of the world, use a
process of inference to derive new representations about the world, and use
these new representations to deduce what to do.”
“In which we see how an agent can take advantage of the structure of a problem
to efficiently construct complex plans of action.”
Performance measure
• gold +1000, death −1000, −1 per step, −10 for using arrow
Environment
• Squares adjacent to wumpus are smelly
• Squares adjacent to pit are breezy
• Glitter 𝑖𝑓𝑓 gold is in the same square
• Shooting kills wumpus if you are facing it
• Shooting uses up the only arrow
• Grabbing picks up gold if in same square
Actuators
• Left turn, Right turn, Wumpus world characterization
• Observable? No (only local perception)
• Forward (1 square), Grab, Shoot
• Deterministic? Yes (outcomes exactly specified)
• Episodic? No (sequential at the level of actions)
Sensors
• Static? Yes (wumpus and pits do not move)
• Breeze, Glitter, Smell (in current square) • Discrete? Yes
• Single-agent? Yes (wumpus is a natural feature)
Zurich University of Applied Sciences and Arts 5
CAI Centre for Artificial Intelligence (stdm)
Exploring a wumpus world
➔ What next?
𝐾𝐵 ⊨𝑖 𝛼
• Meaning: sentence 𝛼 can be derived from 𝐾𝐵 by procedure 𝒊
• Intuition:
• Consequences of 𝐾𝐵 are a haystack
• 𝛼 is a needle
• Entailment (⊨, the principle of “logical consequence”) says: “needle is in haystack”
• Inference: finding it
Desirable properties of 𝑖
• Soundness: 𝑖 is sound if whenever 𝐾𝐵 ⊨𝑖 𝛼, it is also true that 𝐾𝐵 ⊨ 𝛼
• Completeness: 𝑖 is complete if whenever 𝐾𝐵 ⊨ 𝛼, it is also true that 𝐾𝐵 ⊨𝑖 𝛼
Notation
• Let 𝑃𝑖,𝑗 be true if there is a pit in i/j
• Let 𝐵𝑖,𝑗 be true if there is a breeze in i/j
Pros and cons of propositional logic (as compared to atomic knowledge representation)
• Declarative: pieces of syntax correspond to facts
• Allows partial/disjunctive/negated information (unlike most data structures and databases)
• Compositional: meaning of 𝐵1,1 ∧ 𝑃1,2 is derived from meaning of 𝐵1,1 and of 𝑃1,2
• Meaning is context-independent (unlike natural language, where meaning depends on context)
• Very limited expressive power (unlike natural language)
→ E.g., cannot say “pits cause breezes in adjacent squares“ except by one sentence for each square!
→ It is useful to view the world as consisting of objects and relationships between them
Perception
• Timestep 𝑡 is smelly if I perceive a Smell (and whatever else) at 𝑡
∀𝑏, 𝑔, 𝑡 𝑃𝑒𝑟𝑐𝑒𝑝𝑡 𝑆𝑚𝑒𝑙𝑙, 𝑏, 𝑔 , 𝑡 ⇒ 𝑆𝑚𝑒𝑙𝑙 𝑡
• If I perceive a Glitter at 𝑡, I am at the place of the gold
∀𝑠, 𝑏, 𝑡 𝑃𝑒𝑟𝑐𝑒𝑝𝑡 𝑠, 𝑏, 𝐺𝑙𝑖𝑡𝑡𝑒𝑟 , 𝑡 ⇒ 𝐴𝑡𝐺𝑜𝑙𝑑(𝑡)
Reflex
• ∀𝑡 𝐴𝑡𝐺𝑜𝑙𝑑 𝑡 ⇒ 𝐴𝑐𝑡𝑖𝑜𝑛(𝐺𝑟𝑎𝑏, 𝑡)
1. Start with an initial KB of atemporal knowledge (e.g., relating breeziness to presence of pits)
2. At each time step, add current percept and temporal axioms (e.g., successor-state axioms)
State what happens to each fluent (i.e., any aspect of the
world that changes) depending on what action is taken
Further reading
• Rege, «Logik Programmierung 1&2» in «Programmiersprachen und -Paradigmen»
• AIMA ch. 7.4-7.6; 8.2-8.3; 9
Zurich University of Applied Sciences and Arts 15
CAI Centre for Artificial Intelligence (stdm)
Where’s the intelligence?
Man vs. machine
• Expert systems based on domain ontologies are still helpful in very specific domains
• As with humans, symbolic (i.e., logical) reasoning might be a higher-order process on top of
subsymbolic learning (i.e., machine learning)
Classical planning
• «Planning is the art and practice of thinking before acting» Patrik Haslum
«... finding a sequence of actions to accomplish a goal ...» AIMA ch. 11.1
• Planning agents seen so far:
• Problem solving agent (V03/V04): atomic representation → needs domain-specific heuristics
• Hybrid propositional logic agent (V05): ground (i.e., variable-free) sentences → may get swamped
➔ The part of AI being conducted by most researchers today calling themselves “AI guys”
without doing “machine learning” Entirely true 2016 – changed
with the current hype
Why is planning so big?
• Solved applications: Large logistics problems, operational planning, robotics, scheduling, …
• Community: Search is its basis; logic & knowledge representation is part of it
→ treated at specialized (ICAPS) and major AI (IJCAI, AAAI, ECCAI) international conferences
• AI’s tendency of spawning new disciplines:
• Many now autonomous disciplines started as a field of study within AI
• Examples: Computer vision, robotics, information retrieval, automatic speech recognition
• Machine learning could take this path, but currently the “buzzword” status of AI keeps it
• Other universalist tendencies: “Everything is search”, “everything is optimization”
One of planning’s big shots: Malte Helmert of University of Basel (→ see http://ai.cs.unibas.ch/misc/tutorial_aaai2015/)
Setting
• a single agent in a (→ multi-agent / game-playing possible)
• fully observable, (→ conformant planning possible)
• sequential and discrete, (→ temporal and real-time planning possible)
• deterministic and (→ probabilistic planning possible)
• static (offline) environment (→ online possible)
“Tower of Hanoi” is a classic
planning example
• A classical mini transportation problem: Loading / unloading cargo, flying between different airports
• Actions: 𝐿𝑜𝑎𝑑(𝑐𝑎𝑟𝑔𝑜, 𝑝𝑙𝑎𝑛𝑒, 𝑎𝑖𝑟𝑝𝑜𝑟𝑡), 𝑈𝑛𝑙𝑜𝑎𝑑(𝑐𝑎𝑟𝑔𝑜, 𝑝𝑙𝑎𝑛𝑒, 𝑎𝑖𝑟𝑝𝑜𝑟𝑡), 𝐹𝑙𝑦(𝑝𝑙𝑎𝑛𝑒, 𝑎𝑖𝑟𝑝𝑜𝑟𝑡, 𝑎𝑖𝑟𝑝𝑜𝑟𝑡)
• Predicates: 𝐼𝑛(𝑐𝑎𝑟𝑔𝑜, 𝑝𝑙𝑎𝑛𝑒), 𝐴𝑡(𝑐𝑎𝑟𝑔𝑜 ∨ 𝑝𝑙𝑎𝑛𝑒, 𝑎𝑖𝑟𝑝𝑜𝑟𝑡)
• Complete PDDL planning problem description (with all variables existentially quantified [∃]):
Initial & goal state are
given; 𝐴𝑐𝑡𝑖𝑜𝑛(𝑠) and
𝑅𝑒𝑠𝑢𝑙𝑡(𝑠, 𝑎) follow
from action schemas.
• Plan: C1@P1
[𝐿𝑜𝑎𝑑(𝐶1, 𝑃1, 𝑆𝐹𝑂), 𝐹𝑙𝑦(𝑃1, 𝑆𝐹𝑂, 𝐽𝐹𝐾), 𝑈𝑛𝑙𝑜𝑎𝑑(𝐶1, 𝑃1, 𝐽𝐹𝐾),
SFO JFK
𝐿𝑜𝑎𝑑(𝐶2, 𝑃2, 𝐽𝐹𝐾), 𝐹𝑙𝑦(𝑃2, 𝐽𝐹𝐾, 𝑆𝐹𝑂), 𝑈𝑛𝑙𝑜𝑎𝑑(𝐶2, 𝑃2, 𝑆𝐹𝑂). ]
C2@P2
Two formulations
• Forward (progression): search considers actions that are applicable
• Backward (regression): search considers actions that are relevant
• Neither of them is efficient without good heuristics!
• State abstractions (i.e., collapsing multiple states into a single one to shrink the graph)
• Reduce the state space by e.g. ignoring some fluents
• But: There is no clear understanding yet of which methods work best on what problems
• Logical agents
• apply inference to a knowledge base to derive new information and make decisions
• Wumpus world requires the ability to represent partial and negated information, reason by
cases, etc.
• Planning is AI’s main field, due to success stories like remotely controlling a NASA
spacecraft in real time
• Planning refers to problem solving techniques (i.e., search) on factored (i.e., logic-based)
representations of states and actions, allowing for fast algorithms
• PDDL describes the initial and goal states as conjunctions of literals; actions in terms of their
preconditions and effects
• Hierarchical task networks (HTN) allow the agent to take advice from the domain
designer in the form of high-level actions (HLAs) that can be implemented in various
ways by lower-level action sequences
• HTN methods can create very large plans required by many real-world applications
A) Logic
B) Reasoning in databases – an example
C) Datalog
D) Planning
𝐾𝐵 ⊨ 𝛼
• Intuitively, entailment means that one thing follows from another: “from 𝐾𝐵 I know that 𝛼”
• Formally, “knowledge base 𝐾𝐵 entails sentence 𝛼 𝑖𝑓𝑓 𝛼 is true in all worlds where 𝐾𝐵 is true”
• Example: A KB containing 𝑥 + 𝑦 = 4 entails 4 = 𝑥 + 𝑦
All possible models for the presence of pits in 2/1, 2/2 and 1/3:
• Red: all models compliant with the KB
(KB := wumpus-world rules + percepts)
• Blue: all models where KB is false
• Yellow: all models for sentence
𝛼1 =“no pit in 2/1”
➔ 𝐾𝐵 ⊨ 𝛼1
(the sentence, not all possible models for it!)
➔ i.e., 𝐾𝐵 is a stronger assertion than 𝛼1
(ruling out more possible worlds/models)
Formal: 𝛼 ⊨ 𝛽 𝑖𝑖𝑓 𝑀 𝛼 ⊆ 𝑀 𝛽
(with 𝑀(𝛼) being the set of all models of 𝛼)
(In case of prolonged confusion, look up Mike Shulman’s answer of January 4, 2011, in this
thread: https://golem.ph.utexas.edu/category/2011/01/entailment_and_implication.html)
(𝛼 ∧ 𝛽) ≡ (𝛽 ∧ 𝛼) commutativity of ∧
(𝛼 ∨ 𝛽) ≡ (𝛽 ∨ 𝛼) commutativity of ∨
((𝛼 ∧ 𝛽) ∧ 𝛾) ≡ (𝛼 ∧ (𝛽 ∧ 𝛾)) associativity of ∧
((𝛼 ∨ 𝛽) ∨ 𝛾) ≡ (𝛼 ∨ (𝛽 ∨ 𝛾)) associativity of ∨
¬(¬𝛼 ) ≡ 𝛼 double-negation elimination
(𝛼 ⇒ 𝛽) ≡ (¬𝛽 ⇒ ¬𝛼) contraposition
(𝛼 ⇒ 𝛽) ≡ (¬𝛼 ∨ 𝛽) implication elimination
(𝛼 ⟺ 𝛽) ≡ ( 𝛼 ⇒ 𝛽 ∧ 𝛽 ⇒ 𝛼 ) biconditional elimination
¬(𝛼 ∧ 𝛽) ≡ (¬𝛼 ∨ ¬𝛽) De Morgan
¬(𝛼 ∨ 𝛽) ≡ (¬𝛼 ∧ ¬𝛽) De Morgan
(𝛼 ∧ (𝛽 ∨ 𝛾)) ≡ ((𝛼 ∧ 𝛽) ∨ (𝛼 ∧ 𝛾)) distributivity of ∧ over ∨
(𝛼 ∨ (𝛽 ∧ 𝛾)) ≡ ((𝛼 ∨ 𝛽) ∧ (𝛼 ∨ 𝛾)) distributivity of ∧ over ∨
3. If satisfiable: extract all variables representing actions that are assigned true in the model
➔ this is the plan
Ontological engineering
• It is unclear (computationally and philosophically) if special-purpose ontologies can be merged
into a general-purpose one
• But: Using upper ontologies («world knowledge») connected to task-specific ones is a way
that works for many domains
• OWL, the W3C-standardized description logic, is very expressive but still seldom used
Zurich University of Applied Sciences and Arts 38
CAI Centre for Artificial Intelligence (stdm)
More on knowledge representation (KR)
Remarks
• KR as presented here is most helpful today in the context of ontologies (expert systems,
semantic web)
• There are alternative forms of KR besides formal (deductive) languages, e.g.:
• Procedural languages (e.g., Python code)
• Subsymbolic representations (e.g., the weights in a neural network)
• AI planning uses KR and reasoning in a less formal way (→ see V07)
A neural network encodes all its
knowledge (i.e., all it has learned about
data) in the weights 𝑤𝑖,𝑗 and 𝑤′𝑗,𝑘
Further reading
• AIMA ch. 8.4; 10
Zurich University of Applied Sciences and Arts 39
CAI Centre for Artificial Intelligence (stdm)
Other types of knowledge & their representation
based on Z. Alvi, VU “Artificial Intelligence CS607”, lecture 14
• Procedural knowledge: Describes how to do things, provides a set of directions of how to perform
certain tasks, e.g., how to drive a car
• Declarative knowledge: It describes objects, rather than processes. What is known about a
situation, e.g., it is sunny today, cherries are red
• Meta knowledge: Knowledge about knowledge, e.g., the knowledge that blood pressure is more
important for diagnosing a medical condition than eye color
• Heuristic knowledge: (Empirical) rule-of-thumb, e.g., if I start seeing shops, I am close to a market
• Structural knowledge: Describes structures and their relationships, e.g., how the various parts of
the car fit together to make a car, or knowledge structures in terms of concepts, sub concepts, and
objects
Representations
• Pictures and symbols: This is how the earliest humans represented knowledge when sophisticated
linguistic systems had not yet evolved
• Graphs and Networks:
→ allow relationships between entities, e.g., to show family relationships, now we can use a graph
→ May be used to represent procedural knowledge, e.g., how to start a car?
• Numbers: Eventually, every representation we use gets translated to numbers in the computer's
internal representation
…using triples
…in a database
Task
• For a given graph and pattern, find all instances of the pattern
𝑌
𝑋
• Results:
• 𝑋 = 𝑎, 𝑌 = 𝑏; 𝑋 = 𝑏, 𝑌 = 𝑎
• 𝑋 = 𝑔, 𝑌 = 𝑐; 𝑋 = 𝑐, 𝑌 = 𝑔
…find drugs that interfere with another drug involved in the treatment of a disease
𝑊
𝑋 𝑌 𝑍
𝑊
𝑋 𝑌 𝑍
«Over the next few weeks, he’d made a + withdrawal(‘Fikri’, 5000, ‘some bank’, 2016-11-2)
number of large withdrawals from a + withdrawal(‘Fikri’, 2000, ‘some bank’, 2016-11-21)
Russian bank account and placed repeated
…
calls to a few people in Syria»
«More recently, he rented a truck, drove to + rented(‘Fikiri’, ‘truck’, ‘Miami’, ‘Orlando’, 2019-
01-30)
Orlando, and visited Disney World himself»
flag(Person, 1, Date) <= foreignWithdrawal(Person, Tot_amount, Date) & Tot_amount > 10000
flag(Person, 1, Date) <= rented(Person, Vehicle, Origin, Dest, Date) & importantLocation(Dest)
alert(Person, Flag_cnt, Min_date, Max_date) <= totalflags(Person, Flag_cnt, Min_date, Max_date) &
Max_date - Min_date < 10 & #days
Flag_cnt > 3
Who could have known before January 30 that 𝑋 was going to happen?
knew(‘Smith’)
Self-reference / recursion: not possible in standard SQL
knew(Person2) <= (though certain DBMS implement it)
knew(Person1) &
contacted(Person1, Person2, Message, Time) &
Time < 2019-01-30
knew(Person2) <=
knew(Person1) &
met_with(Person1, Person2, Time) &
Time < 2019-01-30
FYI – more precisely, Horn clauses: also valid without the implication
Some modifications (for efficient evaluation):
• Variables in the head also appear in the body of a clause
• Under certain conditions, up to one negated term in the body is allowed (“stratified negation”)
• Usually no functional symbols (not true in pyDatalog)
Source: https://mcturra2000.wordpress.com/2014/09/14/logic-programming-example-unit-conversion-using-datalog/
Installing pyDatalog: pip install pyDatalog
See also: https://sites.google.com/site/pydatalog/
Example: Your new pet «Fritz» croaks and eats flies; is it green? (see https://en.wikipedia.org/wiki/Backward_chaining)
• Facts:
• 𝑐𝑟𝑜𝑎𝑘𝑒𝑠(𝑓𝑟𝑖𝑡𝑧)
• 𝑒𝑎𝑡𝑠𝐹𝑙𝑖𝑒𝑠(𝑓𝑟𝑖𝑡𝑧)
• Rules:
• 𝑐𝑟𝑜𝑎𝑘𝑒𝑠 𝑋 ∧ 𝑒𝑎𝑡𝑠𝐹𝑙𝑖𝑒𝑠 𝑋 ⇒ 𝑓𝑟𝑜𝑔 𝑋
• 𝑐ℎ𝑖𝑟𝑝𝑠 𝑋 ∧ 𝑠𝑖𝑛𝑔𝑠 𝑋 ⇒ 𝑐𝑎𝑛𝑎𝑟𝑦 𝑋
• 𝑓𝑟𝑜𝑔 𝑋 ⇒ 𝑔𝑟𝑒𝑒𝑛 𝑋 Logic notation for the
• 𝑐𝑎𝑛𝑎𝑟𝑦 𝑋 ⇒ 𝑦𝑒𝑙𝑙𝑜𝑤 𝑋 Modus Ponens rule
Pro SPARQL
• Designed for graph queries
Con SPARQL
• Not algebraically closed (input is a graph, but output is a set of records)
• Limited expressiveness (no arbitrary recursion)
• If input is tabular, you have to shred it into a graph before using SPARQL
(➔ often a 3x-x blow up in size!)
• Everything has to be in one graph
• Datalog combines expressive power (about individuals and their relations) with
efficient inference
• Forward and backward chaining are fast & complete for Horn clauses
(Datalog)
• While Datalog might gain popularity in big data applications in the future,
logic in general remains very important for AI
Practice
• Sub-optimal planning is sometimes easy
• PDDL has facilitated the development of very accurate domain-independent heuristics
making planning feasible (formalisms based on FOL have had less success)
Cost – benefit
• Remove a part of the benefits of the expressiveness of PDDL to…
• …gain access to efficient solution methods of SAT and CSP solvers
➔ A possible solution sequence: [𝑀𝑜𝑣𝑒𝑇𝑜𝑇𝑎𝑏𝑙𝑒 (𝐶, 𝐴), 𝑀𝑜𝑣𝑒(𝐵, 𝑇𝑎𝑏𝑙𝑒, 𝐶), 𝑀𝑜𝑣𝑒(𝐴, 𝑇𝑎𝑏𝑙𝑒, 𝐵)]
Use cases
• Spacecraft operation in real time (1998)
NASA’s Deep Space 1 was controlled by a planning & scheduling system devising and
carrying out plans like «During the next week take pictures of the following asteroids
and thrust 90% of the time» (→ see [Nilsson, 2010] ch. 32.2.1)
• Factory scheduling (1985)
4-week (3 shifts a day) production plan at Hitachi for assembly line of 350 products with
35 machines and >2000 different operations (→ see AIMA ch. 11.4.2, HTN on next slide)
• Military operation planning (1990)
A scheduling program helped with the logistics of 1st gulf war and is said to have
«paid back all of DARPAs 30 years of investment in AI in a matter of a few months»
(→ see [Nilsson, 2010] ch. 23.3.3)
Challenges
• Taking resources (incl. time) into account → scheduling
• Being overwhelmed by state space size → hierarchical planning
• Needing to incorporate human wisdom → hierarchical planning
• Coping with uncertainty → conformant / contingency / online planning (analog to AIMA ch. 4)
• Planning with multiple agents → planning with cooperative and adversarial multiagents is unsolved
• Algortithm HIERARCHICAL-SEARCH
• Recursively chose an HLA in current plan
• Replace HLA with one of its refinements, until plan
achieves its goal
• Can be implemented as breadth-first search
(alternatives possible)
• Example: Clean your apartment (several rooms, connected by narrow corridors) Pessimistic
• 5 Low-level actions (u,d,l,r,suck) set REACH-
• 2 HLA’s: Navigate, CleanRoom
• Breadth-first: 5𝑑 (𝑑: length of shortest solution)
• Hierarchical search: still exponential (tries all ways consistent with hierarchy)
• Angelic search: approx. linear in number of squares