Study Material
Study Material
Agents=Architecture + Program
AI Agents Performing Actions
Role of an Agent Program
State Space Search
• A state space is the set of all configurations
that a given problem and its environment
could achieve. Each configuration is called a
state, and contains. Static information. This is
often extracted and held separately, e.g., in
the knowledge base of the agent.
Representation
• In state space search, a state space is formally
represented as a tuple
S: {S, A, Action(s), Result(s,a), Cost(s,a)}
Example 1: (X’S AND 0’S)
State space representation of a
problem
• All the states the system can be in are represented as nodes of a graph.
• An action that can change the system from one state to another (e.g. a
move in a game) is represented by a link from one node to another.
• Links may be unidirectional (e.g. Xs and Os, chess, can't go back)
or bi-directional (e.g. geographic move).
• Search for a solution.
• A solution might be:
– Any path from start state to goal state.
– The best (e.g. lowest cost) path from start state to goal state (e.g. Travelling
salesman problem).
• It may be possible to reach the same state through many different paths
(obviously true in Xs and Os).
• There may be loops in the graph (can go round in circle). No loops in Xs
and Os.
Example 2 (TSP)
• Travelling salesman problem.
Start at A, visit all cities, return to A. Links
show cost of each trip (distance, money). Find
trip with minimum cost.
Solution is a path. e.g. [A,D,C,B,E,A]
Example 3 (8-PUZZLE)
• The puzzle can be solved by moving the tiles
one by one in the single empty space and thus
achieving the Goal state. Instead of moving
the tiles in the empty space we can visualize
moving the empty space in place of the tile.
The empty space cannot move diagonally and
can take only one step at a time.
Types of Environments in AI
• Fully Observable vs Partially Observable
• Deterministic vs Stochastic
• Competitive vs Collaborative
• Single-agent vs Multi-agent
• Static vs Dynamic
• Discrete vs Continuous
Agents in Artificial Intelligence
Agents can be grouped into classes based on
their degree of perceived intelligence and
capability :
• Simple Reflex Agents
• Model-Based Reflex Agents
• Goal-Based Agents
• Utility-Based Agents
• Learning Agent
Simple reflex agents
• Simple reflex agents ignore the rest of the percept history and act
only on the basis of the current percept. Percept history is the
history of all that an agent has perceived to date. The agent function
is based on the condition-action rule. A condition-action rule is a
rule that maps a state i.e, condition to an action. If the condition is
true, then the action is taken, else not. This agent function only
succeeds when the environment is fully observable.
Model-based reflex agents
• It works by finding a rule whose condition matches the current situation. A
model-based agent can handle partially observable environments by the use of a
model about the world. The agent has to keep track of the internal state which is
adjusted by each percept and that depends on the percept history. The current state
is stored inside the agent which maintains some kind of structure describing the part
of the world which cannot be seen.
• Updating the state requires information about :
• how the world evolves independently from the agent, and
• how the agent’s actions affect the world.
Goal-based agents
• These kinds of agents take decisions based on how far they are currently
from their goal(description of desirable situations). Their every action is
intended to reduce its distance from the goal. This allows the agent a way
to choose among multiple possibilities, selecting the one which reaches a
goal state. The knowledge that supports its decisions is represented
explicitly and can be modified, which makes these agents more flexible.
They usually require search and planning. The goal-based agent’s behavior
can easily be changed.
Utility-based agents
• The agents which are developed having their end uses as building blocks are called
utility-based agents. When there are multiple possible alternatives, then to decide
which one is best, utility-based agents are used. They choose actions based on
a preference (utility) for each state. Sometimes achieving the desired goal is not
enough. We may look for a quicker, safer, cheaper trip to reach a destination. Agent
happiness should be taken into consideration. Utility describes how “happy” the
agent is. Because of the uncertainty in the world, a utility agent chooses the action
that maximizes the expected utility. A utility function maps a state onto a real
number which describes the associated degree of happiness.
Learning Agent :
• A learning agent in AI is the type of agent that can learn from its past
experiences or it has learning capabilities. Learning element: It is
responsible for making improvements by learning from the environment
• Critic: The learning element takes feedback from critics which describes
how well the agent is doing with respect to a fixed performance standard.
• Performance element: It is responsible for selecting external action
• Problem Generator: This component is responsible for suggesting actions
that will lead to new and informative experiences.
All search methods can be broadly
classified into two categories:
• Uninformed (or Exhaustive or Blind) methods,
where the search is carried out without any
additional information that is already provided in
the problem statement. Some examples include
Breadth First Search, Depth First Search etc.
• Informed (or Heuristic) methods, where search is
carried out by using additional information to
determine the next step towards finding the
solution. Best First Search is an example of such
algorithms
Informed Search Uninformed Search
It uses knowledge for the searching It doesn’t use knowledge for searching
process. process.
It provides the direction regarding the No suggestion is given regarding the solution
solution. in it.
Greedy Search, A* Search, Graph Search. Depth First Search, Breadth First Search.
BFS(Breadth First Search)
BFS stands for Breadth First Search is a vertex
based technique for finding a shortest path in
graph. It uses a Queue data structure which
follows first in first out. In BFS, one vertex is
selected at a time when it is visited and marked
then its adjacent are visited and stored in the
queue. It is slower than DFS.
BFS(Breadth First Search)
A standard BFS implementation puts each vertex of the graph into
one of two categories:
• Visited
• Not Visited
The purpose of the algorithm is to mark each vertex as visited while
avoiding cycles.
The algorithm works as follows:
1. Start by putting any one of the graph's vertices at the back of a
queue.
2. Take the front item of the queue and add it to the visited list.
3. Create a list of that vertex's adjacent nodes. Add the ones which
aren't in the visited list to the back of the queue.
4. Keep repeating steps 2 and 3 until the queue is empty.
Advantages and Disadvantages of BFS
• Advantages:
1. A BFS will find the shortest path between the
starting point and any other reachable node.
A depth-first search will not necessarily find
the shortest path.
• Disadvantages
1. A BFS on a binary tree generally requires
more memory than a DFS.
DFS (Depth First Search )
DFS stands for Depth First Search is a edge
based technique. It uses the Stack data
structure, performs two stages, first visited
vertices are pushed into stack and second if
there is no vertices then visited vertices are
popped.
Depth First Search
Advantages
• Can escape local optimums by picking non-improving
solutions
• The Tabu List can be used to avoid cycles and reverting to
old solutions
• Can be applied to both discrete and continuous solutions
Disadvantages
• Number of iterations can be very high
• There are a lot of tunable parameters in this algorithm
Simulated annealing
• Simulated Annealing (SA) is an effective and general form of
optimization. It is useful in finding global optima in the
presence of large numbers of local optima. “Annealing” refers
to an analogy with thermodynamics, specifically with the way
that metals cool and anneal. Simulated annealing uses the
objective function of an optimization problem instead of the
energy of a material.
• Implementation of SA is surprisingly simple. The algorithm is
basically hill-climbing except instead of picking the best
move, it picks a random move. If the selected move improves
the solution, then it is always accepted. Otherwise, the
algorithm makes the move anyway with some probability less
than 1. The probability decreases exponentially with the
“badness” of the move, which is the amount deltaE by which
the solution is worsened (i.e., energy is increased.)
Advantage and Disadvantages
Advantage
• Easy to code for complex problems as well.
• Gives good solution.
• Statistically guarantees finding optimal solution
Disadvantages
• Slow process
• Can’t tell whether optimal solution is found.