AI Lec-Module-I
AI Lec-Module-I
Module II
• Uncertainty in AI, Uncertainty, Probability, Syntax and Semantics, Inference,
Independence and Bayes' Rule, Bayesian Network, Neural Networks, Support
Vector Machine.
Module III
• Classification & Regression, Supervised, Unsupervised and Reinforcement
Learning, Theory, concepts and applications.
Module IV
• Applications of AI.
Grading
Evaluation/Part Weightage
Quiz 20%
End-Sem 60%
Class Performance$ 20%
• Provide your feedback for any improvement without any fear as and when
it strikes to you.
• Maintain a notebook for this subject and note down key points. Attempt the
short/daily assignment problems in this notebook.
• In case you are not able to attend the class due to a valid reason, please drop
an email to me in advance. Please note that 75% attendance is mandatory in
this subject, the informed absence/leave will not be considered as present.
Why this course ???
News clips
In the future, AI will be diffused into every aspect
of the economy.
—Nils J. Nilsson, founding researcher, Artificial
Intelligence & Computer Science, Stanford University
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Why this course ???
News clips
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Why this course ???
News clips
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Why this course ???
Movies on AI
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Why this course ???
Movies on AI
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Why this course ???
AI in action today
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Module-I
Introduction
What is AI?
AI is an abbreviation of one of the most popular technologies
of recent time that means Artificial Intelligence.
State
• A State is a representation of problem elements/AI
system at a given moment/current situation or
environment.
• This can be thought of as the "snapshot" of the
current situation of the system under consideration.
Terminology
Actions
• Action is an activity, step, process, or function that
an agent performs given a specific state of the
environment. Actions is a description of the possible
actions that the agent can take.
Path Cost
• Path cost assigns a numerical cost to each path that
leads to the goal. The problem-solving agents choose
a cost function that matches its performance
measure.
Terminology
Transition model
• Transition model describes what each action does.
It is specified by a function Result(s, a) that returns
the state that results from doing action a in state s.
State Space
• The initial state, actions, and transition model
together define the state space of a problem, a set of
all states reachable from the initial state by any
sequence of actions.
Terminology
Goal Test
• The goal test determines whether a given state is a
goal state.
Solution
• A Solution to a problem is an action sequence that
leads from the initial state to a goal state.
Optimal solution
• An optimal solution is a solution that has the lowest
path cost of all the solutions.
Agents and environments
Agent
• An Agent is anything that can be viewed as
perceiving its environment through sensors and
acting upon that environment through actuators.
Agents and environments
Agent Environment
Sensors
Percepts
?
Actuators
Actions
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Agents and environments
Agent Environment
Sensors
Percepts
?
Actuators
Actions
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Agents and environments
Agent Environment
Sensors
Percepts
?
Actuators
Actions
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Agents and environments
Agent Environment
Sensors
Percepts
?
Actuators
Actions
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Agent functions
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Agent programs
• The agent program l runs on some machine M to
implement f :
– f = Agent(l,M)
– Real machines have limited speed and memory, introducing
delay, so agent function f depends on M as well as l
NEXT NEXT NEXT NEXT
Percept
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Agent functions and agent programs
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Example: Vacuum world
A B
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Vacuum cleaner agent A B
Courtesy: Lecture notes from Prof. Stuart Russell and Dawn Song
Rationality
• A rational agent does the right thing (what is this?)
• Rationality is not the same as perfection.
• Rationality maximizes expected performance, while
perfection maximizes actual performance.
• A fixed performance measure evaluates the
sequence of observed action effects on the
environment.
Rationality A B
Image: http://nypost.com/2014/06/21/how-google-
might-put-taxi-drivers-out-of-business/
PEAS: Medical diagnosis system
• Performance measure
– Patient health, cost, reputation
• Environment
– Patients, medical staff, insurers,
courts
• Actuators
– Screen display, email
• Sensors
– Keyboard/mouse
The task environment - PEAS
• Performance measure
– -1 per step; + 10 food; +500 win; -500 die;
+200 hit scared ghost
• Environment
– Pacman dynamics (incl ghost behavior)
• Actuators
– Left Right Up Down
• Sensors
– Entire state is visible (except power pellet
duration)
Environment Properties
• Fully observable vs. partially observable
• Deterministic vs. stochastic / strategic
• Episodic vs. sequential
• Static vs. dynamic
• Discrete vs. continuous
• Single agent vs. multiagent
Environment Properties
Fully observable vs. partially observable
• The task environment is said to be fully observable if
an agent’s sensors give it access to the complete
state of the environment at each point in time.
Poker
Environment Examples
Environment Obser Determi Episodic Static Discrete Agents
vable nistic
Chess with a clock Fully Strategic Sequential Semi Discrete Multi
Backgammon
Environment Examples
Environment Obser Determi Episodic Static Discrete Agents
vable nistic
Chess with a clock Fully Strategic Sequential Semi Discrete Multi
Environment
Current internal states
is-braking then initiate-
braking) and some of
which are innate reflex
(blinking eye on sudden …). Condition-action rules What action I
should do now
Background information
Actuators
used in the process
Simple reflex agents
The advantage of Simple reflex agents: Simple. But they turn out to
be of very limited intelligence.
A little bit of unobservability can cause serious trouble.
Environment
Current internal states
Clean. It will Suck in
response to Dirty, but it
will fail to move left or
What action I
right, in response to Clean. Condition-action rules should do now
Background information
Actuators
used in the process
Reflex agents with state
These are known as model-based reflex agents. It maintains
internal state that depend on the percept history, and thereby
reflects at least some of the unobserved aspects of the current state.
Updating this internal state information requires two kinds of
knowledge to be encoded in the agent program.
Environment
agent’s own action What my actions do Current
affect the world. internal states
Background information
This is implemented using used in the process
What action I
model of the world. Condition-action rules
should do now
Agent Actuators
Goal-based agents
The state of the environment is not always enough to decide what
to do. The agent needs some sort of goal information that describes
situations that are desirable.
The agent program can combine this with information about the
results of possible actions in order to choose actions that achieve
the goal.
Sensors
Environment
What it will be like
What my actions do
rule, as it considers the if I do action A
Agent Actuators
Goal-based agents
The state of the environment is not always enough to decide what
to do. The agent needs some sort of goal information that describes
situations that are desirable.
The agent program can combine this with information about the
results of possible actions in order to choose actions that achieve
the goal.
Sensors
Environment
What it will be like
What my actions do if I do action A
“Have milk” → “buy milk”
Con: Cannot handle tradeoffs
among goals, appears less Goals
What action I
should do now
efficient, failure probability
etc. Agent Actuators
Utility-based agents
Goals alone are not really enough to generate high-quality behavior
in most environments. A utility function maps a state onto a real
number, which describes the associated degree of happiness. It
allows handling conflicting goals (e.g. speed/time vs safety in
drive). Utility is a numeric scale.
A complete specification
Sensors
of the utility function
State
allows rational decisions What the world
How the world evolves is like now
with multiple and/or
Environment
conflicting goals. What my actions do
What it will be like
if I do action A
Root Node
Links
Parent of X
Node-X
Child of X
Terminal Node
Search
Search: Terminology
• A graph is also a set of nodes connected by links but where
loops are allowed and a node can have multiple parents. We
have two kinds of graphs to deal with:
• Directed graphs, where the links have direction (akin to
one-way streets).
• Undirected graphs, where the links go both ways. You can
think of an undirected graph as shorthand for a graph with
directed links going each way between connected nodes.
Search
Search: Terminology
• A graph is also a set of nodes connected by links but where
loops are allowed and a node can have multiple parents. We
have two kinds of graphs to deal with:
Search
Search: Graph search vs Tree search
• Trees are a subclass of directed graphs, which don't have
cycles and every node has a single parent.
• Cycles are bad for searching, since, obviously, you don't
want to go round and round getting nowhere.
• A graph can be converted to an equivalent problem of
searching a tree by doing two things: turning undirected
links into two directed links; and, more importantly, making
sure we never consider a path with a loop or, even better, by
never visiting the same node twice.
Search
Search: Graph search vs Tree search
• Example: We have a tree with S as the start point, and our
goal is to find a path to reach G.
Search
Search: As a problem-solving agent
One general approach to problem solving in AI is to reduce
the problem to be solved to one of searching a graph. To use
this approach, we must specify what are the states, the
actions and the goal test.
Assumptions
The actions are deterministic, that is, we know exactly the
state after the action is performed.
The actions are discrete, so we don't have to represent what
happens while the action is happening.
Search
What a search problem should have?
• A search problem consists of:
– A state space S
E -9
Nodes contain information that makes them very useful for the
purposes of search algorithms. They contain a state, which can be
checked using the goal test to see if it is the final state.
Search
General Tree Search
However, nodes are simply a data structure — they don’t search,
they hold information. To actually search, we use the frontier, the
mechanism that “manages” the nodes.
The frontier starts by containing an initial state and an empty set of
explored items, and then repeats the following actions until a
solution is reached:
Search
General Tree Search
• Main variations:
– Which leaf node to expand next
– Whether to check for repeated states
– Data structures for frontier, expanded nodes
Search
Measuring performance of Search Algorithms
• The typical measure for time and space complexity is the size
of the state space graph, |V | + |E|, where V is the set of
vertices (nodes) of the graph and E is the set of edges (links).
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 Frontier:
Frontier: A,
D
B,
S C, E
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
Depth-first Search
# Define the function that removes a node from the frontier and returns it.
def remove(self):
# Terminate the search if the frontier is empty, because this means that there is no solution.
if self.empty():
raise Exception("empty frontier")
else:
# Save the last item in the list (which is the newest node added)
node = self.frontier[-1]
# Save all the items on the list besides the last node (i.e. removing the last node)
self.frontier = self.frontier[:-1]
return node
Search
Depth-first Search
• Complete: Guaranteed to find a solution if one exists?
• Optimal: Guaranteed to find the least cost path?
• Time complexity?
1 node
b
• Space complexity? … 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
• Is it optimal?
– No, it finds the “leftmost” solution,
regardless of depth or cost
Search
Breadth-first Search
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
Search
Breadth-first Search: Pseudo Code
Search
Breadth-first Search: Properties
• Is it complete?
– s must be finite if a solution exists, so yes!
• Is it optimal?
– If costs are equal (e.g., 1)
Search
Breadth-first Search: Properties
Search
Uniform Cost Search
Search
Uniform Cost Search
2 a G
g(n) = cost from root to n c
b
1 8 2
Strategy: expand lowest g(n) 2 e
3 d f
9 2
S h 8 1
Frontier is a priority queue
1 p q r
sorted by g(n) 15
S 0
d 3 e 9 p 1
b 4 c e 5 h 17 r 11 q 16
11
Cost a 6 a h 13 r 7 p q f
contours
p q f 8 q c G
q 11 c G 10 a
a
Search
Uniform Cost Search: Properties
• What nodes does UCS expand?
– Processes all nodes with cost less than cheapest solution!
– If that solution costs C* and arcs cost at least , then the
“effective depth” is roughly C*/
– Takes time O(bC*/) (exponential in effective depth)
• Is it optimal?
– Yes! (Proof next lecture via A*)
Search
Uninformed vs Informed Search
Guide search towards the goal instead of all over the place
Informed Uninformed
Search
Informed Search
• Greedy Best-first search expands the node that is the closest to the
goal, as determined by a heuristic function h(n).
• It evaluates nodes by using just the heuristic function: f(n) = h(n).
Zerind 87
151
75
Iasi
Arad
140
92
Sibiu Fagaras
99
118
Vaslui
80
Rimnicu Vilcea
Timisoara
142 h(n) = straight-line distance to Bucharest
111 Pitesti 211
Lugoj 97
70 98
85 Hirsova
Mehadia 146 101 Urziceni
75 138 86
Bucharest
Drobeta 120
90
Craiova Eforie
Giurgiu
Search
Greedy Best-First Search
Search
Greedy Best-First Search
Search
Greedy Best-First Search
Search
Greedy Best-First Search
Search
Greedy Best-First Search: Properties
Zerind 87
151
75
Iasi
Arad
140
92
Sibiu Fagaras
99
118
Vaslui
80
Rimnicu Vilcea
Timisoara
142 h(n) = straight-line distance to Bucharest
111 Pitesti 211
Lugoj 97
70 98
85 Hirsova
Mehadia 146 101 Urziceni
75 138 86
Bucharest
Drobeta 120
90
Craiova Eforie
Giurgiu
Search
Search
Search
Search
Search
Search
Search
Search
A* Search: Optimality ???
Search
A* Search: Optimality ???
Assume:
• A is an optimal goal node …
• B is a suboptimal goal node
• h is admissible
A
Claim: B
• A will be chosen for expansion before B
Search
A* Search: Optimality ???
Proof:
…
• Imagine B is on the frontier
• Some ancestor n of A is on the frontier, n
too (maybe A itself!)
• Claim: n will be expanded before B A
B
1. f(n) is less than or equal to f(A)
Proof:
…
• Imagine B is on the frontier
• Some ancestor n of A is on the frontier, n
too (maybe A itself!)
• Claim: n will be expanded before B A
B
1. f(n) is less than or equal to f(A)
2. f(A) is less than f(B)
Proof:
…
• Imagine B is on the frontier
• Some ancestor n of A is on the frontier,
n
too (maybe A itself!)
• Claim: n will be expanded before B A
1. f(n) is less than or equal to f(A) B
2. f(A) is less than f(B)
3. n is expanded before B
• All ancestors of A are expanded before B
• A is expanded before B f(n) f(A) < f(B)
• A* tree search is optimal
Search
A* Search: Properties
Search
Creating Admissible Heuristics
Let us consider an example of 8-puzzle to learn how to create
admissible heuristics.
• Why is it admissible?
• h(start) = 3 + 1 + 2 + … = 18
Search
Local search algorithms
The uninformed and informed search algorithms that we have seen
are designed to explore search spaces systematically.
• They keep one or more paths in memory and by record which
alternatives have been explored at each point
along the path.
• When a goal is found, the path to that goal also constitutes a solution to
the problem.
• In many problems, however, the path to the goal is irrelevant.
If the path to the goal does not matter, we might consider a different
class of algorithms that do not worry about paths at all.
Search
Local search algorithms
• Local search algorithms operate using a single current node and generally
move only to neighbors of that node.
• Local search algorithms ease up on completeness and optimality in the interest
of improving time and space complexity?
• Although local search algorithms are not systematic, they have two key
advantages:
▪ They use very little memory (usually a constant amount), and
▪ They can often find reasonable solutions in large or infinite (continuous) state spaces.
• In addition to finding goals, local search algorithms are useful for solving pure
optimization problems, in which the aim is to find the best state according to
an objective function.
▪ In optimization problems, the path to goal is irrelevant and the goal state itself is the
solution.
▪ In some optimization problems, the goal is not known and the aim is to find the best
state.
Search
Local search algorithms: Hill Climbing
Random restarts
– find global optimum
– duh
Random sideways
moves
– Escape from
shoulders
– Loop forever on flat
local maxima
Search
Local search algorithms: Global and local maxima
• A local maximum is a peak that is higher than each of its neighboring states but
lower than the global maximum.
o Hill-climbing algorithms that reach the vicinity of a local maximum will be
drawn upward toward the peak but will then be stuck with nowhere else to go.
• A plateau is a flat area of the state-space landscape. It can be a flat local maximum,
from which no uphill exit exists, or a shoulder, from which progress is possible.
• No sideways moves:
– Succeeds w/ prob. 0.14
– Average number of moves per trial:
• 4 when succeeding, 3 when getting stuck
– Expected total number of moves needed:
• 3(1-p)/p + 4 =~ 22 moves
• Allowing 100 sideways moves:
– Succeeds w/ prob. 0.94
– Average number of moves per trial:
• 21 when succeeding, 65 when getting stuck
– Expected total number of moves needed: Moral: algorithms with knobs
• 65(1-p)/p + 21 =~ 25 moves to twiddle are irritating