You are on page 1of 51

COMP 401: Artificial Intelligence

Lecture 1
Introduction
13-10-2022
Course Information
 Course Code: Comp 401
 Course Title: Artificial Intelligence
 Number of Credit Hours: 3 (3 hours lecture + 0 lab.)
 Prerequisite : -
 Final Exam (duration): 3 hours
 Total Marks: 150
◼ 105 Final Exam.
◼ 37 Quarterly Exam. (Midterm 27 Mark + Small Project 10 Marks)
◼ 8 Oral Exam.
Textbook
 Stuart Russell and Peter Norvig (2020). Artificial
Intelligence: A Modern Approach (4th Edition),
Prentice Hall.
Course Objectives
 Give a solid understanding of the definitions,
abstractions, reasoning techniques, and topics
related to the field of artificial intelligence (AI).
 The focus is on:
 Search strategies for solving problems in AI.
 Knowledge representation and reasoning using first-
order logic.
Course Outline
 Introduction.
 Intelligent agent.
 Problem-solving by searching.
 Knowledge representation; types of reasoning;
logic languages; inferences in first-order logic.
 Dealing with uncertainty.
Agenda of Lecture 1
 What is AI?
 Intelligent Agents.
 Problem Solving by Searching
 Problem formalization
 State-space graph vs search tree

 Uninformed search strategies


◼ Depth-firstsearch
◼ Breadth-first search
What is AI?
The science of making machine that:

Thought 2
Think Humanly Think Rationally 1

3 Act Humanly Act Rationally 4


Behavior
Human Performance Rationality

A system is rational if it does the right thing, given


what it knows.
Thinking rationally: "laws of thought"

 The Greek philosopher Aristotle provides patterns for


argument structures that always yielded correct conclusions
when given correct premises—for example, “Socrates is a
man; all men are mortal; therefore, Socrates is mortal.”
 These laws of thought were LOGIC supposed to govern the
operation of the mind; their study initiated the field called
logic.
 Direct line through mathematics and philosophy to modern
AI.
Problems of the "laws of thought"

1. The uncertainty of the knowledge may be


less than 100% .
2. There is a big difference between solving a
problem “in principle” and solving it in
practice.
Thinking humanly

 Bellman 1978, the automation of activities that we


associate with human thinking, activities such as:
 Decision-making
 Problem solving
 learning
Acting humanly: Turing Test
 Turing (1950) in his article "Computing machinery and intelligence":
 "Can machines think?" → "Can machines behave intelligently?"
 Operational test for intelligent behavior: the Imitation Game

 A Computer passes the test if a human interrogator, after posing some


written questions, cannot tell whether the written response come from a
person or a computer.
Acting humanly: Turing Test (Cont.)

 Suggested major components of AI:


 Knowledge Representation to store what it knows or hear.
 Automated Reasoning to use the stored information to answer questions
and to draw new conclusions.
 Language Understanding to enable to communicate successfully in
English.
 Machine Learning to adopt new circumstances and to detect and
extrapolate patterns.
Acting rationally: rational agent
 AI is viewed as the study and construction of rational
agents.
 Agent: entities that can be viewed as perceiving and acting upon
their environment.
◼ Agents use sensors to perceive, and effectors to act.
 Rational behavior: doing the right thing.

 The right thing: that which is expected to maximize goal


achievement, given the available information
 A rational agent is one that acts to achieve the best outcome
or, when there is uncertainty, the best expected outcome.
 Doesn't necessarily involve thinking – e.g., blinking reflex
– but thinking should be in the service of rational action.
 The course advocates "acting rationally".
 The rational-agent approach has advantages over
the other approaches:
 More general than the “laws of thought” approach because
correct inference is just one of several possible mechanisms
for achieving rationality.
 It is more amenable to scientific development than are
approaches based on human behavior or human thought.
Programs and Agents
 Programs: executes some instructions to do something.
 Computer Agents: operate autonomously, perceive
their environment, persist over a prolonged time
period, adapt to change, and create and pursue goals.
What Can AI do?
Question: Which of the following can be done by AI?
✓  Playing a decent game of chess?

