38
AI Topics Search Reasoning Expert Systems Natural Language Understanding Planning and Robotics

AI Topics Search Reasoning Expert Systems Natural Language Understanding Planning and Robotics

Embed Size (px)

Citation preview

Page 1: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

AI Topics Search

Reasoning Expert Systems

Natural Language Understanding Planning and Robotics

Page 2: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Search(Game Playing)General Description

A game or puzzle is represented as a graph, with nodes representing states and arcs connecting nodes if there is a legal move from one state to the other.

Example Tic-Tac-Toe : A two person game with 9 nodes initally blank. The nodes are 3 x 3. A player (0 or x) makes a move by labeling an unlabeled node 0 or x. A winning state is 3 nodes in a row, column, or diagonal labeled the same.

Page 3: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

State Space

• States – A configuration of a game or puzzle is called a state of the game or puzzle. A game has a finite (or countable) set of states called it’s state space. The state space has initial states and final states.

• Arcs – Two adjacent states are linked by an arc. The game is played by a player moving from one state via an arc to an adjacent state.

• Winning – A player wins a game by moving along a path which begins with an initial state and ends with a final or winning state. His opponent plays every other state.

Page 4: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Tic Tac Toe

• Tic Tac Toe is a 3 x 3 game with a state space of 9 x 3 states.• Each state is labeled 0 or x or is unlabeled.• Each state is numbered by its row (1,2,3) and by its column

(1,2,3)• Each state belongs to a row, a column, and to one or two

diagonals {(1,1) (2,2) (3,3)} or {(1,3) (2,2) (3,1)}• A play is recorded when one player labels a state.• A win occurs when one player has labeled a row, a column or

one of the two diagonals.

Page 5: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

State Space for Tic Tac Toe

• State names – row, column, diagonal• 111 , 12x , 132 , . . .

• Arc names – vertex1,vertex2• 11x-12x, 12x – 13x , . . .

Page 6: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

State Space for Nim

Page 7: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Automated Reasoning

General Description

The basis of automated reasoning is a declarative statement or proposition. The proposition has a truth value of True of False. Logic operators operate on the propositions and the resulting propositions have a truth value.Predicate calculus is like propositional calculus with the addition of predicates which are truth valued relations.

Example Propositional Calculus P = It is raining Or the car won’t start. Q : It is raining R : The car won’t start. Q Or RPredicate Calculus If it is raining then the car won’t start. If Q then R.

Page 8: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Propositional Calculus• A proposition is an atomic statement (no logical

connectives such as And, Or) which has a truth value of True or False

• Notation – A proposition is denoted by a capital letter such as P.

• Connectives – And, Or, If, Not are connectives which yield a compound propostion with truth value given below:

• And T F Or T F If T F Not T F T T F T T T T T T T F F F F F F T F F F T F T T

Page 9: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Predicate Calculus

• Predicate – Predicate calculus symbols may represent – variables denoting a class of objects ; variable symbols begin with

an uppercase letter such as People, Students, etc– constant names denoting a single object ; constant symbols begin

with a lower case letter such as george, bill’s_car– functions denoting a correspondence between inputs and

outputs; function name begin with a lowercase letter, such as father(bill)

– predicates denoting a correspondence between inputs and a truth value; predicates begin with a lowercase letter, such as hastaken(bill,datastructures).

Page 10: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Rules of Inference• P , P Q then Q - modus ponens• ¬ Q, P Q then ¬ P - modus tollens• P Q, Q R then P R - chaining • (¬ P Q), (P R) (Q R) – resolution• (P R) , (¬ P Q) (P R) (¬ P Q)

– P R ¬R P– ¬ P Q P Q – ¬R Q by chaining– Q R by definition of

Page 11: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Contradiction & Proof by Contradiction

• A contradiction is always false• Suppose A are axioms assumed to be true.

– Want to show A T– If T A False is a tautology, then

• T A must be false• So, since A is true, T must be false and so T is true.

Page 12: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Example of Using Resolution

• Resolution : (¬ P Q), (P R) (Q R) • Modus Ponens : P , (P Q) Q1.P2.P Q ¬ P Q3.¬ Q4.Q resolution 1,25. resolution 3,46. Q by contradiction

Page 13: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

A Logic-Based Financial Advisor

Featuring modus ponens, and unification

Page 14: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Predicates

English Condition Predicate

Savings account adequate

Amount ≥ 5000 / dependent Savings_account( adequate )

Income Steady, ≥ 15000 , + 4000 for each dependent

Income( adequate )

