CS G120 Artificial Intelligence - PowerPoint PPT Presentation

1 / 64
About This Presentation
Title:

CS G120 Artificial Intelligence

Description:

CS G120 Artificial Intelligence. Prof. C. Hafner. Class Notes Feb ... edible ^ healthy recommended. apple fruit. banana fruit. spinach vegetable. spinach green ... – PowerPoint PPT presentation

Number of Views:48
Avg rating:3.0/5.0
Slides: 65
Provided by: carole5
Category:

less

Transcript and Presenter's Notes

Title: CS G120 Artificial Intelligence


1
CS G120 Artificial Intelligence
  • Prof. C. Hafner
  • Class Notes Feb 12, 2009

2
Forward chaining algorithm
  • forwardChain(KB, percept) returns updated KB
  • new-knowledge percept
  • while new-knowledge is not empty
  • p ? pop(new-knowledge)
  • add p to KB
  • for each rule r in KB with p contained in
    LHS(r)
  • if all elements of LHS(r) are in KB
  • push (RHS(r), new-knowledge)
  • return KB
  • --------------------------------------------------
    ----------------
  • Requires an index of the rule set by LHS symbols

3
Feedback on programs
  • C omments in code!!!!!!!!!
  • Some incorrect answers
  • Representation issues OO would be better
  • Some ideas for making the code simpler, more
    readable
  • KB.facts a list of the facts
  • KB.rules a list of the rules
  • Rule.lhs
  • Rule.rhs
  • Testing generally inadequate
  • What should the test cases include?

4
Example
  • KB fruit ? edible
  • vegetable ? edible
  • vegetable green ? healthy
  • edible healthy ? recommended
  • apple ? fruit
  • banana ? fruit
  • spinach ? vegetable
  • spinach ? green
  • apple
  • Correct answer for forwardChain(KB, spinach)
  • Correct answer for makeExplicit(KB)

5
Backward chaining algorithm
  • SUBST(COMPOSE(?1, ?2), p) SUBST(?2, SUBST(?1,
    p))

6
Example knowledge base
  • The law says that it is a crime for an American
    to sell weapons to hostile nations. The country
    Nono, an enemy of America, has some missiles, and
    all of its missiles were sold to it by Colonel
    West, who is American.
  • Prove that Col. West is a criminal

7
Example knowledge base contd.
  • ... it is a crime for an American to sell weapons
    to hostile nations
  • American(x) ? Weapon(y) ? Sells(x,y,z) ?
    Hostile(z) ? Criminal(x)
  • Nono has some missiles, i.e., ?x Owns(Nono,x) ?
    Missile(x)
  • Owns(Nono,M1) and Missile(M1)
  • all of its missiles were sold to it by Colonel
    West
  • Missile(x) ? Owns(Nono,x) ? Sells(West,x,Nono)
  • Missiles are weapons
  • Missile(x) ? Weapon(x)
  • An enemy of America counts as "hostile
  • Enemy(x,America) ? Hostile(x)
  • West, who is American
  • American(West)
  • The country Nono, an enemy of America
  • Enemy(Nono,America)

8
Backward chaining example
9
Backward chaining example
10
Backward chaining example
11
Backward chaining example
12
Backward chaining example
13
Backward chaining example
14
Backward chaining example
15
Backward chaining example
16
Properties of backward chaining
  • Depth-first recursive proof search space is
    linear in size of proof
  • Incomplete due to infinite loops
  • ? fix by checking current goal against every goal
    on stack
  • Inefficient due to repeated subgoals (both
    success and failure)
  • ? fix using caching of previous results (extra
    space)
  • Widely used for logic programming

17
Logic programming Prolog
  • Algorithm Logic Control
  • Basis backward chaining with Horn clauses
    bells whistles
  • Widely used in Europe, Japan (basis of 5th
    Generation project)
  • Compilation techniques ? 60 million LIPS
  • Program set of clauses head - literal1,
    literaln.
  • criminal(X) - american(X), weapon(Y),
    sells(X,Y,Z), hostile(Z).
  • Depth-first, left-to-right backward chaining
  • Built-in predicates for arithmetic etc., e.g., X
    is YZ3
  • Built-in predicates that have side effects (e.g.,
    input and output
  • predicates, assert/retract predicates)
  • Closed-world assumption ("negation as failure")
  • e.g., given alive(X) - not dead(X).
  • alive(joe) succeeds if dead(joe) fails

