Docsity

Intro to Knowledge Representation in AI: Propositional Logic & Inference - Prof. Christoph, Study notes of Computer Science

Toggle sidebar
bg1
Artificial Intelligence Programming
Intro to Knowledge Representation
Chris Brooks
Department of Computer Science
University of San Francisco
Departmentof Computer Science — University of San Francisco – p. 1/??
10-2: Introduction
•So far, we’ve talked about search, which is a means of
considering alternative possibilities.
◦The way in which problem states were represented was
typically pretty straightforward.
•The other aspect of many AI problems involves representing
possible states.
•Our choice of representation influences:
◦The problems our agent is able to solve.
◦The sorts of environments an agent can deal with.
◦The complexity of search
◦The sophistication of our agent.
Departmentof Computer Science — University of San Francisco – p. 2/??
10-3: Knowledge Representation
•Choices we’ll look at include:
◦Logic-based approaches
•Propositional logic
•First-order logic
•Ontologies
◦Logic is a flexible, well-understood, powerful, versatileway
to represent knowledge.
◦Often fits with the way human experts describe their world
◦Facts are either true or false
◦Has a hard time dealing with uncer tainty.
Departmentof Computer Science — University of San Francisco
10-4: Knowledge Representation
•Choices we’ll look at include:
◦Probabilistic approaches
•Bayesian reasoning
•Bayesian networks
•Decision theory
◦Probabilistic reasoning works well in domains with
uncertainty.
◦Inference can be more complex
◦Requires more prior knowledge to use effectively.
◦Representational power typically more limited.
Departmentof Computer Science — University of San Francisco – p. 4/??
10-5: Declarative vs. Procedural
•Knowledge representation entails a shift from a procedural way
of thinking about agents to a declarative way.
•Procedural: Behavior is encoded directly in agent program.
Focus is on algorithms.
•Declarative: Agent knowledge is represented as sentences.
Focus is on data.
•Agents maintain a knowledge base that allows them to reason
about a problem.
•Knowledge is represented as facts and relations
•Inference is typically performed automatically.
•This is sometimes called programming at the knowledge level.
•Specify facts known by an agent, along with goals.
•Programming focus is on encoding knowledge
Departmentof Computer Science — University of San Francisco – p. 5/??
10-6: Wumpus World
•R & N use the Wumpus World as an example domain.
•Environment: 4x4 grid of rooms.
◦Gold in one room, wumpus in another
◦Pits in some rooms
•Actions: Move forward, turn left, turn right, shoot arrow,grab
gold.
•Sensors: Perceive stench, perceive breeze, perceive gold,
sense wall, hear wumpus death.
•Goal: maximize performance, which means finding gold quickly
without encountering the wumpus or falling into a pit.
Departmentof Computer Science — University of San Francisco
pf3
pf4
pf5

Partial preview of the text

Download Intro to Knowledge Representation in AI: Propositional Logic & Inference - Prof. Christoph and more Study notes Computer Science in PDF only on Docsity!

Artificial Intelligence Programming

Intro to Knowledge Representation

Chris Brooks Department of Computer ScienceUniversity of San Francisco

Department of Computer Science — University of San Francisco – p. 1/

??

Introduction • So far, we’ve talked about search, which is a means ofconsidering alternative possibilities.^ ◦^ The way in which problem states were represented wastypically pretty straightforward. • The other aspect of many AI problems involves representingpossible states. • Our choice of representation influences:^ ◦^ The problems our agent is able to solve.^ ◦^ The sorts of environments an agent can deal with.^ ◦^ The complexity of search^ ◦^ The sophistication of our agent.

Department of Computer Science — University of San Francisco – p. 2/

??

Knowledge Representation • Choices we’ll look at include:^ ◦^ Logic-based approaches^ •

Propositional logic • First-order logic • Ontologies ◦ Logic is a flexible, well-understood, powerful, versatile wayto represent knowledge. ◦ Often fits with the way human experts describe their world ◦ Facts are either true or false ◦ Has a hard time dealing with uncer tainty.

Department of Computer Science — University of San Fra

Knowledge Representation • Choices we’ll look at include:^ ◦^ Probabilistic approaches^ •