Conclusion investment

Page 15: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Rules

English Predicate Calculus

If Inadequate savings thenIncrease savings

Investment( savings )

Savings adequate and income adequate

Savings(adequate) ^ income(adequate) investment(stocks)

Savings adequate and income inadequate

Savings(adequate) ^ income(inadequate) investment(combination)

Page 16: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Functions in Predicate Calculus

Functions are used in predicate calculus and have arithmetic values.

Minsavings takes one argument Y = number of dependents and returns 5000 * Y.

Using minsavings the adequacy of savings is determined by the rules:

4. X amount_savings(X) ^ Y ( dependents( Y ) ^ greater(X, minsavings( Y )) savings_accoun( adequate )

5. X amount_savings(X) ^ Y ( dependents( Y ) ^ ¬ greater(X, minsavings( Y )) savings_accoun( inadequate )

Page 17: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Functions for Income

Minincome( X ) = 15000 + (4000 * X) says that the minimum income for a person with X dependents is 15000 + 4000 for each dependent.

X earnings( X, steady ) Y (dependents(Y) greater( X,minincome(Y))) income( adequate )

X earnings( X, steady ) Y (dependents(Y) ¬ greater( X,minincome(Y))) income( inadequate )

X earnings( X,unsteady ) income(inadequate)

Page 18: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

English to Predicate Calculus_

English Predicate Calculus

If it doesn’t rain on Monday,Tom will go to the mountains.

~ weather(rain,Monday) go( Tom, mountains )

Emma is a Doberman pinscher and a good dog.

Isa(Emma,good_dog) ^ Isa(Emma, Doberman_pinscher)

All basketball players are tall. X (basketball_player(X) tall(X))

Some people like anchovies X (person(X) ^ like(X,anchovies) )

If wishes were horses, beggars would ride.

equal(wishes,horses) ride(beggars)

Page 19: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Expert Systems

General Description Expert systems involve a restricted problem involving the diagnosis of a cause or the prediction of the effect of a cause. In medicine we want to know the diagnosis of an illness or else we want to know the effect of some conditions.

Example Automotive diagnosis: If carburator has gas then fuel OK. If fuel OK and plug has spark then engine will fire.

Page 20: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

20

CLIPS Target Language

CLIPS is rule based – forward chaining

CLIPS inference engine uses the RETE algorithm for pattern matching and rule firing so CLIPS is very efficient.

CLIPS employs LISP – Like syntax for expression of facts and rule patterns and actions

Page 21: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

CLIPS

Clips infers new knowledge by using named rule templates consisting of an antecedent which must match facts in the fact list and a consequent which adds or modifies facts.

Fact List

Rule List(defrule calculate_basic

?p <- (pay (hours ?h)(rate ?r)) (test (<= ?h 40))

=> (assert (basic_pay (* ?h ?r)))

(retract ?p))

Page 22: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

22

CLIPS Inferencing

Page 23: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

CLIPS

Rule List

Rule List(defrule calculate_basic

?p <- (pay (hours ?h)(rate ?r)) (test (<= ?h 40))

=> (assert (basic_pay (* ?h ?r)))

(retract ?p))

(defrule calculate_overtime (pay (hours ?h)(rate ?r))

(test (> ?h 40)) (status incomplete)

=> (assert (overtime (* (- ?h 40) (* ?r 1.5))))

) (defrule calculate_regular

(pay (hours ?h)(rate ?r)) (status incomplete)

(test (> ?h 40)) =>

(assert (regular (* 40 ?r) )))

(defrule calculate_adjustedgross (regular ?r)

(overtime ?o) (status incomplete)

=> (assert (adjusted_gross (+ ?r ?o)))

(assert (status done)))

(deftemplate pay (slot hours)(slot rate))

(deffacts payroll ( pay (hours 44)(rate 8)) (status incomplete))

Page 24: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Running Clips

Page 25: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Clips example 2deftemplate area (slot length) (slot width))

(deffacts areafacts (area (length 10) (width 8)))

(defrule calc (area (length ?l) (width ?w)) => (assert (rect (* ?l ?w))))

Page 26: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Example 3 –Tic Tac Toe• (deftemplate square (slot row) (slot column) (slot diag) (slot mark))• (deftemplate player (slot play))• (deftemplate winner (slot person))

• (deffacts state• (square (row 1) (column 1) (diag 1) (mark n))• (square (row 1) (column 2) (diag n) (mark n))• (square (row 1) (column 3) (diag 2) (mark n))• (square (row 2) (column 1) (diag n) (mark n))• (square (row 2) (column 2) (diag b) (mark n))• (square (row 2) (column 3) (diag n) (mark n))• (square (row 3) (column 1) (diag 2) (mark n))• (square (row 3) (column 2) (diag n) (mark n))• (square (row 3) (column 3) (diag 1) (mark n))• (player (play computer))• )

• (defrule mark-valid• ?s <- (square (row 1) (column 1) (diag 1) (mark n))• (player (play ?c))• =>• (retract ?s)• (assert (square (row 1) (column 1) (diag 1) (mark ?c)))• )

Page 27: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Example 3 - Output

Page 28: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Natural Language UnderstandingGeneral Description Words correspond to concepts and

complex phrases to structured concepts. An example would be “pigeons” corresponding to a concept. The complex phrase “hunters are shooting pigeons” corresponds to a concept involving several entities and an action.

Example “Hunters are shooting pigeons”Agent : HuntersAction : ShootingObject : Pigeons

Page 29: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Language Understanding

Context Free Grammars,Transition Network Parsers

Page 30: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Stages of Language AnalysisParsing

Sentence

Noun Phrase Verb Phrase Noun Phrase

Noun Verb Noun

Tarzan kissed Jane

Page 31: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Semantic AnalysisInternal Representation

Person : Tarzan Person : Jane

Agent kiss

Instrument

Object

Lips

Page 32: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

1. <Sentence> <Noun_Phrase> <Verb_Phrase> <Noun_Phrase>2. <Noun_Phrase> noun | article noun3. <Verb_Phrase> verb | auxillary_verb4. <Article> a | the5. <Noun> man | hunters | pigeons6. <Verb> likes | bites | shooting

A Context Free Grammar

<Nonterminal> generates sublanguage using rules with nonterminal on left

Terminal (noun, article ..) make up language strings

Word (man,hunters .. ) is a terminal representing itself.

Page 33: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Simple LL Parsing

• Grammar has no empty rules• If A x and A y, then First(x) and First(y) don’t have any

characters in common.• A Simple LL Grammar for some English sentences :

1. S NVP2. N dn3. N n4. V av5. V v6. P N .7. P .

Page 34: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Parsing with a Simple LL grammar• Let T be the unmatched sentential form starting with S.• Let X be the remaining source.

– Let t be the first character of T and x the first character of X.– If t is a nonterminal, there is

• a single rule t Y for which First(Y) contains x. Replace t by rev(Y).• no rule – syntax error

– else t is terminal in which case t = x or syntax error

Grammar Unmatched sentential form Remaining Source

S NVPN dnN nV avV vP N .P .

SNVPnVPVPavPPN..

Hunters are shooting pigeons.Hunters are shooting pigeons.Hunters are shooting pigeons.are shooting pigeons.are shooting pigeons.pigeons.pigeons ..

Page 35: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Planning and Robotics

General Description

Planning assumes a device or robot capable of atomic actions. Planning is the activity of finding a sequence of these atomic actions which accomplish a higher level task, such as moving across an obstacle filled area towards a predefined goal. This is often accomplished via hierarchical problem decomposition.

Example High level task : Move from X to Y

x

W

y

Can reach W from X;

Can reach Y from W

Page 36: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Planning

• Planning involves using special knowledge about the problem• Consider the problem of finding Shortest Paths in Grid Graphs• A grid graph is a graph in which vertices occur as a rectangular array

and have x-y coordinates. Edges have uniform length = 1. Grid graphs can be used to model circuit layout or city street networks.

• Manhattan distance DM (u,v) between two vertices u,v is the sum of the absolute X difference plus the absolute Y difference. This is a lower bound to the graph distance between u and v.

• Given a vertex u and a goal vertex g, the detour of a neighbor v of u with respect to g is T(v) equals 0 If the neighbor v is towards goal g, (not going out of your way) and otherwise the detour is 1.

• The detour of path P is T(P) from start vertex u to vertex v with respect to goal vertex g is the path length |P| + DM(v,g) – DM(u,g).

• Thus |P| = T(P) + DM(u,g) if the end vertex of P is g.• Minimum path length coincides with minimum detour of the path.

Page 37: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Manhattan Distance

• Manhattan distance is – the sum of X distance between two vertices and the Y distance

between the vertices = 4 below

X ------------ 0 ----------- 0 | | | | 0 -------------- 0 Y

Page 38: AI Topics  Search  Reasoning  Expert Systems  Natural Language Understanding  Planning and Robotics

Shortest Path Routing using Manhattan Distance