UNIT - 1 (Introduction to Artificial Intelligence)
UNIT - 1 (Introduction to Artificial Intelligence)
Intelligence
Unit - I
By Ashutosh Pandey
What is Artificial Intelligence (AI)?
"It is a branch of computer science by which we can create intelligent machines which can behave like a human, think like
humans, and able to make decisions."
AI is one of the fascinating and universal fields of Computer science which has a great scope in future. AI
holds a tendency to cause a machine to work as a human.
It is currently working with a variety of subfields, ranging from general to specific, such as self-driving cars,
playing chess, proving theorems, playing music, Painting, etc.
Advantages of Artificial Intelligence
○ High Accuracy with less errors: AI machines or systems are prone to less errors and high accuracy
as it takes decisions as per pre-experience or information.
○ High-Speed: AI systems can be of very high-speed and fast-decision making, because of that AI
systems can beat a chess champion in the Chess game.
○ High reliability: AI machines are highly reliable and can perform the same action multiple times with
high accuracy.
○ Useful for risky areas: AI machines can be helpful in situations such as defusing a bomb, exploring
the ocean floor, where to employ a human can be risky.
○ Digital Assistant: AI can be very useful to provide digital assistant to the users such as AI
technology is currently used by various E-commerce websites to show the products as per customer
requirement.
○ Useful as a public utility: AI can be very useful for public utilities such as a self-driving car which
can make our journey safer and hassle-free, facial recognition for security purpose, Natural language
Disadvantages of Artificial Intelligence
○ High Cost: The hardware and software requirement of AI is very costly as it requires lots of
maintenance to meet current world requirements.
○ Can't think out of the box: Even we are making smarter machines with AI, but still they cannot
work out of the box, as the robot will only do that work for which they are trained, or programmed.
○ No feelings and emotions: AI machines can be an outstanding performer, but still it does not have
the feeling so it cannot make any kind of emotional attachment with human, and may sometime be
harmful for users if the proper care is not taken.
○ Increase dependency on machines: With the increment of technology, people are getting more
dependent on devices and hence they are losing their mental capabilities.
○ No Original Creativity: As humans are so creative and can imagine some new ideas but still AI
machines cannot beat this power of human intelligence and cannot be creative and imaginative.
Application of AI
1. AI in Astronomy
○ Artificial Intelligence can be very useful to solve complex universe problems. AI technology can be
helpful for understanding the universe such as how it works, origin, etc.
2. AI in Healthcare
○ In the last, five to ten years, AI becoming more advantageous for the healthcare industry and going to
have a significant impact on this industry.
○ Healthcare Industries are applying AI to make a better and faster diagnosis than humans. AI can help
doctors with diagnoses and can inform when patients are worsening so that medical help can reach to
the patient before hospitalization.
3. AI in Gaming
○ AI can be used for gaming purpose. The AI machines can play strategic games like chess, where the
machine needs to think of a large number of possible places.
4. AI in Finance
○ AI and finance industries are the best matches for each other. The finance industry is implementing
automation, chatbot, adaptive intelligence, algorithm trading, and machine learning into financial
processes.
5. AI in Data Security
○ The security of data is crucial for every company and cyber-attacks are growing very rapidly in the
digital world. AI can be used to make your data more safe and secure. Some examples such as AEG bot,
AI2 Platform,are used to determine software bug and cyber-attacks in a better way.
6. AI in Social Media
○ Social Media sites such as Facebook, Twitter, and Snapchat contain billions of user profiles, which need
to be stored and managed in a very efficient way. AI can organize and manage massive amounts of
data. AI can analyze lots of data to identify the latest trends, hashtag, and requirement of different
users.
9. AI in Robotics:
○ Artificial Intelligence has a remarkable role in Robotics. Usually, general robots are programmed such
that they can perform some repetitive task, but with the help of AI, we can create intelligent robots
which can perform tasks with their own experiences without pre-programmed.
○ Humanoid Robots are best examples for AI in robotics, recently the intelligent Humanoid robot named
as Erica and Sophia has been developed which can talk and behave like humans.
10. AI in Entertainment
○ We are currently using some AI based applications in our daily life with some entertainment services
such as Netflix or Amazon. With the help of ML/AI algorithms, these services show the
recommendations for programs or shows.
11. AI in Agriculture
○ Agriculture is an area which requires various resources, labor, money, and time for best result. Now a
day's agriculture is becoming digital, and AI is emerging in this field. Agriculture is applying AI as
agriculture robotics, solid and crop monitoring, predictive analysis. AI in agriculture can be very
helpful for farmers.
12. AI in E-commerce
○ AI is providing a competitive edge to the e-commerce industry, and it is becoming more demanding in
the e-commerce business. AI is helping shoppers to discover associated products with recommended
size, color, or even brand.
13. AI in education:
○ AI can automate grading so that the tutor can have more time to teach. AI chatbot can communicate
with students as a teaching assistant.
○ AI in the future can be work as a personal virtual tutor for students, which will be accessible easily at
any time and any place.
What is an Agent?
An agent can be anything that perceives its environment through sensors and act upon that environment
through actuators. An Agent runs in the cycle of perceiving, thinking, and acting. An agent can be:
○ Human-Agent: A human agent has eyes, ears, and other organs which work for sensors and hand,
legs, vocal tract work for actuators.
○ Robotic Agent: A robotic agent can have cameras, infrared range finder, NLP for sensors and various
motors for actuators.
○ Software Agent: Software agent can have keystrokes, file contents as sensory input and act on
those inputs and display output on the screen.
Types of AI Agents
Agents can be grouped into five classes based on their degree of perceived intelligence and capability. All
these agents can improve their performance and generate better action over the time. These are given
below:
○ The Simple reflex agents are the simplest agents. These agents take decisions on the basis of the
current percepts and ignore the rest of the percept history.
○ These agents only succeed in the fully observable environment.
○ The Simple reflex agent does not consider any part of percepts history during their decision and
action process.
○ The Simple reflex agent works on Condition-action rule, which means it maps the current state to
action. Such as a Room Cleaner agent, it works only if there is dirt in the room.
○ Problems for the simple reflex agent design approach:
○ They have very limited intelligence
○ They do not have knowledge of non-perceptual parts of the current state
○ Not adaptive to changes in the environment.
2. Model-based reflex agent
○ The Model-based agent can work in a partially observable environment, and track the situation.
○ A model-based agent has two important factors:
a. Model: It is knowledge about "how things happen in the world," so it is called a Model-based
agent.
b. Internal State: It is a representation of the current state based on percept history.
○ These agents have the model, "which is knowledge of the world" and based on the model they
perform actions.
○ Updating the agent state requires information about:
a. How the world evolves
b. How the agent's action affects the world.
3. Goal-based agents
○ The knowledge of the current state environment is not always sufficient to decide for an agent to what
to do.
○ The agent needs to know its goal which describes desirable situations.
○ Goal-based agents expand the capabilities of the model-based agent by having the "goal" information.
○ They choose an action, so that they can achieve the goal.
○ These agents may have to consider a long sequence of possible actions before deciding whether the
goal is achieved or not. Such considerations of different scenario are called searching and planning,
which makes an agent proactive.
4. Utility-based agents
○ These agents are similar to the goal-based agent but provide an extra component of utility
measurement which makes them different by providing a measure of success at a given state.
○ Utility-based agent act based not only goals but also the best way to achieve the goal.
○ The Utility-based agent is useful when there are multiple possible alternatives, and an agent has to
choose in order to perform the best action.
○ The utility function maps each state to a real number to check how efficiently each action achieves
the goals.
5. Learning Agents
○ A learning agent in AI is the type of agent which can learn from its past experiences, or it has learning
capabilities.
○ It starts to act with basic knowledge and then able to act and adapt automatically through learning.
○ A learning agent has mainly four conceptual components, which are:
a. Learning element: It is responsible for making improvements by learning from environment
b. Critic: Learning element takes feedback from critic which describes that how well the agent is
doing with respect to a fixed performance standard.
c. Performance element: It is responsible for selecting external action
d. Problem generator: This component is responsible for suggesting actions that will lead to new
and informative experiences.
○ Hence, learning agents are able to learn, analyze performance, and look for new ways to improve the
performance.
Search Algorithms in Artificial Intelligence
Problem-solving agents:
In Artificial Intelligence, Search techniques are universal problem-solving methods. Rational agents
or Problem-solving agents in AI mostly used these search strategies or algorithms to solve a specific
problem and provide the best result. Problem-solving agents are the goal-based agents and use atomic
representation. In this topic, we will learn various problem-solving search algorithms.
Search Algorithm Terminologies:
○ Search: Searching Is a step by step procedure to solve a search-problem in a given search space. A
search problem can have three main factors:
a. Search Space: Search space represents a set of possible solutions, which a system may have.
b. Start State: It is a state from where agent begins the search.
c. Goal test: It is a function which observe the current state and returns whether the goal state is
achieved or not.
○ Search tree: A tree representation of search problem is called Search tree. The root of the search
tree is the root node which is corresponding to the initial state.
○ Actions: It gives the description of all the available actions to the agent.
○ Transition model: A description of what each action do, can be represented as a transition model.
○ Path Cost: It is a function which assigns a numeric cost to each path.
○ Solution: It is an action sequence which leads from the start node to the goal node.
○ Optimal Solution: If a solution has the lowest cost among all solutions.
Properties of Search Algorithms:
Following are the four essential properties of search algorithms to compare the efficiency of these
algorithms:
Completeness: A search algorithm is said to be complete if it guarantees to return a solution if at least any
solution exists for any random input.
Optimality: If a solution found for an algorithm is guaranteed to be the best solution (lowest path cost)
among all other solutions, then such a solution for is said to be an optimal solution.
Time Complexity: Time complexity is a measure of time for an algorithm to complete its task.
Space Complexity: It is the maximum storage space required at any point during the search, as the
complexity of the problem.
Types of search algorithms
Uninformed Search Algorithms
1. Breadth-first Search
2. Depth-first Search
3. Depth-limited Search
4. Iterative deepening depth-first search
5. Uniform cost search
6. Bidirectional Search
1. Breadth-first Search:
○ Breadth-first search is the most common search strategy for traversing a tree or graph. This algorithm
searches breadthwise in a tree or graph, so it is called breadth-first search.
○ BFS algorithm starts searching from the root node of the tree and expands all successor node at the
current level before moving to nodes of next level.
○ The breadth-first search algorithm is an example of a general-graph search algorithm.
○ Breadth-first search implemented using FIFO queue data structure.
Advantages:
Disadvantages:
○ It requires lots of memory since each level of the tree must be saved into memory to expand the next
level.
○ BFS needs lots of time if the solution is far away from the root node.
Example:
In the below tree structure, we have shown the traversing of the tree using BFS algorithm from the root
node S to goal node K. BFS search algorithm traverse in layers, so it will follow the path which is shown by
the dotted arrow, and the traversed path will be:
S---> A--->B---->C--->D---->G--->H--->E---->F---->I---->K
○ Depth-first search isa recursive algorithm for traversing a tree or graph data structure.
○ It is called the depth-first search because it starts from the root node and follows each path to its
greatest depth node before moving to the next path.
○ DFS uses a stack data structure for its implementation.
○ The process of the DFS algorithm is similar to the BFS algorithm.
Advantage:
○ DFS requires very less memory as it only needs to store a stack of the nodes on the path from root
node to the current node.
○ It takes less time to reach to the goal node than BFS algorithm (if it traverses in the right path).
Disadvantage:
○ There is the possibility that many states keep re-occurring, and there is no guarantee of finding the
solution.
Example:
In the below search tree, we have shown the flow of depth-first search, and it will follow the order as:
It will start searching from root node S, and traverse A, then B, then D and E, after traversing E, it will
backtrack the tree as E has no other successor and still goal node is not found. After backtracking it will
traverse node C and then G, and here it will terminate as it found goal node.
Completeness: DFS search algorithm is complete within finite state
space as it will expand every node within a limited search tree.
Heuristics function: It is a technique designed to solve a problem quickly. Heuristic is a function which is
used in Informed Search, and it finds the most promising path. It takes the current state of the agent as its
input and produces the estimation of how close agent is from the goal. It is represented by h(n), and it
calculates the cost of an optimal path between the pair of states. The value of the heuristic function is
always positive.
Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence heuristic cost should be less
than or equal to the estimated cost.
Pure Heuristic Search:
Pure heuristic search is the simplest form of heuristic search algorithms. It expands nodes based on their
heuristic value h(n). It maintains two lists, OPEN and CLOSED list. In the CLOSED list, it places those nodes
which have already expanded and in the OPEN list, it places nodes which have yet not been expanded.
On each iteration, each node n with the lowest heuristic value is expanded and generates all its successors
and n is placed to the closed list. The algorithm continues unit a goal state is found.
In the informed search we will discuss two main algorithms which are given below:
Greedy best-first search algorithm always selects the path which appears best at that moment. It is the
combination of depth-first search and breadth-first search algorithms. It uses the heuristic function and
search. Best-first search allows us to take the advantages of both algorithms. With the help of best-first
search, at each step, we can choose the most promising node. In the best first search algorithm, we expand
the node which is closest to the goal node and the closest cost is estimated by heuristic function, i.e.
1. f(n)= g(n).
Advantages:
○ Best first search can switch between BFS and DFS by gaining the advantages of both the algorithms.
○ This algorithm is more efficient than BFS and DFS algorithms.
Disadvantages:
○ It can behave as an unguided depth-first search in the worst case scenario.
Example:
Consider the below search problem, and we will traverse it using greedy best-first search. At each iteration,
each node is expanded using evaluation function f(n)=h(n) , which is given in the below table.
In this search example, we are using two lists which are OPEN and CLOSED Lists.
Time Complexity: The worst case time complexity of Greedy best first search is O(b m).
Space Complexity: The worst case space complexity of Greedy best first search is O(b m). Where, m is the
maximum depth of the search space.
Complete: Greedy best-first search is also incomplete, even if the given state space is finite.
A* search is the most commonly known form of best-first search. It uses heuristic function h(n), and cost to
reach the node n from the start state g(n). It has combined features of UCS and greedy best-first search, by
which it solve the problem efficiently. A* search algorithm finds the shortest path through the search space
using the heuristic function. This search algorithm expands less search tree and provides optimal result
faster. A* algorithm is similar to UCS except that it uses g(n)+h(n) instead of g(n).
In A* search algorithm, we use search heuristic as well as the cost to reach the node. Hence we can combine
both costs as following, and this sum is called as a fitness number.
Algorithm of A* search:
Step1: Place the starting node in the OPEN list.
Step 2: Check if the OPEN list is empty or not, if the list is empty then return failure and stops.
Step 3: Select the node from the OPEN list which has the smallest value of evaluation function (g+h), if
node n is goal node then return success and stop, otherwise
Step 4: Expand node n and generate all of its successors, and put n into the closed list. For each successor
n', check whether n' is already in the OPEN or CLOSED list, if not then compute evaluation function for n' and
place into Open list.
Step 5: Else if node n' is already in OPEN and CLOSED, then it should be attached to the back pointer which
reflects the lowest g(n') value.
Disadvantages:
○ It does not always produce the shortest path as it mostly based on heuristics and approximation.
○ A* search algorithm has some complexity issues.
○ The main drawback of A* is memory requirement as it keeps all generated nodes in the memory, so
it is not practical for various large-scale problems.
Example:
In this example, we will traverse the given graph using the A* algorithm. The heuristic value of all states is
given in the below table so we will calculate the f(n) of each state using the formula f(n)= g(n) + h(n), where
g(n) is the cost to reach any node from start state.
Here we will use OPEN and CLOSED list.
Solution:
Initialization: {(S, 5)}
Iteration3: {(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S--> A-->B, 7), (S-->G, 10)}
Iteration 4 will give the final result, as S--->A--->C--->G it provides the optimal path with cost 6.
Points to remember:
○ A* algorithm returns the path which occurred first, and it does not search for all remaining paths.
○ The efficiency of A* algorithm depends on the quality of heuristic.
○ A* algorithm expands all nodes which satisfy the condition f(n)
Time Complexity: The time complexity of A* search algorithm depends on heuristic function, and the
number of nodes expanded is exponential to the depth of solution d. So the time complexity is O(b^d),
where b is the branching factor.
○ Hill climbing algorithm is a local search algorithm which continuously moves in the direction of
increasing elevation/value to find the peak of the mountain or best solution to the problem. It
terminates when it reaches a peak value where no neighbor has a higher value.
○ Hill climbing algorithm is a technique which is used for optimizing the mathematical problems. One of
the widely discussed examples of Hill climbing algorithm is Traveling-salesman Problem in which we
need to minimize the distance traveled by the salesman.
○ It is also called greedy local search as it only looks to its good immediate neighbor state and not
beyond that.
○ A node of hill climbing algorithm has two components which are state and value.
○ Hill Climbing is mostly used when a good heuristic is available.
○ In this algorithm, we don't need to maintain and handle the search tree or graph as it only keeps a
single current state.
Features of Hill Climbing:
Following are some main features of Hill Climbing Algorithm:
○ Generate and Test variant: Hill Climbing is the variant of Generate and Test method. The Generate
and Test method produce feedback which helps to decide which direction to move in the search
space.
○ Greedy approach: Hill-climbing algorithm search moves in the direction which optimizes the cost.
○ No backtracking: It does not backtrack the search space, as it does not remember the previous
states.
State-space Diagram for Hill Climbing:
The state-space landscape is a graphical representation of the hill-climbing algorithm which is showing a
graph between various states of algorithm and Objective function/Cost.
On Y-axis we have taken the function which can be an objective function or cost function, and state-space on
the x-axis. If the function on Y-axis is cost then, the goal of search is to find the global minimum and local
minimum. If the function of Y-axis is Objective function, then the goal of the search is to find the global
maximum and local maximum.
Different regions in the state space landscape:
Local Maximum: Local maximum is a state which is better than its neighbor states, but there is also
another state which is higher than it.
Global Maximum: Global maximum is the best possible state of state space landscape. It has the highest
value of objective function.
Flat local maximum: It is a flat space in the landscape where all the neighbor states of current states have
the same value.
○ 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 3: Select and apply an operator to the current state.
○ Step 4: Check new state:
a. If it is goal state, then return success and quit.
b. Else if it is better than the current state then assign new state as a current state.
c. Else if not better than the current state, then return to step2.
○ Step 5: Exit.
Problems in Hill Climbing Algorithm:
1. Local Maximum: A local maximum is a peak state in the landscape which is better than each of its
neighboring states, but there is another state also present which is higher than the local maximum.
Solution: Backtracking technique can be a solution of the local maximum in state space landscape. Create
a list of the promising path so that the algorithm can backtrack the search space and explore other paths as
well.
2. Plateau: A plateau is the flat area of the search space in which all the neighbor states of the current
state contains the same value, because of this algorithm does not find any best direction to move. A hill-
climbing search might be lost in the plateau area.
Solution: The solution for the plateau is to take big steps or very little steps while searching, to solve the
problem. Randomly select a state which is far away from the current state so it is possible that the algorithm
3. Ridges: A ridge is a special form of the local maximum. It has an area which is higher than its
surrounding areas, but itself has a slope, and cannot be reached in a single move.
Solution: With the use of bidirectional search, or by moving in different directions, we can improve this
problem.
Simulated Annealing:
A hill-climbing algorithm which never makes a move towards a lower value guaranteed to be incomplete
because it can get stuck on a local maximum. And if algorithm applies a random walk, by moving a
successor, then it may complete but not efficient. Simulated Annealing is an algorithm which yields
both efficiency and completeness.
In mechanical term Annealing is a process of hardening a metal or glass to a high temperature then
cooling gradually, so this allows the metal to reach a low-energy crystalline state. The same process is
used in simulated annealing in which the algorithm picks a random move, instead of picking the best
move. If the random move improves the state, then it follows the same path. Otherwise, the algorithm
follows the path which has a probability of less than 1 or it moves downhill and chooses another path.