CMSC 471 CMSC 471 Fall 2015 Fall 2015 Class #3 Class #3 - - PowerPoint PPT Presentation

cmsc 471 cmsc 471 fall 2015 fall 2015
SMART_READER_LITE
LIVE PREVIEW

CMSC 471 CMSC 471 Fall 2015 Fall 2015 Class #3 Class #3 - - PowerPoint PPT Presentation

CMSC 471 CMSC 471 Fall 2015 Fall 2015 Class #3 Class #3 Thursday 9/3/15 Thursday 9/3/15 Problem Solving as Search Problem Solving as Search Todays class Goal-based agents Representing states and operators Example problems


slide-1
SLIDE 1

CMSC 471 CMSC 471 Fall 2015 Fall 2015

Class #3 Class #3 Thursday 9/3/15 Thursday 9/3/15 Problem Solving as Search Problem Solving as Search

slide-2
SLIDE 2

Today’s class

  • Goal-based agents
  • Representing states and operators
  • Example problems
  • Generic state-space search algorithm
  • Lisp lab!
slide-3
SLIDE 3

Characteristics of environments

Fully

  • bservable?

Deterministic? Episodic? Static? Discrete? Single agent?

Solitaire Backgammon Taxi driving Internet shopping Medical diagnosis

slide-4
SLIDE 4

Characteristics of environments

Fully

  • bservable?

Deterministic? Episodic? Static? Discrete? Single agent?

Solitaire No Yes Yes Yes Yes Yes Backgammon Taxi driving Internet shopping Medical diagnosis

slide-5
SLIDE 5

Characteristics of environments

Fully

  • bservable?

Deterministic? Episodic? Static? Discrete? Single agent?

Solitaire No Yes Yes Yes Yes Yes Backgammon Yes No No Yes Yes No Taxi driving Internet shopping Medical diagnosis

slide-6
SLIDE 6

Characteristics of environments

Fully

  • bservable?

Deterministic? Episodic? Static? Discrete? Single agent?

Solitaire No Yes Yes Yes Yes Yes Backgammon Yes No No Yes Yes No Taxi driving No No No No No No Internet shopping Medical diagnosis

slide-7
SLIDE 7

Characteristics of environments

Fully

  • bservable?

Deterministic? Episodic? Static? Discrete? Single agent?

Solitaire No Yes Yes Yes Yes Yes Backgammon Yes No No Yes Yes No Taxi driving No No No No No No Internet shopping No No No No Yes No Medical diagnosis

slide-8
SLIDE 8

Characteristics of environments

Fully

  • bservable?

Deterministic? Episodic? Static? Discrete? Single agent?

Solitaire No Yes Yes Yes Yes Yes Backgammon Yes No No Yes Yes No Taxi driving No No No No No No Internet shopping No No No No Yes No Medical diagnosis No No No No No Yes

→ Lots of real-world domains fall into the hardest case!

slide-9
SLIDE 9

Summary

  • An agent perceives and acts in an environment, has an

architecture, and is implemented by an agent program.

  • An ideal agent always chooses the action which maximizes its

expected performance, given its percept sequence so far.

  • An autonomous agent uses its own experience rather than built-in

knowledge of the environment by the designer.

  • An agent program maps from percept to action and updates its

internal state.

– Reflex agents respond immediately to percepts. – Goal-based agents act in order to achieve their goal(s). – Utility-based agents maximize their own utility function.

  • Representing knowledge is important for successful agent design.
  • The most challenging environments are partially observable,

stochastic, sequential, dynamic, and continuous, and contain multiple intelligent agents.

slide-10
SLIDE 10

Problem Solving Problem Solving as Search as Search

Chapter 3.1-3.3

Some material adopted from notes by Charles R. Dyer, University of Wisconsin-Madison

slide-11
SLIDE 11

Pre-Reading Review

  • What is search (a.k.a. state-space search)?
  • What are these concepts in search?

– Initial state – Actions / transition model – State space graph – Step cost / path cost – Goal test (cf. goal) – Solution / optimal solution

  • What is an open-loop system?
  • What is the difference between expanding a state and

generating a state?

  • What is the frontier (a.k.a. open list)?
slide-12
SLIDE 12

Representing actions

  • Note also that actions in this framework can all be considered

as discrete events that occur at an instant of time.

– For example, if “Mary is in class” and then performs the action “go home,” then in the next situation she is “at home.” There is no representation of a point in time where she is neither in class nor at home (i.e., in the state of “going home”).

  • The number of actions / operators depends on the

representation used in describing a state.

– In the 8-puzzle, we could specify 4 possible moves for each of the 8 tiles, resulting in a total of 4*8=32 operators. – On the other hand, we could specify four moves for the “blank” square and we would only need 4 operators.

  • Representational shift can greatly simplify a problem!
slide-13
SLIDE 13

Representing states

  • What information is necessary to encode about the world to

sufficiently describe all relevant aspects to solving the goal? That is, what knowledge needs to be represented in a state description to adequately describe the current state or situation of the world?

  • The size of a problem is usually described in terms of the

number of states that are possible. – Tic-Tac-Toe has about 39 states. – Checkers has about 1040 states. – Rubik’s Cube has about 1019 states. – Chess has about 10120 states in a typical game.

slide-14
SLIDE 14

Closed World Assumption

  • We will generally use the Closed World

Assumption.

  • All necessary information about a problem domain

is available in each percept so that each state is a complete description of the world.

  • There is no incomplete information at any point in

time.

slide-15
SLIDE 15

Knowledge representation issues

  • What’s in a state ?

– Is the color of the boat relevant to solving the Missionaries and Cannibals problem? Is sunspot activity relevant to predicting the stock market? What to represent is a very hard problem that is usually left to the system designer to specify.

  • What level of abstraction or detail to describe the world.

– Too fine-grained and we’ll “miss the forest for the trees.” Too coarse- grained and we’ll miss critical details for solving the problem.

  • The number of states depends on the representation and level
  • f abstraction chosen.

– In the Remove-5-Sticks problem, if we represent the individual sticks, then there are 17-choose-5 possible ways of removing 5 sticks. On the

  • ther hand, if we represent the “squares” defined by 4 sticks, then there

are 6 squares initially and we must remove 3 squares, so only 6-choose- 3 ways of removing 3 squares.

slide-16
SLIDE 16

Formalizing search in a state space

  • A state space is a graph (V, E) where V is a set of nodes

and E is a set of arcs, and each arc is directed from a node to another node

  • Each node is a data structure that contains a state

description plus other information such as the parent of the node, the name of the operator that generated the node from that parent, and other bookkeeping data

  • Each arc corresponds to an instance of one of the operators.

When the operator is applied to the state associated with the arc’s source node, then the resulting state is the state associated with the arc’s destination node

slide-17
SLIDE 17

Formalizing search II

  • Each arc has a fixed, positive cost associated with it

corresponding to the cost of the operator.

  • Each node has a set of successor nodes corresponding to all
  • f the legal operators that can be applied at the source

node’s state.

– The process of expanding a node means to generate all of the successor nodes and add them and their associated arcs to the state- space graph

  • One or more nodes are designated as start nodes.
  • A goal test predicate is applied to a state to determine if its

associated node is a goal node.

slide-18
SLIDE 18

Water Jug Problem

Given a full 5-gallon jug and an empty 2-gallon jug, the goal is to fill the 2-gallon jug with exactly one gallon of water.

  • State = (x,y), where x is

the number of gallons

  • f water in the 5-gallon

jug and y is # of gallons in the 2-gallon jug

  • Initial State = (5,0)
  • Goal State = (*,1),

where * means any amount Name Cond. Transition Effect Empty5 – (x,y)→(0,y) Empty 5-gal. jug Empty2 – (x,y)→(x,0) Empty 2-gal. jug 2to5 x ≤ 3 (x,2)→(x+2,0) Pour 2-gal. into 5-gal. 5to2 x ≥ 2 (x,0)→(x-2,2) Pour 5-gal. into 2-gal. 5to2part y < 2 (1,y)→(0,y+1) Pour partial 5-gal. into 2- gal.