18
EXAMPLES
  • likes(X, pizza) ? likes(X, spaghetti)
  • drinks(X, beer) drinks(X, wine) ? likes(X,
    pizza)
  • likes(X, Y) Knows(X, Z) ? Likes(Z, Y)
  • likes(john, pizza)
  • drinks(sally, beer)
  • drinks(sam, beer)
  • drinks(sam, wine)
  • knows(mary, john)
  • knows(john, tom)
  • knows(steve, sue)
  • Query who likes spaghetti?
  • Add knows(W, V) ? Knows(V, W)

19
Challenge create a representation for clauses
  • Variables begin X, Y, or Z (upper case)
  • Predicate and function symbols and constants
    begin with lower case letters
  • Logical symbols are
  • AND OR NOT IMPLIES EXISTS FORALL TRUE FALSE
  • (no ??) is provided
  • A python class called FOLexp whose constructor
    takes an expression (a string) in this language
    using () and returns an instance of the class
    will be posted on blackboard. The class has two
    components op and args where the args is a tuple
    (NOT a list). The null symbol None will be
    returned for bad input.
  • There will be a method for finding out if a
    FOLexp is an atom or a tuple, and for finding out
    if an FOLexp is a variable.

20
Assignment 4b. Due Feb 19
  • In one file
  • Standardize (e) returns a FOLexp object with the
    variables replaced with new variables with unique
    names.
  • Unify(e1, e2) returns fail or a substitution,
    which is a list of variable/term pairs (2 element
    lists).
  • These programs must be accompanied GOOD test
    datasets, and programs testStandardize() and
    testUnify() that runs them.

21
New topic Search
  • Classic Search Problems
  • Missionaries and Cannibals
  • 8 puzzle
  • 4 color map problem
  • Path finding
  • Resource allocation/scheduling
  • Relationship to operations research

22
The search framework for problem solving
  • Given
  • A set of discrete states (usually finite, but
    often very large) that define the problem space
  • A designated start state
  • A subset of designated goal states
  • A set of operators or actions the agent can
    perform at each state
  • A function Next State x Op ? State
  • Objective find a sequence of operators that, if
    applied beginning in the start state, will lead
    to a goal state
  • Or find the shortest or least-cost sequence

23
Explore the problems space by generating and
searching a tree
  • Root start state
  • Each node represents a state, children are all
    the next-states

24
Example The 8-puzzle
  • states?
  • actions?
  • goal test?
  • path cost?

25
Example The 8-puzzle
  • states? locations of tiles
  • actions? move blank left, right, up, down
  • goal test? goal state (given)
  • path cost? 1 per move
  • Note optimal solution of n-Puzzle family is
    NP-hard

26
Example Romania
27
Example Romania
  • On holiday in Romania currently in Arad.
  • Flight leaves tomorrow from Bucharest
  • Formulate goal
  • be in Bucharest
  • Formulate problem
  • states various cities
  • actions drive between cities
  • Find solution
  • sequence of cities, e.g., Arad, Sibiu, Fagaras,
    Bucharest

28
Tree search example
29
Tree search example
30
Tree search example
31
Implementation general tree search
32
Implementation states vs. nodes
  • A state is a (representation of) a physical
    configuration
  • A node is a data structure constituting part of a
    search tree includes state, parent node, action,
    path cost g(x), depth
  • The Expand function creates new nodes, filling in
    the various fields and using the SuccessorFn of
    the problem to create the corresponding states.

33
Search strategies
  • A search strategy is defined by picking the order
    of node expansion
  • Strategies are evaluated along the following
    dimensions
  • completeness does it always find a solution if
    one exists?
  • time complexity number of nodes generated
  • space complexity maximum number of nodes in
    memory
  • optimality does it always find a least-cost
    solution?
  • Time and space complexity are measured in terms
    of
  • b maximum branching factor of the search tree
  • d depth of the least-cost solution
  • m maximum depth of the state space (may be 8)

34
Uninformed search strategies
  • Uninformed search strategies use only the
    information available in the problem definition
  • Breadth-first search
  • Uniform-cost search
  • Depth-first search
  • Depth-limited search
  • Iterative deepening search

35
Breadth-first search
  • Expand shallowest unexpanded node
  • Implementation
  • fringe is a FIFO queue, i.e., new successors go
    at end

36
Breadth-first search
  • Expand shallowest unexpanded node
  • Implementation
  • fringe is a FIFO queue, i.e., new successors go
    at end

37
Breadth-first search
  • Expand shallowest unexpanded node
  • Implementation
  • fringe is a FIFO queue, i.e., new successors go
    at end

38
Breadth-first search
  • Expand shallowest unexpanded node
  • Implementation
  • fringe is a FIFO queue, i.e., new successors go
    at end

39
Properties of breadth-first search
  • Complete? Yes (if b is finite)
  • Time? 1bb2b3 bd b(bd-1) O(bd1)
  • Space? O(bd1) (keeps every node in memory)
  • Optimal? Yes (if cost 1 per step)
  • Space is the bigger problem (more than time)

Hypothetical in text illustrating the problem of
an exponential complexity bound b (branching
factor) 10, a node uses 1000 bytes, and 10,000
nodes per second can be generated. A solution
at depth 8 takes 31 hours and uses 1 terabyte.
At level 9 it is 129 days and 101 terabytes.
40
Uniform-cost search
  • Expand least-cost unexpanded node
  • Implementation
  • fringe queue ordered by path cost
  • Equivalent to breadth-first if step costs all
    equal
  • Complete? Yes, if step cost e
  • Time? of nodes with g cost of optimal
    solution, O(bceiling(C/ e)) where C is the cost
    of the optimal solution
  • Space? of nodes with g cost of optimal
    solution, O(bceiling(C/ e))
  • Optimal? Yes nodes expanded in increasing order
    of g(n)

41
Depth-first search
  • Expand deepest unexpanded node
  • Implementation
  • fringe LIFO queue, i.e., put successors at
    front

42
Depth-first search
  • Expand deepest unexpanded node
  • Implementation
  • fringe LIFO queue, i.e., put successors at
    front

43
Depth-first search
  • Expand deepest unexpanded node
  • Implementation
  • fringe LIFO queue, i.e., put successors at
    front

44
Depth-first search
  • Expand deepest unexpanded node
  • Implementation
  • fringe LIFO queue, i.e., put successors at
    front

45
Depth-first search
  • Expand deepest unexpanded node
  • Implementation
  • fringe LIFO queue, i.e., put successors at
    front

46
Depth-first search
  • Expand deepest unexpanded node
  • Implementation
  • fringe LIFO queue, i.e., put successors at
    front

47
Depth-first search
  • Expand deepest unexpanded node
  • Implementation
  • fringe LIFO queue, i.e., put successors at
    front

48
Depth-first search
  • Expand deepest unexpanded node
  • Implementation
  • fringe LIFO queue, i.e., put successors at
    front

49
Depth-first search
  • Expand deepest unexpanded node
  • Implementation
  • fringe LIFO queue, i.e., put successors at
    front

50
Depth-first search
  • Expand deepest unexpanded node
  • Implementation
  • fringe LIFO queue, i.e., put successors at
    front

51
Depth-first search
  • Expand deepest unexpanded node
  • Implementation
  • fringe LIFO queue, i.e., put successors at
    front

52
Depth-first search
  • Expand deepest unexpanded node
  • Implementation
  • fringe LIFO queue, i.e., put successors at
    front

53
Properties of depth-first search
  • Complete? No fails in infinite-depth spaces,
    spaces with loops
  • Modify to avoid repeated states along path
  • ? complete in finite spaces
  • Time? O(bm) terrible if m is much larger than d
  • but if solutions are dense, may be much faster
    than breadth-first. (m is maximum depth)
  • Space? O(bm), i.e., linear space!
  • Optimal? No

54
Depth-limited search
  • depth-first search with depth limit l,
  • i.e., nodes at depth l have no successors
  • Recursive implementation

55
Iterative deepening search
56
Iterative deepening search l 0
57
Iterative deepening search l 1
58
Iterative deepening search l 2
59
Iterative deepening search l 3
60
Iterative deepening search
  • Number of nodes generated in a depth-limited
    search to depth d with branching factor b
  • NDLS b0 b1 b2 bd-2 bd-1 bd
  • Number of nodes generated in an iterative
    deepening search to depth d with branching factor
    b
  • NIDS (d1)b0 d b1 (d-1)b2 3bd-2
    2bd-1 1bd
  • For b 10, d 5,
  • NDLS 1 10 100 1,000 10,000 100,000
    111,111
  • NIDS 6 50 400 3,000 20,000 100,000
    123,456
  • Overhead (123,456 - 111,111)/111,111 11

61
Properties of iterative deepening search
  • Complete? Yes
  • Time? (d1)b0 d b1 (d-1)b2 bd O(bd)
  • Space? O(bd)
  • Optimal? Yes, if step cost 1

62
Summary of algorithms
63
Repeated states
  • Failure to detect repeated states can turn a
    linear problem into an exponential one!

64
Graph search (Dynamic Programming)
Write a Comment
User Comments (0)
About PowerShow.com