Intelligent Agents 2 AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 1
2 Intelligence Agents Agents Rationality PEAS (Performance measure, Environment, Actuators, Sensors) Environments Agent structures The agent projects AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 2
Agents include an animal agent a human agent a robotic agent (robot) a software agent (softbot) internet agent crawler webbot email agent search agent, etc. Agents AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 3
Agents and environments sensors environment percepts actions? agent actuators An agent is anything that can be viewed as perceiving its environment through sensors and acting upon that environment through actuators AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 4
Agent functions An agent is completely specified by the agent function : maps from percept histories to actions f : P A Find a way to implement the rational agent function concisely AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 5
Agent programs The agent program runs on the physical architecture to produce the agent function agent = architecture + program The agent program takes a single percept as input, keeps internal state function Skeleton-Agent( percept) returns action persistent: memory, the agent s memory of the world memory Update-Memory(memory, percept) action Choose-Best-Action(memory) memory Update-Memory(memory, action) return action The algorithm is described by the pseudocode AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 6
Another form of algorithm A procedure for the skeleton-agent that takes a single percept as input, keeps internal state Procedure of Skeleton-Agent Input: percept Output: action memory the agent s memory of the world 1. memory Update-Memory(memory, percept) 2. action Choose-Best-Action(memory) 3. memory Update-Memory(memory, action) The algorithm is also described by the pseudocode AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 7
The pseudocode The pseudocode is a simple language to describe algorithms similar to programming language like Java, C, Python or Lisp informal to use mathematical formulas or ordinary English to describe parts Persistent variables (global variables): a variable is given an initial value the first time a function is called and retains that value on all subsequent calls to the function. The agent programs use persistent variables for memory. Variables have lowercase italic names. Function as values: The value of a variable is allowed to be a function. Functions and procedures have capitalized names Indentation is significant: the scope of a loop or conditional AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 8
The pseudocode Assignment: x value means that the right-hand side evaluate to the left-hand side variable Destructuring assignment: x, y pair means that the right-hand side evaluate to a two-element tuple, and the first element is assigned to x and the second to y. Or for each x,y in pair do if-then (-else): if c then else means that if the condition c is hold then doing something; otherwise doing something else for each: for each x in c do means that the loop is executed with the variable x bound to successive elements of the collection c. Or while c do or even loop Generators and yield: generator G(x) yields number defines G as a generator function AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 9
Lists: [x,y,z], [first rest] Sets: {x,y,z} The pseudocode Arrays start at 1: as in usual mathematical notation, not 0 as in Java and C AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 10
The code The algorithms in the pseudocode can be implemented in Java, C/C++, Python, Lisp and Prolog etc. The (Lisp) code for each topic is divided into four directories: agents: code defining agent types and programs algorithms: code for the methods used by the agent programs environments: code defining environment types, simulations domains: problem types and instances for input to algorithms (Often run algorithms on domains rather than agents in environments) AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 11
A coding (Lisp) (setq joe (make-agent :name joe :body (make-agent-body) :program (make-dumb-agent-program))) (defun make-dumb-agent-program () (let ((memory nil)) # (lambda (percept) (push percept memory) no-op))) AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 12
Rationality A rational agent is one that does right thing Without loss of generality, goals specifiable by performance measure defining a numerical value for any environment history Rational action: whichever action maximizes the expected value of the performance measure given the percept sequence to date Rational omniscient percepts may not supply all relevant information Rational clairvoyant action outcomes may not be as expected rational successful AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 13
Vacuum-cleaner world A B Percepts: location and contents, e.g., [A, Dirty] Actions: Left, Right, Suck, NoOp AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 14
A vacuum-cleaner agent Percept sequence Action [A, Clean] Right [A, Dirty] Suck [B, Clean] Lef t [B, Dirty] Suck [A, Clean], [A, Clean] Right [A, Clean], [A, Dirty]. Suck. function Reflex-Vacuum-Agent([location,status]) returns an action if status = Dirty then return Suck else if location = A then return Right else if location = B then return Left What is the right function? Can it be implemented in a program? AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 15
Vacuum-cleaner rational agent Fixed performance measure evaluates the environment sequence one point per square cleaned up in time T? one point per clean square per time step, minus one per move? penalize for > k dirty squares? AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 16
PEAS To design a rational agent, we must specify the task environment E.g., an automated taxi (intelligent vehicle): Performance measure?? Environment?? Actuators?? Sensors?? AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 17
Automated taxi agent To design a rational agent, we must specify the task environment E.g., an automated taxi: Performance measure?? safety, destination, profits, legality,... Environment?? streets, traffic, pedestrians, weather,... Actuators?? steering, accelerator, brake, horn, speaker/display,... Sensors?? video, accelerometers, gauges, engine sensors, GPS,... AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 18
Performance measure?? Environment?? Actuators?? Sensors?? Internet shopping agent AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 19
Internet shopping agent Performance measure?? price, quality, appropriateness, efficiency,... Environment?? web sites, vendors, shippers,... Actuators?? display to user, follow URL, fill in form,... Sensors?? pages (text, graphics, scripts),... AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 20
Environments Observable?? Deterministic?? Episodic?? Static?? Discrete?? Single-agent?? Solitaire Backgammon Internet shopping Taxi AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 21
Environments Solitaire Backgammon Internet shopping Taxi Observable?? Yes Yes No No Deterministic?? Episodic?? Static?? Discrete?? Single-agent?? AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 22
Environments Solitaire Backgammon Internet shopping Taxi Observable?? Yes Yes No No Deterministic?? Yes No Partly No Episodic?? Static?? Discrete?? Single-agent?? AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 23
Environments Solitaire Backgammon Internet shopping Taxi Observable?? Yes Yes No No Deterministic?? Yes No Partly No Episodic?? No No No No Static?? Discrete?? Single-agent?? AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 24
Environments Solitaire Backgammon Internet shopping Taxi Observable?? Yes Yes No No Deterministic?? Yes No Partly No Episodic?? No No No No Static?? Yes Semi Semi No Discrete?? Single-agent?? AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 25
Environments Solitaire Backgammon Internet shopping Taxi Observable?? Yes Yes No No Deterministic?? Yes No Partly No Episodic?? No No No No Static?? Yes Semi Semi No Discrete?? Yes Yes Yes No Single-agent?? AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 26
Environments Solitaire Backgammon Internet shopping Taxi Observable?? Yes Yes No No Deterministic?? Yes No Partly No Episodic?? No No No No Static?? Yes Semi Semi No Discrete?? Yes Yes Yes No Single-agent?? Yes No Yes (except auctions) No The environment type largely determines the agent design The real world is (of course) partially observable, stochastic, sequential, dynamic, continuous, multi-agent AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 27
Agent structures Agents interact with environments through sensors and actuators Agent Sensors Percepts? Environment Actuators Actions AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 28
Agent structures Four basic types in order of increasing generality: simple reflex agents reflex agents with state goal-based agents utility-based agents All these can be turned into learning agents AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 29
Simple reflex agents Agent Sensors What the world is like now Condition-action rules What action I should do now Environment Actuators AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 30
Simple reflex agents function Simple-Reflex-Agent( percept) returns an action persistent: rules, a set of condition-action rules state Interpret-Input(percept) rule Rule-Match(state, rules) action rule.action return action AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 31
Example function Reflex-Vacuum-Agent([location,status]) returns an action if status = Dirty then return Suck else if location = A then return Right else if location = B then return Left (setq joe (make-agent :name joe :body (make-agent-body) :program (make-reflex-vacuum-agent-program))) (defun make-reflex-vacuum-agent-program () # (lambda (percept) (let ((location (first percept)) (status (second percept))) (cond ((eq status dirty) Suck) ((eq location A) Right) ((eq location B) Left))))) AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 32
Model-based reflex agents State How the world evolves What my actions do Condition-action rules Sensors What the world is like now What action I should do now Environment Agent Actuators AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 33
Example function Reflex-Vacuum-Agent([location,status]) returns an action persistent: last A, last B, numbers, initially if status = Dirty then... (defun make-reflex-vacuum-agent-with-state-program () (let ((last-a infinity) (last-b infinity)) # (lambda (percept) (let ((location (first percept)) (status (second percept))) (incf last-a) (incf last-b) (cond ((eq status dirty) (if (eq location A) (setq last-a 0) (setq last-b 0)) Suck) ((eq location A) (if (> last-b 3) Right NoOp)) ((eq location B) (if (> last-a 3) Left NoOp))))))) AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 34
Goal-based agents Sensors State How the world evolves What the world is like now What my actions do Goals What it will be like if I do action A What action I should do now Environment Agent Actuators AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 35
Utility-based agents Sensors State How the world evolves What the world is like now What my actions do Utility What it will be like if I do action A How happy I will be in such a state Environment Agent What action I should do now Actuators AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 36
Performance standard Learning agents Critic Sensors feedback learning goals Learning element changes knowledge Performance element Environment Problem generator Agent Actuators AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 37
The agent projects Design and implement a simple but useful agent Justrightnowontheprogresswiththenewknowledgecharpterby-charpter selectively by a programming language which you are familiar with in a software environment or platform single agent or multi-agents (group) Options: Internet agent Intelligent robot intelligent motor intelligent drone AI Slides (4e) c Lin Zuoquan@PKU 2003-2017 2 38