Operator table

slide-19
SLIDE 19

5, 2 3, 2 2, 2 1, 2 4, 2 0, 2 5, 1 3, 1 2, 1 1, 1 4, 1 0, 1 5, 0 3, 0 2, 0 1, 0 4, 0 0, 0 Empty2 Empty5 2to5 5to2 5to2part

Water jug state space

slide-20
SLIDE 20

5, 2 3, 2 2, 2 1, 2 4, 2 0, 2 5, 1 3, 1 2, 1 1, 1 4, 1 0, 1 5, 0 3, 0 2, 0 1, 0 4, 0 0, 0

Water jug solution

slide-21
SLIDE 21

Formalizing search IV

  • State-space search is the process of searching through a

state space for a solution by making explicit a sufficient portion of an implicit state-space graph to find a goal node.

– For large state spaces, it isn’t practical to represent the whole space. – Initially V={S}, where S is the start node; when S is expanded, its successors are generated and those nodes are added to V and the associated arcs are added to E. This process continues until a goal node is found.

  • Each node implicitly or explicitly represents a partial

solution path (and cost of the partial solution path) from the start node to the given node.

– In general, from this node there are many possible paths (and therefore solutions) that have this partial path as a prefix.

slide-22
SLIDE 22

State-space search algorithm

function general-search (problem, QUEUEING-FUNCTION) ;; problem describes the start state, operators, goal test, and operator costs ;; queueing-function is a comparator function that ranks two states ;; general-search returns either a goal node or failure nodes = MAKE-QUEUE(MAKE-NODE(problem.INITIAL-STATE)) loop if EMPTY(nodes) then return "failure" node = REMOVE-FRONT(nodes) if problem.GOAL-TEST(node.STATE) succeeds then return node nodes = QUEUEING-FUNCTION(nodes, EXPAND(node, problem.OPERATORS)) end ;; Note: The goal test is NOT done when nodes are generated ;; Note: This algorithm does not detect loops

slide-23
SLIDE 23

Key procedures to be defined

  • EXPAND

– Generate all successor nodes of a given node

  • GOAL-TEST

– Test if state satisfies all goal conditions

  • QUEUEING-FUNCTION

– Used to maintain a ranked list of nodes that are candidates for expansion

slide-24
SLIDE 24

Bookkeeping

  • Typical node data structure includes:

– State at this node – Parent node – Operator applied to get to this node – Depth of this node (number of operator applications since initial state) – Cost of the path (sum of each operator application so far)

slide-25
SLIDE 25

Some issues

  • Search process constructs a search tree, where

– root is the initial state and – leaf nodes are nodes

  • not yet expanded (i.e., they are in the list “nodes”) or
  • having no successors (i.e., they’re “deadends” because no
  • perators were applicable and yet they are not goals)
  • Search tree may be infinite because of loops even if state

space is small

  • Return a path or a node depending on problem.

– E.g., in cryptarithmetic return a node; in 8-puzzle return a path

  • Changing definition of the QUEUEING-FUNCTION leads

to different search strategies

slide-26
SLIDE 26

Evaluating search strategies

  • Completeness

– Guarantees finding a solution whenever one exists

  • Time complexity

– How long (worst or average case) does it take to find a solution? Usually measured in terms of the number of nodes expanded

  • Space complexity

– How much space is used by the algorithm? Usually measured in terms of the maximum size of the “nodes” list during the search

  • Optimality/Admissibility

– If a solution is found, is it guaranteed to be an optimal one? That is, is it the one with minimum cost?

slide-27
SLIDE 27

LISP OVERVIEW LISP OVERVIEW

slide-28
SLIDE 28

Why Lisp?

  • Because it’s historically the most widely used AI programming language
  • Because it’s good for writing production software (Graham article)
  • Because it’s a functional programming language, and has lots of features that
  • ther languages don’t
  • Functional programming is great for designing distributed software
  • Because you can write new programs and extend old programs really, really

quickly in Lisp

  • Because it’s a REALLY good experience for CS majors to have to learn a

new language to proficiency in a short period of time. (Kind of like the real world.)