Bayesian reasoning • Bayesian networks • Decision theory ◦ Probabilistic reasoning works well in domains withuncertainty. ◦ Inference can be more complex ◦ Requires more prior knowledge to use effectively. ◦ Representational power typically more limited.

Department of Computer Science — University of San Francisco – p. 4/

??

Declarative vs. Procedural • Knowledge representation entails a shift from a procedural wayof thinking about agents to a declarative way. • Procedural: Behavior is encoded directly in agent program.Focus is on algorithms. • Declarative: Agent knowledge is represented as sentences.Focus is on data. • Agents maintain a knowledge base that allows them to reasonabout a problem. • Knowledge is represented as facts and relations • Inference is typically performed automatically. • This is sometimes called programming at the knowledge level. • Specify facts known by an agent, along with goals. • Programming focus is on encoding knowledge

Department of Computer Science — University of San Francisco – p. 5/

??

Wumpus World • R & N use the Wumpus World as an example domain. • Environment: 4x4 grid of rooms.^ ◦^ Gold in one room, wumpus in another^ ◦^ Pits in some rooms • Actions: Move forward, turn left, turn right, shoot arrow,grabgold. • Sensors: Perceive stench, perceive breeze, perceive gold,sense wall, hear wumpus death. • Goal: maximize performance, which means finding gold quicklywithout encountering the wumpus or falling into a pit.

Department of Computer Science — University of San Fra

Wumpus World

PIT

Stench Stench START

B^ r^ e^ e^ z

e

Gold

PIT

B^ r^ e^ e^ z^ PIT

e

B^ r^ e^ e^ z

e

B^ r^ ee^ z

e

B^ r^ e^ e^ z

e B^ r^ e^ e^ z

e Stench

Department of Computer Science — University of San Francisco – p. 7/

??

Knowledge base • A knowledge base is composed of

sentences

that assert facts

about the world.^ ◦^ What’s the difference between a knowledge base and adatabase?^ ◦^ In principle, expressiveness and usage.^ ◦^ In practice, a knowledge base might be implemented usinga database. • Sentences describe:^ ◦^ Objects of interest in the world (wumpueses, gold, pits,rooms, agent)^ ◦^ Relationships between objects (agent is holding arrow)

Department of Computer Science — University of San Francisco – p. 8/

??

Syntax and Semantics • Syntax: Defines whether a sentence is properly constructed.^ ◦^ In arithmetic,

x^ + 2 = 5

is syntactically correct, whereas

x+ = 3

is not. ◦^ In a Python program,

timeElapsed

is syntactically

correct, while

timeElapsed

is not.

-^ Semantics: Defines when a sentence is true or false.^ ◦

The semantics of

x^ + 2 = 5

are that this sentence is true in

worlds where

x^ = 3

and false otherwise.

◦^ Logical sentences must be true or false; no “degree of truth”.

Department of Computer Science — University of San Fra

Models

-^ Model: A model is an assignment of values to a subset of thevariables of interest in our problem.^ ◦

A model for the U2 problem might indicate where each bandmember is. ◦ In the Wumpus World, a model would indicate the locationof the pits, gold, agent, arrow, and wumpus.

-^ A model provides an agent with a

possible world

; one guess at

how things might be. • We’ll often be interested in finding models that make asentence true or false, or all the models that could be true for agiven set of sentences. • Models are very much like states.

Department of Computer Science — University of San Francisco – p. 10/

??

Logic

-^ Entailment: Entailment is the idea that one sentence followslogically from another.^ ◦

Written as:

a^ |=

b

◦^ Technically, this says: for all models where a is true, b isalso true. ◦^ (think if-then) ◦^ a^

|=^ a

-^ Note that entailment is a property of a set of sentences, and notan instruction to an agent.

Department of Computer Science — University of San Francisco – p. 11/

??

Inference

-^ A knowledge base plus a model allows us to perform inference.^ ◦

For a given set of sentences, plus some assignment ofvalues to variables, what can we conclude?

-^ Entailment tells us that a sentence can be derived. •^ Inference tells us

how

it is derived.

-^ An algorithm that only derives entailed sentences is said to be^ sound

◦^ Doesn’t make mistakes or conclude incorrect sentences.

Department of Computer Science — University of San Fran

Notation

•^ A

∧^ B

  • AND. sentence is true if both A and B are true. -^ A

∨^ B

OR. Sentence is true if either A or B (or both) are true.