X  Driving in the center of Cairo?

?  Discovering and proving new mathematical theorems?

?  Performing a complex surgical operation?

✓  Translating spoken English into spoken Arabic in real

time?
Intelligent Agents
 An agent is an entity that can be viewed as perceiving its
environment through sensors and acting upon that
environment through actuators.
 Examples
1. Human agent:
 Sensors: eyes, ears, and other organs
 Actuators: hands, legs, mouth, and other body parts

2. Robotic agent:
 Sensors: cameras and infrared range finders
 Actuators: various motors for actuators
Intelligent Agents (Cont.)
 Examples
3. Software agent:
 receives keystrokes, file contents, and network
packets as sensory inputs,
 acts on the environment by displaying on the
screen, writing files, and sending network packets.
Agents and environments

 An agent’s behavior can be described by the agent


function
 The agent function maps from percept histories to
actions:
[f: P* → A]
Example :Vacuum-cleaner World

 Percepts: location and contents, e.g., [A, Dirty]


 Actions: Left, Right, Suck, NoOp
Example (Cont.)
 One very simple agent function is:
 if the current square is dirty, then suck; otherwise,
move to the other square. A partial tabulation of this
agent function is:

Percept sequence Action


[A, Clean] Right
[A, Dirty] Suck
[B , Clean] Left
[B, Dirty] Suck
Problem Solving by searching
Problem Formalization
 Problems are generally specified in terms of states
and actions necessary to reach the goal.
 It is desired to find the goal state (or states).
 Solving a problem is the process of searching
through the different states of the problem, called
state-space, until one of the goal state is reached.
Example of a state:
 A state in the 8-puzzle problem
Initial state
 The start stat of a given problem.
Actions
 In order to reach goals, an action is needed:
 Choices that can be made in each state.
 For example, in the 8-puzzle problem, the action is
moving the blank tile up, down, left, or right.
 Actions is usually defined as a function:
 Action (s) is a function returns the set of actions that
can be executed in state s.
Transition Model
 A description of what state results from performing
any applicable action in any state.
 Transition model is defined by the function:

Result(s, a) which returns the state resulting from


performing available action a in state s.
 Example:

Result ( 1 2 3 , left ) = 1 2 3
8 5 8 5
4 7 6 4 7 6
State Space
 Transition model indicates how states and actions
are related to each other.
 The initial state, actions, and transition model
define the state space of the problem—the set of
all states reachable from the initial state by any
sequence GRAPH of actions.
 The state space forms is a graph G = (V, E):
V is a set of states (vertices)
 E is a set of edges connecting the vertices through
actions.
Goal Test and Path Cost
 Goal Test: A method to detect whether a given state
is a goal state or not.
 Path Cost: numerical cost associated with a given
path.
 It is desired to minimize the path cost as mush as
possible.
Search Problem
A search problem consists of
1. Initial state
2. State space
3. Goal test
4. Actions
5. Transition model
6. Action cost
 A solution is a sequence of actions that leads from
the initial state to a goal state.
Example 1: Romania
 On holiday in Romania; currently in Arad.
 Flight leaves tomorrow from Airport in Bucharest
 Formulate goal:
 be in Bucharest
 Formulate problem:
 states: various cities
 actions: drive between cities
 Start state: Arad
 Goal test: Is state = = Bucharest
 Find solution:
 sequence of cities from Arad to Bucharest, e.g., Arad, Sibiu,
Fagaras, Bucharest
Example 1: Romania
Example 2: The 8-puzzle

 states?
 actions?
 goal test?
Example 2: The 8-puzzle

 states? locations of tiles (any location of tiles can be start state)

 actions? move blank left, move blank right, move blank up, move
blank down

 goal test? = goal state (given)


Example 3: 8-queen problem
Place eight queens on a chessboard such that no
queen attacks any other. (A queen attacks any piece in
the same row, column or diagonal.)
 states? Any arrangement of 0 to 8 queens on the board.

 Initial state? : No queens on the board.

 actions? Add a queen to any empty square.

 goal test? 8 queens are on the board, none

attacked.
State Space Graphs
 State space graph: A mathematical
representation of a search problem
 Nodes are (abstracted) world configurations a G
(states of the problem)
b c
 Arcs represent successors (action results)
 The goal test is a set of goal nodes (may be e
d f
only one)
S h
p r
 In a search graph, each state occurs q
only once!
Tiny search graph for a tiny
 We can rarely build this full graph in search problem
memory (it’s too big), but it’s a
useful idea.
Search Trees

 A search tree:
 The start state is the root node
 Children correspond to successors
 Nodes show states, but correspond to Actions that achieve those states
 For most problems, we can never actually build the whole tree
State Space Graphs vs. Search Trees

Each NODE in
State Space Graph in the search Search Tree
tree is an entire S
PATH in the
a G d e p
b c
state space
graph. b c e h r q
e
d f a a h r p q f
S h We construct
p q f q c G
p q r both on demand
q c a
– and we G
construct as little a
as possible.
State Space Graphs vs. Search Trees

Consider this 4-state graph: How big is its search tree (from S)?

S G

Important: Lots of repeated structure in the search tree!


Search Example: Romania
Searching with a Search Tree

 Search:
 Expand out potential plans (tree nodes)
 Maintain a fringe of partial plans under consideration
 Try to expand as few tree nodes as possible
General Tree Search
function Tree_Search (problem, strategy) returns a solution, or failure
initialize the search tree using the initial state of problem
loop do
if there are no candidates for expansion then return failure
choose a leaf node for expansion according to strategy
if the node contains a goal state then return the corresponding solution
else expand the node and add the resulting nodes to the search tree
end
 Important ideas:
 Fringe : set of leaf nodes that are waiting to be expanded
 Expansion: pick one node out of the fringe and check if it is a goal or
not, if it not a goal expand it.
 Exploration strategy: which node in the fringe you choose for expansion
 Main question: which fringe nodes to explore?
Example: Tree Search
a G
b c

S : Initial state d
e
f
G: Goal state S h
p r
q
Depth-First Search
Depth-First Search

Strategy: expand a a G
b c
deepest node first
e
d f
Implementation: Fringe S h
is a LIFO stack p q r

d e p

b c e h r q

a a h r p q f

p q f q c G

q c G a

a
Search Algorithm Properties
Search Algorithm Properties

 Complete: Guaranteed to find a solution if one exists?


 Optimal: Guaranteed to find the (optimal ) least cost path?
 Time complexity?
 Space complexity? 1 node
b
… b nodes
 Picture of search tree: b2 nodes
 b is the branching factor m tiers
 m is the maximum depth
 solutions at various depths
 Number of nodes in entire tree? bm nodes
 1 + b + b2 + …. bm = O(bm)
Depth-First Search (DFS) Properties

 What nodes DFS expand?


 Some left prefix of the tree. 1 node
b
 Could process the whole tree! … b nodes

 If m is finite, takes time O(bm) b2 nodes


m tiers
 How much space does the fringe take?
 Only has siblings on path to root, so
O(bm) bm nodes

 Is it complete?
 m could be infinite; it is complete only
if we prevent cycles.

 Is it optimal?
 No, it finds the “leftmost” solution,
regardless of depth or cost
Breadth-First Search
Breadth-First Search

Strategy: expand a a G
b c
shallowest node first
e
d f
Implementation: Fringe is S h
a FIFO queue
p q r

d e p
Search
b c e h r q
Tiers
a a h r p q f

p q f q c G

q c G a

a
Breadth-First Search (BFS) Properties
 What nodes does BFS expand?
 Processes all nodes above shallowest
solution
1 node
 Let depth of shallowest solution be s b
… b nodes
 Search takes time O(bs) s tiers
b2 nodes

bs nodes
 How much space does the fringe take?
 Has roughly the last tier, so O(bs)
bm nodes

 Is it complete?
 s must be finite if a solution exists,
so yes!

 Is it optimal?
 Only if costs are all 1 (more on costs
later)

You might also like