slide-29
SLIDE 29

Why All Those Parentheses?

  • Surprisingly readable if you indent properly
  • Makes prefix notation manageable
  • An expression is an expression is an expression, whether

it’s inside another one or not

  • (+ 1 2)
  • (* (+ 1 2) 3)
  • (list (* 3 5) ‘atom ‘(list inside a list) (list

3 4) ‘(((very) (very) (very) (nested list))))

slide-30
SLIDE 30

Functional Programming

  • Computation == Evaluation of expressions
  • Everything is an expression...
  • ...even a function!
  • Avoid the use of state (global and local variables) and side

effects – “pure” I/O definition of functional behavior

  • Lambda calculus: Formal language for defining and

manipulating functions

  • Recursion is a natural way of thinking in functional

programming languages

  • Truly functional programs are highly parallelizable
slide-31
SLIDE 31

Cool Things About Lisp

  • Functions as objects (pass a function as an argument)
  • Lambda expressions (construct a function on the fly)
  • Lists as first-class objects
  • Program as data
  • Macros (smart expansion of expressions)
  • Symbol manipulation
slide-32
SLIDE 32

Basic Lisp Types

  • Numbers (integers, floating-point, complex)
  • Characters, strings (arrays of chars)
  • Symbols, which have property lists
  • Lists (linked cells)
  • Empty list: nil
  • cons structure has car (first) and cdr (rest)
  • Arrays (with zero or more dimensions)
  • Hash tables
  • Streams (for reading and writing)
  • Structures
  • Functions, including lambda functions
slide-33
SLIDE 33

Basic Lisp Functions

  • Numeric functions: + - * / incf decf
  • List access: car (first), second … tenth, nth, cdr

(rest), last, length

  • List construction: cons, append, list
  • Advanced list processing: assoc, mapcar, mapcan
  • Predicates: listp, numberp, stringp, atom, null,

equal, eql, and, or, not

  • Special forms: setq/setf, quote, defun, if, cond,

case, progn, loop

slide-34
SLIDE 34

Useful Help Facilities

  • (apropos ‘str)  list of symbols whose name contains

‘str

  • (describe ‘symbol)  description of symbol
  • (describe #’fn)  description of function
  • (trace fn)  print a trace of fn as it runs
  • (print “string”)  print output
  • (format …)  formatted output (see Norvig p. 84)
  • :a  abort one level out of debugger
slide-35
SLIDE 35

Great! How Can I Get Started?

  • On sunserver (CS) and gl machines, run /usr/local/bin/clisp
  • From http://clisp.cons.org you can download CLISP for

your own PC (Windows or Linux)

  • Great Lisp resource page:

http://mypage.iu.edu/~colallen/lp/

slide-36
SLIDE 36

LISP BASICS

slide-37
SLIDE 37

Lisp characteristics

  • Lisp syntax: parenthesized prefix notation
  • Lisp interpreter: read-eval-print loop
  • Nested evaluation
  • Preventing evaluation (quote and other special forms)
  • Forcing evaluation (eval)
slide-38
SLIDE 38

Types of objects

  • NIL and T
  • Symbols

– ’a ’x ’shawn

  • Numbers

– 27 -2 7.519

  • Lists

– ’(a b c) ’(2 3 marie)

  • Strings

– ”This is a string!”

  • Characters

– #\x #\- #\B

slide-39
SLIDE 39

Special forms

  • Quote
  • Setf / setq
  • Defun
  • Defparameter / defconstant
  • If
  • Cond
  • Case
  • Loop
  • Mapcar
slide-40
SLIDE 40

Built-in functions

  • For numbers

– + - * / incf decf

  • A diversion: destructive functions

– (setf x 1) – (setf y (+ x 1)) vs. (setf y (incf x))

  • For lists

– car (first) cdr (rest) second third fourth – length nth – cons append nconc – mapcar mapcan – find remove remove-if

  • Printing: print, format
slide-41
SLIDE 41

A Lisp example

  • Writing a function to compute the nth Fibonacci number

– Notes distributed in class… see fib-notes.txt on website