-^ ¬ A^ NOT. Sentence is true if A is false. -^ A

⇒^

B^ Implies. Sentence is true if A is false or B is true.

-^ A

⇔^

B^ Equivalence. Sentence is true if A and B have the same truth value.

Department of Computer Science — University of San Francisco – p. 19/

??

Propositional Logic - implication

-^ Implication is a particularly useful logical construct. •^ The

sentence

A^ ⇒

B^ is true if:

◦^ A is true and B is true. ◦^ A is false. • Example: If it is raining right now, then it is cloudy right now. • A^ ⇒^ B^ is equivalent to

¬A

∨^ B

-^ Implication will allow us to perform inference.

Department of Computer Science — University of San Francisco – p. 20/

??

Propositional Logic - Still more definitions

-^ Logical equivalence: Two sentences are logically equivalent ifthey are true for the same set of models.^ ◦

P^ ∧

Q^ is logically equivalent to

P^ ∨ ¬

Q)

-^ Validity (tautology): A sentence is valid if it is true for all models.^ ◦

A^ ∨ ¬

A

-^ Contradiction: A sentence that is false in all models.^ ◦

A^ ∧ ¬

A

Department of Computer Science — University of San Fran

Propositional Logic - Still more definitions

-^ Satisfiability: A sentence is satisfiable if it is true for somemodel.^ ◦

EdgeOnLef t

∨^ BonoOnLef t

is true in some worlds.

◦^ Often our problem will be to find a model that makes asentence true (or false). ◦^ A model that satisfies all the sentences we’re interested inwill be the goal or solution to our search.

Department of Computer Science — University of San Francisco – p. 22/

??

Logical reasoning

-^ Logical reasoning proceeds by using existing sentences in anagent’s KB to

deduce

new sentences.

-^ Deduction is guarateed to produce true sentences, assuming asound mechanism is used. •^ Rules of inference.^ ◦

Modus Ponens^ •^

A, A

⇒^ B

, conclude

B

◦^ And-Elimination^ •^

A^ ∧

B, conclude

A.

◦^ Or-introduction^ •^

A, conclude

A^ ∨

B

Department of Computer Science — University of San Francisco – p. 23/

??

Logical Reasoning

-^ Rules of inference.^ ◦

Contraposition:

A^ ⇒

B^ can be rewritten as

¬B

A

◦^ Double negative:

A) =

A

◦^ Distribution^ •^

A^ ∨^

(B^ ∧

C) = (

A^ ∨

B)^

∧^ (A

∨^ C

•^ A

∧^ (B

∨^ C

A^ ∧

B)^

∨^ (A

∧^ C

◦^ DeMorgan’s theorem^ •^

A^ ∨^

B, rewrite as

A^ ∧ ¬

B)

-^ or

A^ ∧

B^ ⇔ ¬

(¬A

B)

Department of Computer Science — University of San Fran

Inference as Search

-^ We can then use good old breadth-first search (or any othersearch) to perform inference and determine whether asentence is entailed by a knowledge base. •^ Basic idea: Begin with statements in our KB. •^ Actions are applications of implication.^ ◦

For example, say we know 1)

A^ ⇒

B, 2)

B^ ⇒

C, and 3)

A.

◦^ One possible action is to apply Modus Ponens to 1 and 3 toconclude

B.

◦^ We can then apply Modus Ponens again to conclude

C.

Department of Computer Science — University of San Francisco – p. 25/

??

Inference as Search

-^ Our search can proceed in a breadth-first manner (what are allthe possible conclusions from the original KB), depth-first (takeone inference, then use it to make further inferences, and soon) or somewhere in-between. •^ Successor function defines all applicable rules for a givenknowledge base. •^ The result of this search is called a

proof

.^ Department of Computer Science — University of San Francisco – p. 26/

??

Example

-^ Begin with:^ ◦

There is no pit in (1,1):

R^1

:^ ¬P

1 ,^1

◦^ A square has a breeze iff there is a pit in the neighboringsquare ◦^ R

:^ B 2

