Upload
others
View
13
Download
0
Embed Size (px)
Citation preview
Intelligent Agents
2
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 1
2 Intelligence Agents
2.1 Agents
2.2 Agent programs
2.3 Rationality
2.4 Environments
2.5 Agent structures
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 2
Agents
An agent is an entity that perceives and acts in an environment
Agents include– animal agents
– human agents
– robotic agents (robots)– software agents (softbots)– – internet agents– – – crawler– – – webbot– – – email agent– – – search agent, etc.– – chatbots– – – Cortana/Siri/GAssistant/Waston/Alexa/FMessenger/· · ·
Single agent or usually multi-agents (so-called distributed AI)
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 3
Agents and environments
?
agent
percepts
sensors
actions
environment
actuators
An agent is anything that can be viewed as perceiving its environmentthrough sensors and acting upon that environment through actuators
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 4
Sensors and actuators
A sensor measures some aspect of the environment in a formthat can be used as input by an agent
– vision, hearing, touch– radio, infrared, GPS, wireless signals– active sensing: send out a signal (such as radar or ultrasound)
and sense the reflection of this signal off of the environment⇒ IoT (Internet of Things)
Perception provides agents with information about the world theyinhabit by interpreting the response of sensors
Actuators– hands, legs, vocal tract etc.– automated taxi: those available to a human drivere.g., accelerator, steering, braking and so on
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 5
Agent functions
An agent is completely specified by the agent function : maps frompercept histories to actions
f : P∗→ A
For any given class of environments and tasks, we seek theagent (or class of agents) with the best performance
Find a way to implement the rational agent function concisely
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 6
Agent programs
The agent program runs on the physical architecture to produce theagent function
agent = architecture+ program
program = algorithm + data
The agent program takes a single percept as input, keeps internalstate
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 (5e) c© Lin Zuoquan@PKU 2003-2019 2 7
Another form of algorithm
A procedure for the skeleton-agent that takes a single percept asinput, 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 (5e) c© Lin Zuoquan@PKU 2003-2019 2 8
Algorithm
Recall: an algorithm is an explicit effective set of instructions for acomputing procedure
– may be used to find the answers to any of a given class of ques-tions– can be precisely defined by computational models, e.g., Turing ma-chine, etc.
Analysis of algorithms, independently of the particular implementationand input
– time complexity: speed in secondse.g., the worst Tworst(n) or the average Tavg(n)– space complexity: memory consumption in bytes
Complexity analyzes problems rather than algorithms
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 9
Algorithm
O-notation: asymptotic analysis
T (n) is O(f(n)) if T (n) ≤ kf(n) for some k, for all n > 0
O(nk) for some k: polynomial time/space, called P or “easiness”Otherwise, exponential time/space, e.g., O(2n), called NP , hardness
– class of nondeterministic (Turing machine) polynomial problemsguess a solution and then verify whether the guess is correct in
polynomial time– NP -complete problems (the hardest subclass of NP )– – co-NP (-complete) is the complement of NP (-complete)“yes” and“no” answers reversed
Theorem: either all the NP -complete problems are in P or none ofthem is
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 10
Algorithm
NP = P ??if you could try all the guesses at once, or you were very lucky
and always guess right the first time
#P : counting problems corresponding to decision problems in NP
decision problems have a yes-or-no answer, counting problemshave an integer answer: how many solutions
at least as hard as any NP problems
PSPACE: require a polynomial amount of space, even on a non-deterministic machine
it is believed that PSPACE-hard problems are worse than NP -complete problems although it could turn out thatNP = PSPACE,just as P = NP
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 11
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 and local variables): a variable isgiven an initial value the first time a function is called and re-tains that value on all subsequent calls to the function. The agentprograms use persistent variables for memory. Variables have low-ercase italic names.
• Function as values: The value of a variable is allowed to be afunction. Functions and procedures have capitalized names
• Indentation is significant: the scope of a loop or conditional
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 12
The pseudocode
• Assignment: ”x← value” means that the right-hand side eval-uate to the left-hand side variable
– Destructuring assignment: ”x, y ← pair” means that theright-hand side evaluate to a two-element tuple, and the firstelement is assigned to x and the second to y. Or ”for eachx, y in pair do”
• if-then (-else): ”if c then · · · else · · ·” means that if the con-dition c is hold then doing something; otherwise doing somethingelse
• for each: ”for each x in c do” means that the loop is executedwith the variable x bound to successive elements of the collectionc. Or ”while c do” or even ”loop · · · ”
• Generators and yield: ”generator G(x) yields number” de-fines G as a generator function
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 13
The pseudocode
• Lists: [x, y, z], [first|rest]
• Sets: {x, y, z}
• Arrays start at 1: as in usual mathematical notation, not 0 asin Java and C
• /* the explanations can be given as remarks */
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 14
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 environ-ments)
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 15
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 (5e) c© Lin Zuoquan@PKU 2003-2019 2 16
Rationality
A rational agent is one that does right thing– to achieve the best performance“goals” specifiable by performance measuredefining a numerical value for any environment history
Rational action: whichever action maximizes the expected value ofthe performance measure given the percept sequence to date
Limited rationality: computational limitations make perfect ra-tionality unachievable⇒ design best program for given machine resources
Rational 6= omniscient– percepts may not supply all relevant information
Rational 6= clairvoyant– action outcomes may not be as expected
⇒ rational 6= successful
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 17
Vacuum-cleaner world
Example: Robot cleaner, say, iRobot Roombat
A B
Percepts: location and contents, e.g., [A,Dirty]
Actions: Left, Right, Suck, NoOp
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 18
A vacuum-cleaner agent
Percept sequence Action[A,Clean] Right
[A,Dirty] Suck
[B,Clean] Left
[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 (5e) c© Lin Zuoquan@PKU 2003-2019 2 19
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 (5e) c© Lin Zuoquan@PKU 2003-2019 2 20
PEAS (Performance/Environment/Actuators/Sensors)
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 (5e) c© Lin Zuoquan@PKU 2003-2019 2 21
Example: automated taxi agent
To design a rational agent, we must specify the task environment
E.g., intelligent vehicle (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 (5e) c© Lin Zuoquan@PKU 2003-2019 2 22
Example: Internet shopping agent
Performance measure??
Environment??
Actuators??
Sensors??
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 23
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 (5e) c© Lin Zuoquan@PKU 2003-2019 2 24
Environments
Solitaire Backgammon Internet shopping TaxiObservable??Deterministic??Episodic??Static??Discrete??Single-agent??
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 25
Environments
Solitaire Backgammon Internet shopping TaxiObservable?? Yes Yes No NoDeterministic??Episodic??Static??Discrete??Single-agent??
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 26
Environments
Solitaire Backgammon Internet shopping TaxiObservable?? Yes Yes No NoDeterministic?? Yes No Partly NoEpisodic??Static??Discrete??Single-agent??
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 27
Environments
Solitaire Backgammon Internet shopping TaxiObservable?? Yes Yes No NoDeterministic?? Yes No Partly NoEpisodic?? No No No NoStatic??Discrete??Single-agent??
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 28
Environments
Solitaire Backgammon Internet shopping TaxiObservable?? Yes Yes No NoDeterministic?? Yes No Partly NoEpisodic?? No No No NoStatic?? Yes Semi Semi NoDiscrete??Single-agent??
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 29
Environments
Solitaire Backgammon Internet shopping TaxiObservable?? Yes Yes No NoDeterministic?? Yes No Partly NoEpisodic?? No No No NoStatic?? Yes Semi Semi NoDiscrete?? Yes Yes Yes NoSingle-agent??
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 30
Environments
Solitaire Backgammon Internet shopping TaxiObservable?? Yes Yes No NoDeterministic?? Yes No Partly NoEpisodic?? No No No NoStatic?? Yes Semi Semi NoDiscrete?? Yes Yes Yes NoSingle-agent?? Yes No Yes (except auctions) No
The environment type largely determines the agent design
The real world is (of course) partially observable, stochastic, sequen-tial, dynamic, continuous, multi-agent
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 31
Agent structures
Agents interact with environments through sensors and actuators
Agent Sensors
Actuators
En
viro
nm
ent
Percepts
Actions
?
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 32
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 (5e) c© Lin Zuoquan@PKU 2003-2019 2 33
Simple reflex agents
Agent
En
viro
nm
ent
Sensors
What action Ishould do nowCondition-action rules
Actuators
What the worldis like now
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 34
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 (5e) c© Lin Zuoquan@PKU 2003-2019 2 35
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 (5e) c© Lin Zuoquan@PKU 2003-2019 2 36
Model-based reflex agents
Agent
En
viro
nm
ent
Sensors
State
How the world evolves
What my actions do
Condition-action rules
Actuators
What the worldis like now
What action Ishould do now
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 37
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 (5e) c© Lin Zuoquan@PKU 2003-2019 2 38
Goal-based agents
Agent
En
viro
nm
ent
Sensors
What action Ishould do now
State
How the world evolves
What my actions do
Actuators
What the worldis like now
What it will be like if I do action A
Goals
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 39
Utility-based agents
Agent
Enviro
nm
ent
Sensors
How happy I will bein such a state
State
How the world evolves
What my actions do
Utility
Actuators
What action Ishould do now
What it will be likeif I do action A
What the worldis like now
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 40
Learning agents
Performance standard
Agent
En
viro
nm
ent
Sensors
Performanceelement
changes
knowledge
learning goals
Problemgenerator
feedback
Learning element
Critic
Actuators
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 41
The agent projects
Design and implement a simple but useful agent– Just right now on the progress with the new knowledge charpter-
by-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 (say, smart shopping, chatbot)
• Intelligent robot
• Intelligent motor
• Intelligent drone
• Coding algorithms and finding applications
AI Slides (5e) c© Lin Zuoquan@PKU 2003-2019 2 42