Professional Documents
Culture Documents
AIML-UNIT1
AIML-UNIT1
AIML-UNIT1
AY 2023-2024 SEM-VI
Unit I - Syllabus
Unit – Introduction to AI 09 hours
• The concept of rationality, the nature of environments, structure of agents, problem solving agents,
• Search with partial information (Heuristic search) Hill climbing, A*, AO* Algorithms,
• The concept of rationality, the nature of environments, structure of agents, problem solving agents,
• Search with partial information (Heuristic search) Hill climbing, A*, AO* Algorithms,
Weak AI Strong AI
It supports narrow range of applications It supports wider range of applications
with a limited scope. with a wide scope
This application is good at specific task This application has an incredible human-
level intelligence
• The concept of rationality, the nature of environments, structure of agents, problem solving agents,
• Search with partial information (Heuristic search) Hill climbing, A*, AO* Algorithms,
Sensors, actuators, and effectors are the three main components the intelligent
agents
TYPES OF AI AGENTS
Observable environment: If agent know complete knowledge of environment.
For example: Chess Game
1. Simplest agents
2. Take decisions on the basis of the
current percepts
3. Ignore the rest of the percept history
4. Works on Condition-action (if-then)
rule
5. Environment should be fully
observable
6. Problems: limited intelligence
TYPES OF AI AGENTS
Partially Observable environment: If agent does not know the complete knowledge
of environment. For example: Traffic on road
1. High performance
2. Optimal result
3. Rational action
PROBLEM SOLVING AGENTS IN AI
• The concept of rationality, the nature of environments, structure of agents, problem solving agents,
• Search with partial information (Heuristic search) Hill climbing, A*, AO* Algorithms,
Up
Left
Solution
Right
PROPERTIES OF SEARCH ALGORITHMS
Search Algorithm
Uninformed/Blind
Informed search
search
Breadth First Search Best First Search
Depth First Search A* Search
Uniform Cost Search
Depth Limited Search
Bidirectional Search
TYPES OF SEARCH ALGORITHMS [CONT.. ]
Time consuming, More time & space complexity Quick solution, Less time & space complexity
• The concept of rationality, the nature of environments, structure of agents, problem solving agents,
• Search with partial information (Heuristic search) Hill climbing, A*, AO* Algorithms,
HEURISTIC SEARCH
Heuristic function
• Here H(n) is heuristic cost and • Here H(n) is heuristic cost and
H*(n) is estimated cost. H*(n) is estimated cost.
HEURISTIC
Start State
SEARCH: EXAMPLE
A Heuristic Cost
E H(E)=2
B=3+1=4; C=4+1=5; D=5+1=6
5
2 Actual cost from A to G = 1+3+5+2 = 11
F G ADMISSIBLE
H(B)=3, so H(n)=3 and H*(n)=11
H(F)=3 Goal State
H(n)<=H*(n)
3<=11
HEURISTIC
Start State
SEARCH: EXAMPLE
A Heuristic Cost
1 1 H(D)=5
H(B)=3 1 H(D)=5
E H(E)=2 3
Actual cost from A to G (via D) = 1+3 = 4
5
2
F G NON- H(D)=5, so H(n)=5 and H*(n)=4
ADMISSIBLE
H(F)=3 Goal State H(n)>H*(n)
5>4
GENERATE AND TEST SEARCH
Also known as “British Museum Search Algorithm”.
• Generate and Test Search is a heuristic search technique based on Depth First Search with Backtracking which
guarantees to find a solution if done systematically and there exists a solution.
• The generate-and-test strategy is the simplest of all the approaches. It consists of the following steps:
• Algorithm: Generate-and-Test
1. Generate all possible solutions.
2. Select one solution among the possible
solutions.
3. If a solution has been found and acceptable,
quit. Otherwise return to step 1.
PROPERTIES OF GOOD GENERATOR
Good Generators need to be complete i.e. they should
generate all the possible solutions and cover all the possible
Complete
states. In this way, we can guaranty our algorithm to
converge to the correct solution at some point in time.
• The total number of solutions in this case is (100*100*100) which is approximately 1M.
• If we do not make use of any informed search technique then it results in exponential time
complexity.
• Let’s say if we generate 5 solutions every minute. Then the total numbers generated in 1 hour are
5*60=300 and the total number of solutions to be generated are 1M.
• Let us consider the brute force search technique for example linear search whose average time
complexity is N/2. Then on an average, the total number of the solutions to be generated are
approximately 5 lakhs.
• Using this technique even if you work for about 24 hrs. a day then also you will need 10 weeks to
complete the task.
EXAMPLE: SOLUTION
• Now consider using heuristic function where we have domain knowledge that every number is a
prime number between 0-99 then the possible number of solutions are (25*25*25) which is
approximately 15,000.
• Now consider the same case that you are generating 5 solutions every minute and working for 24
hrs. then you can find the solution in less than 2 days which was being done in 10 weeks in the case
of uninformed search. .
Conclusion
We can conclude for here that if we can find a good heuristic then time complexity can be reduced
gradually. But in the worst-case time and space complexity will be exponential. It all depends on the
generator i.e. better the generator lesser is the time complexity.
HILL CLIMBING ALGORITHM
Salient Features:
• Local Space algorithm
• Greedy Approach
• No Backtracking
HILL CLIMBING ALGORITHM
The State-space diagram is a graphical representation of the set of states(input) our search
algorithm can reach vs the value of our objective function(function we intend to
maximize/minimize).
Global maxima It is the best possible state in the state space diagram. This because at this state,
objective function has the highest value.
Plateau/flat
It is a flat region of state space where neighboring states have the same value.
local maxima
It is a region which is higher than its neighbor's but itself has a slope. It is a special kind
Ridge
of local maximum.
Current state The region of state space diagram where we are currently present during the search.
(Denoted by the highlighted circle in the given image.)
HILL CLIMBING ALGORITHM: TYPES
Step 1: Evaluate the initial state, if it is goal state then return success and Stop.
Step 2: Loop Until a solution is found or there is no new operator left to apply.
Step 5: Exit.
SIMPLE HILL CLIMBING: ALGORITHM
STEEPEST-ASCENT HILL CLIMBING
Step 1: Evaluate the initial state, if it is goal state then return success and stop, else
make the current state as your initial state.
Step 2: Loop until a solution is found or the current state does not change.
1. Let S be a state such that any successor of the current state will be better than it.
2. For each operator that applies to the current state;
• Apply the new operator and generate a new state.
• Evaluate the new state.
• If it is goal state, then return it and quit, else compare it to the S.
• If it is better than S, then set new state as S.
• If the S is better than the current state, then set the current state to S.
Step 3: Exit.
STOCHASTIC HILL CLIMBING
Stochastic hill climbing does not examine for all its neighbours before moving. Rather, this
search algorithm selects one neighbour node at random and evaluate it as a current state
or examine another state.
PROBLEMS IN DIFFERENT REGIONS IN HILL
CLIMBING
To overcome plateaus:
Make a big jump. Randomly
select a state far away from
the current state. Chances
are that we will land at a
non-plateau region
PROBLEMS IN DIFFERENT REGIONS IN HILL
CLIMBING
It is an advanced BFS algorithm that searches for shorter paths first rather than
the longer paths. A* is optimal as well as a complete algorithm.
But A* is slow and also the space it requires is a lot as it saves all the possible
paths that are available to us. This makes other faster algorithms have an upper
hand over A* but it is nevertheless, one of the best algorithms out there.
WHY CHOOSE A* OVER OTHER FASTER
ALGORITHMS?
Dijkstra’s algorithm and A* Algorithm for comparison
A* is used to find the most optimal path from a source to a destination. It optimizes the path
by calculating the least distance from one node to the other.
Need to remember : F = G + H
F : This parameter is used to find the least cost from one node to the next node.
Responsible to find the most optimal path from our source to destination.
H : H is the heuristic/estimated path between the current code to the destination node.
Not actual cost but is the assumption cost from the node to destination.
A* ALGORITHM: EXAMPLE
A* ALGORITHM: EXAMPLE
A* ALGORITHM: ALGORITHM
A* ALGORITHM
2. AO* algorithm uses the concept of AND-OR graphs to decompose any complex
problem given into smaller set of problems which are further solved.
3. AND-OR graphs are specialized graphs that are used in problems that can be
broken down into sub problems where;
• AND side of the graph represent a set of task that need to be done to achieve
the main goal , whereas the
• OR side of the graph represent the different ways of performing task to achieve
the same main goal.
AO* SEARCH ALGORITHM
Want to pass
Mobile
in exam
AND AND
OR OR
AO* SEARCH ALGORITHM: EXAMPLE 01
AO* SEARCH ALGORITHM: EXAMPLE 02
AO* SEARCH ALGORITHM: EXAMPLE 02
Example#3
AO* SEARCH ALGORITHM: EXAMPLE 02
Example#4
AO* SEARCH ALGORITHM: EXAMPLE 02
Example#4
AO* SEARCH ALGORITHM: ALGORITHM
A* VS AO* ALGORITHM
1. A* algorithm provides with the optimal solution, whereas AO* stops when it
finds any solution.
3. AO* algorithm doesn't go into infinite loop whereas the A* algorithm can go
into an infinite loop.
Unit I – Outline
• AI problems, foundation of AI and history of AI intelligent agents: Agents and Environments,
• The concept of rationality, the nature of environments, structure of agents, problem solving agents,
• Search with partial information (Heuristic search) Hill climbing, A*, AO* Algorithms,
There might be some situations where more than one agent is searching for the
solution in the same search space, and this situation usually occurs in game
playing.
The environment with more than one agent is termed as multi-agent environment,
in which each agent is an opponent of other agent and playing against each other.
Searches in which two or more players with conflicting goals are trying to explore the
same search space for the solution, are called adversarial searches, often known
as Games.
TECHNIQUES REQUIRED TO GET THE OPTIMAL
SOLUTION
There is always a need to choose those algorithms which provide the best optimal
solution in a limited time. So, we use the two techniques which could fulfill our
requirements.
Heuristic
It allows to approximate the cost value at each level of the
Evaluation
search tree, before reaching the goal node.
Function
TYPES OF GAMES
A game with the perfect information is that in which agents can look into the
Perfect
complete board. Agents have all the information about the game, and they can
information
see each other moves also.
If in a game agents do not have all information about the game and not aware
Imperfect
with what's going on, such type of games are called the game with imperfect
information
information.
Deterministic Deterministic games are those games which follow a strict pattern and set of rules
games for the games, and there is no randomness associated with them.
Non-deterministic are those games which have various unpredictable events and
Non-
has a factor of chance or luck. This factor of chance or luck is introduced by
deterministic
either dice or cards. These are random, and each action response is not fixed.
games
Such games are also called as stochastic games.
FORMALIZATION OF THE PROBLEM
The minimax algorithm proceeds all the way down to the terminal node of the tree, then
backtrack the tree as the recursion.
In this algorithm two players play the game, one is called MAX and other is called MIN.
Both the players fight it as the opponent player gets the minimum benefit while they get the
maximum benefit.
The minimax algorithm performs a depth-first search algorithm for the exploration of the
complete game tree.
MINI-MAX ALGORITHM: EXAMPLE
There are two players one is called Maximizer and other is called Minimizer.
Maximizer will try to get the Maximum possible score, and Minimizer will try to get the
minimum possible score.
This algorithm applies DFS, so in this game-tree, we have to go all the way through the leaves
to reach the terminal nodes.
At the terminal node, the terminal values are given so we will compare those value and
backtrack the tree until the initial state occurs.
STEPS INVOLVED IN SOLVING THE TWO-
PLAYER GAME TREE
The main drawback of the minimax algorithm is that it gets really slow for
complex games such as Chess, go, etc. This type of games has a huge
branching factor, and the player has lots of choices to decide
ALPHA BETA PRUNING
Alpha-beta pruning is a modified version of the minimax algorithm. It is an optimization technique for the minimax
algorithm.
There is a technique by which without checking each node of the game tree we can compute the correct minimax decision
and this technique is called pruning. This involves two threshold parameter Alpha and beta for future expansion, so it is
called alpha-beta pruning. It is also called as Alpha-Beta Algorithm.
The Alpha-beta pruning to a standard minimax algorithm returns the same move as the standard algorithm does, but it
removes all the nodes which are not really affecting the final decision but making algorithm slow. Hence by pruning these
nodes, it makes the algorithm fast.
ALPHA BETA PRUNING: EXAMPLE
ALPHA BETA PRUNING: ADVANTAGES
ALPHA BETA PRUNING: DISADVANTAGES