(P^1

∨^ , 2

P^2 ,^1

◦^ R

:^ B 3

(P^1

∨^ , 1

P^2 ,^2

∨^ P

)^3 , 1

(and so on for all other

squares)

-^ Assume the agent visits 1,1 and senses no breeze, but doessense a breeze in 2,1. Add:^ ◦

R^4

:^ ¬B

1 ,^1 ◦^ R

:^ B 5

2 ,^1

Department of Computer Science — University of San Fran

Example

-^ We can use biconditional elimination to rewrite

R^2

as:

◦^ R

B^1 ,^1

⇒^

(P^1 ,^2

∨^ P

∧^ ((

P^1 ,^2

∨^ P

)^2 , 1

⇒^ B

-^ And-elimination on

R^6

produces

R^7

: ((P

P^2 ,^1

)^ ⇒

B^1 ,

-^ Contraposition on

R^7

gives us:

R^8

:^ ¬B

(P^1 ,^2

∨^ P

-^ Modus Ponens with

R^8

and

R^4

produces

R^9

:^ ¬(P

P^2 ,^1

-^ DeMorgan’s then gives us

R^10

:^ ¬P

P^2 ,^1 Department of Computer Science — University of San Francisco – p. 28/

??

Resolution

-^ The preceding rules are sound, but not necessarily complete. •^ Also, search can be inefficient: there might be many operatorsthat can be applied in a particular state. •^ Luckily, there is a complete rule for inference (when coupledwith a complete search algorithm) that uses a single operator. •^ This is called

resolution

◦^ A

∨^ B

and

¬A

∨^ C

allows us to conclude

B^ ∨

C.

◦^ A

is either true or not true. If

A^ is true, then

C^ must be true.

◦^ if^ A^ is false, then

B^ must be true.

◦^ This can be generalized to clauses of any length.

Department of Computer Science — University of San Francisco – p. 29/

??

Conjunctive Normal Form

-^ Resolution works with disjunctions. •^ This means that our knowledge base needs to be in this form. •^ Conjunctive Normal Form is a conjunction of clauses that aredisjunctions. •^ (A

∨^ B

∨^ C

)^ ∧^ (

D^ ∨

E^ ∨

F^ )^ ∧

(G^ ∨

H^ ∨

I)^ ∧

-^ Every propositional logic sentence can be converted to CNF.

Department of Computer Science — University of San Fran

How to use a KB: Forward Chaining

-^ Forward chaining involves starting with a KB and continuallyapplying Modus Ponens to derive all possible facts. •^ This is sometimes called data-driven reasoning •^ Start with domain knowledge and see what that knowledge tellsyou. •^ This is very useful for discovering new facts or rules •^ Less helpful for proving a specific sentence true or false^ ◦

Search is not directed towards a goal

Department of Computer Science — University of San Francisco – p. 37/

??

How to Use A KB: Backward Chaining

-^ Backward chaining starts with the goal and “works backward” tothe start. •^ Example: If we want to show that

A^ is entailed, find a sentence

whose consequent is

A.

-^ Then try to prove that sentence’s antecendents. •^ This is sometimes called query-driven reasoning. •^ More effective at proving a particular query, since search isfocused on a goal. •^ Less likely to discover new and unknown information. •^ Means-ends analysis is a similar sort of reasoning. •^ Prolog uses backward chaining.

Department of Computer Science — University of San Francisco – p. 38/

??

Strengths of Propositional Logic

-^ Declarative - knowledge can be separated from inference. •^ Can handle partial information •^ Can compose more complex sentences out of simpler ones. •^ Sound and complete inference mechanisms (efficient for Hornclauses)

Department of Computer Science — University of San Fran

Weaknesses of Propositional logic

-^ Exponential increase in number of literals •^ No way to describe relations between objects •^ No way to quantify over objects. •^ First-order logic is a mechanism for dealing with theseproblems. •^ As always, there will be tradeoffs.^ ◦

There’s no free lunch!

Department of Computer Science — University of San Francisco – p. 40/

??

Applications

-^ Propositional logic can work nicely in bounded domains^ ◦

All objects of interest can be enumerated.

-^ Fast algorithms exist for solving SAT problems via modelchecking.^ ◦

Search all models to find one that satisfies a sentence. ◦ Can be used for some scheduling and planning problems

-^ Constraint satisfaction problems can be expressed inpropositional logic.^ ◦

Often, we’ll use a predicate-ish notation as syntactic sugar.

Department of Computer Science — University of San Francisco – p. 41/

??