AI
AI
• Genetic Algorithms
• Probabilistic models
• Handling Uncertainty
• Selected Topics
References
• Data Structures
• Computer Algorithms
• Logic
• Probability
What is AI
AI:
The branch of computer science concerned with the automation of the
intelligent (human/animal/living) behavior.
human
interrogator
computer
Agents
Agents
• Artificial intelligence is defined as the study of rational agents.
Model-based agent
Goal-based agent
Utility-based agent
Learning agent
Types of agents
Simple reflex agent
• Simple Reflex Agents:
• Operates based on a set of condition-action rules, Model-based agent
also known as "if-then" rules or production rules.
• Start State
• Goal State
• Action
• Solution
The branching factor
• Tic-Tac-Toe: 4
• Chess: 35
• Go: 200
• Arimaa: 17,000
Searching
Searching
• A search problem consists of:
• A state space
“N”
• A successor function
(with actions, costs)
“E”
• A start state and a goal test
• How many
• World states?
120x(230)x(122)x4
• States for pathing?
120
• States for eat-all-dots?
120x(230)
State Space Graphs
• State space graph: A mathematical
representation of a search problem
• Nodes are (abstracted) world configurations
• Arcs represent successors (action results)
• The goal test is a set of goal nodes (maybe only one)
Implementation: e
d f
Fringe is a LIFO stack S h
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
• Infinite branch!
Search Algorithm Properties
• Complete: Guaranteed to find a solution if one exists?
• Optimal: Guaranteed to find the least cost path?
• Time complexity?
1 node
• Space complexity? b
… b nodes
b2 nodes
• Cartoon of search tree:
m tiers
• b is the branching factor
• m is the maximum depth
• solutions at various depths
bm nodes
• Number of nodes in entire tree?
• 1 + b + b2 + …. bm = O(bm)
Depth-First Search (DFS) Properties
• What nodes DFS expand?
• Some left prefix of the tree. 1 node
• Could process the whole tree! b
… b nodes
• If m is finite, takes time O(bm)
b2 nodes
• How much space does the fringe take? m tiers
• Only has siblings on path to root, so O(bm)
• Is it complete?
• m could be infinite, so only if we prevent bm nodes
cycles (more later)
• 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
shallowest node first b c
Implementation: Fringe e
d f
is a FIFO queue S h
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
b
• Let depth of shallowest solution be s … b nodes
• Search takes time O(bs) s tiers
b2 nodes
• Is it complete? bm nodes
• s must be finite if a solution exists, so yes!
• Is it optimal?
• Only if costs are all 1 (more on costs later)
Quiz: DFS vs BFS
• In the previous example what are the visited nodes of the tree using
BFS?
• Using DFS?
• What is the solution path from root to goal ?
Another example
DFS vs BFS
• When will BFS outperform DFS?
• Heuristic search:
• Eg: Best First Search
• Eg: A* search
• The agent has some hint (heuristic) how far it is from goal
• Heuristic search is intelligent search
Heuristic Search
The agent has some hint (heuristic) how far it is from goal
Heuristic Search
A heuristic function:
A function that estimates how close a state is to a goal
Designed for a particular search problem
Examples: Manhattan distance, Euclidean distance for pathing
10
5
11.2
Heuristic Search
Note
If H:consistent=>h(admissible)
Consistent
• Consistent or monotonic
• h is consistent if: n
1. h(goal)=0
2. h(s) ≤ c(s,n)+h(n)
For all s belong to S S
Where n is any direct neighbors state s
g
Note
If H:consistent ➔ h:admissible
But the opposite is not true
A* search
• h(s) is the heuristic value for state s
• g(s) is the distance from the start to the state
• f(s)=h(s)+g(s)
• h(s): admissible for all s
Quiz
Solve using: