Introduction To Artificial Intelligence
Introduction To Artificial Intelligence
Authored by
Ayesha Naureen M.Tech (Ph.D)
Assistant Professor
CSE Dept
BVRIT
AY: 2024-2025 SEM-I, Regulation- 22
II B.Tech
Syllabus:
UNIT I
Introduction:
Artificial Intelligence
What is Artificial Intelligence?
According to the father of Artificial Intelligence, John McCarthy, it is “The science and
engineering of making intelligent machines, especially intelligent computer programs”.
Artificial Intelligence is a way of making a computer, a computer-controlled robot, or a
software think intelligently, in the similar manner the intelligent humans think. AI is
accomplished by studying how the human brain thinks, and how humans learn, decide, and
work while trying to solve a problem, and then using the outcomes of this study as a basis of
developing intelligent software and systems.
AI Approaches Cognitive science, Laws of thought, Turing Test, Rational agent.
AI Techniques Techniques that make system to behave as Intelligent, Describe and match,
Goal reduction, Constraint satisfaction, Tree Searching, Generate and test, Rule based
systems, Biology-inspired AI techniques Neural Networks, Genetic Algorithms,
Reinforcement learning.
Philosophy of AI
● While exploiting the power of the computer systems, the curiosity of humans, led him to
wonder, “Can a machine think and behave like humans do?”
● Thus, the development of AI started with the intention of creating similar intelligence in
machines that we find and regard high in humans.
Goals of AI
● To Create Expert Systems − The systems which exhibit intelligent behaviour, learn,
demonstrate, explain, and advice its users
.● To Implement Human Intelligence in Machines − Creating systems that understand, think,
learn, and behave like humans.
General AI Goal, Engineering based AI Goal, Science-based AI Goal.
Applications of AI
Game playing, Speech Recognition, Natural Language processing, Computer Vision, Expert
Systems.
Game Playing:-
Game playing is a popular application of artificial intelligence that involves the
development of computer programs to play games, such as chess, checkers, or Go. The goal
of game playing in artificial intelligence is to develop algorithms that can learn how to play
games and make decisions that will lead to winning outcomes.
Speech recognition:
Speech recognition is the process of identifying a human voice. Typically, businesses create
these programs and integrate them into various hardware devices to identify speech. When
the program hears your voice or receives your order, it will respond appropriately.
Numerous businesses create software that recognizes speech using cutting-edge technologies
like artificial intelligence, machine learning, and neural networks. The way individuals utilize
hardware and electrical devices has been changed by technologies like Siri, Amazon, Google
Assistant, and Cortana. They include smartphones, devices for home security, cars, etc.
Computer Vision:
AI algorithms have transformed computer vision by enabling machines to analyze and
understand images and videos. Applications like object detection, facial recognition,
autonomous vehicles, and medical imaging heavily rely on AI in computer vision.
1. Search - Searching solves a search issue in a given space step by step. Three major
factors can influence a search issue.
2. Search tree - A Search tree is a tree representation of a search issue. The node at the
root of the search tree corresponds to the initial condition.
3. Actions - It describes all the steps, activities, or operations accessible to the agent.
4. Transition model - It can be used to convey a description of what each action does.
5. Path Cost - It is a function that gives a cost to each path.
6. Solution - An action sequence connects the start node to the target node.
7. Optimal Solution - If a solution has the lowest cost among all solutions, it is said to
be the optimal answer.
Problem Formulation:
Example:
A problem is defined by four items:
1. initial state e.g., "at Arad―
2. actions or successor function : S(x) = set of action–state pairs e.g., S(Arad) = {, … }
3. goal test (or set of goal states) e.g., x = "at Bucharest‖, Checkmate(x)
4. path cost (additive) e.g., sum of distances, number of actions executed, etc. c(x,a,y) is the
step cost, assumed to be ≥ 0 A solution is a sequence of actions leading from the initial state
to a goal state.
1. It is very useful in AI because of it provides a set of all possible states, operations and
goals.
2. If the entire state space for a problem is given then it is possible to trace the path from
the initial to goal state and identify the sequence of operation required for doing it.
2. The resources of the computer system are very limited to handle huge combinational
state-space.
These characteristics often contrast the effectiveness of various search algorithms in artificial
intelligence.
N-puzzle that consists of N tiles (N+1 titles with an empty tile) where N can be 8, 15,
24 and so on.
In the same way, if we have N = 15, 24 in this way, then they have Row and columns
as follow (square root of (N+1) rows and square root of (N+1) columns).
That is if N=15 than number of rows and columns= 4, and if N= 24 number of rows
and columns= 5.
So, basically in these types of problems we have given a initial state or initial
-------------------------------------------------------------------------------------------------------------
Potential solutions that need to be generated vary depending on the kinds of problems
• For some problems the possible solutions may be particular points in the problem space and
for some problems, paths from the start state
Generate-and-test, like depth-first search, requires that complete solutions be generated for
testing
• In its most systematic form, it is only an exhaustive search of the problem space.
• Solutions can also be generated randomly but solution is not guaranteed
• This approach is what is known as British Museum algorithm: finding an object in the
British Museum by wandering randomly.
While generating complete solutions and generating random solutions are the two extremes
there exists another approach that lies in between
The approach is that the search process proceeds systematically but some paths that unlikely
to lead the solution are not considered.
• This evaluation is performed by a heuristic function
Importance of Search Algorithms in Artificial Intelligence
The following points explain how and why the search algorithms in AI are important:
---------------------------------------------------------------------------------------------------------
Simple search
Simple search problem 1:
Algorithm:
SimpleSearch()
Open{start}
While open is not empty
Do pick some node n from open
Openopen\{n}
If GoalTest(n)=True
Then return n
Else open open U MoveGen(n)
Return FAILURE
Simple Search problem 2:
Algorithm:
----------------------------------------------------------------------------------------------------------
Search:
Search is the systematic examination of states to find path from the start/root state to the goal
state. Many traditional search algorithms are used in AI applications. For complex problems,
the traditional algorithms are unable to find the solution within some practical time and space
limits.
Consequently, many special techniques are developed; using heuristic functions. The
algorithms that use heuristic functions are called heuristic algorithms. Heuristic algorithms
are not really intelligent; they appear to be intelligent because they achieve better
performance. Heuristic algorithms aremore efficient because they take advantage of feedback
from the data to direct the search path.
We can divide search algorithms in artificial intelligence into uninformed (Blind search) and
informed (Heuristic search) algorithms based on the search issues.
Uninformed/Blind Search
The uninformed search does not contain any domain knowledge such as closeness, the
location of the goal. It operates in a brute-force way as it only includes information about
how to traverse the tree and how to identify leaf and goal nodes. Uninformed search applies a
way in which search tree is searched without any information about the search space like
initial state operators and test for the goal, so it is also called blind search.It examines each
node of the tree until it achieves the goal node.
Informed Search
A heuristic is a way which might not always be guaranteed for best solutions but guaranteed
to find a good solution in reasonable time.
Informed search can solve much complex problem which could not be solved in another way.
1. Greedy Search
2. A* Search
Application of Informed Search Algorithms
Informed search algorithms are extensively used in various applications, such as:
1. Path finding in Navigation Systems: Used to calculate the shortest route from a point A
to point B on a map.
2. Game Playing: Helps in determining the best moves in games like chess or Go by
evaluating the most promising moves first.
3. Robotics: Utilized in autonomous navigation where a robot must find the best path
through an environment.
4. Problem Solving in AI: Applied to a range of problems from scheduling and planning
to resource allocation and logistics.
--------------------------------------------------------------------------------------------------------------
-----------------------
Depth first search (DFS)
o Depth-first search is a recursive algorithm for traversing a tree or graph data structure.
o 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.
o DFS uses a stack data structure for its implementation. Last in first out (LIFO)
o The process of the DFS algorithm is similar to the BFS algorithm.
Note: Backtracking is an algorithm technique for finding all possible solutions using
recursion.
Advantage:
o 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.
o It takes less time to reach to the goal node than BFS algorithm (if it traverses in the
right path).
o With the help of this we can stores the route which is being tracked in memory to save
time as it only needs to keep one at a particular time.
Disadvantage:
o There is the possibility that many states keep re-occurring, and there is no guarantee
of finding the solution.
o DFS algorithm goes for deep down searching and sometime it may go to the infinite
loop.
o The de¬pth-first search (DFS) algorithm does not always find the shorte¬st path to a
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.
Time Complexity: Time complexity of DFS will be equivalent to the node traversed by the
algorithm. It is given by:
Where, m= maximum depth of any node and this can be much larger than d (Shallowest
solution depth)
Space Complexity: DFS algorithm needs to store only single path from the root node, hence
space complexity of DFS is equivalent to the size of the fringe set, which is O(bm).
Optimal: DFS search algorithm is non-optimal, as it may generate a large number of steps or
high cost to reach to the goal node.
--------------------------------------------------------------------------------------------------------------
Exploration:
Dequeue an element from the front of the queue. Here, we start with node
current_node = 1.
Finishing Up:
Continue the process until the queue is empty, dequeuing nodes 6, 4, and
5 sequentially, each time checking their neighbors. Since all neighbors
will have been already visited by the time we process these nodes, no
new nodes are added to the queue.
The final order of traversal in BFS starting from node 1 in this graph will be: 1, 2, 3, 6, 4, 5.
This order reflects how BFS explores all neighbors at the current depth before moving to
nodes at the next depth level.
2. Push the Source node or the Starting node onto the stack and set its STATUS=2(waiting).
3. Repeat steps 4 to 5 until the stack is empty or the goal node has been reached.
4. Pop the top node T of the stack and set its STATUS=3(visited).
5. Push all the neighbours of node T onto the stack in the ready state (STATUS=1) and with a
depth less than or equal to depth limit 'l' and set their STATUS=2(waiting).
(END OF LOOP)
6. END
When one of the following instances are satisfied, a Depth Limited Search can be terminated.
When we get to the target node.
Once all of the nodes within the specified depth limit have been visited.
Step by Step Example
Consider the given graph with Depth Limit(l)=2, Target Node=H and the given source
node=A
Step 1 :
Now, the first element of the source node is pushed onto the stack.
Step 2 :
A being the top element is now popped from the stack and the neighbouring nodes B and C at
depth=1(<l) of A are pushed onto the stack.
Traversal: A
Step 3 :
C being the topmost element is popped from the stack and the neighbouring node F at
depth=2(=l) is pushed onto the stack.
Traversal: AC
Step 4 :
F being the topmost element is popped from the stack and the neighbouring nodes I and J at
depth=3(>l) will not be pushed onto the stack.
Traversal: ACF
Step 5 :
B being the topmost element is popped from the stack and the neighbouring nodes D and E at
depth=2(=l) are pushed onto the stack.
Traversal: ACFB
Step 6 :
E being the topmost element is popped from the stack and since E has no neighbouring
nodes, no nodes are pushed onto the stack.
Traversal: ACFBE
Step 7 :
D being the topmost element is popped from the stack and the neighbouring nodes G and H at
depth=3(>l) will not be pushed onto the stack.
Traversal: ACFBED
Since the stack is now empty, all nodes within the depth limit have been visited, but the
target node H has not been reached.
Heuristic functions are strategies or methods that guide the search process in AI
algorithms by providing estimates of the most promising path to a solution. They are often
used in scenarios where finding an exact solution is computationally infeasible. Instead,
heuristics provide a practical approach by narrowing down the search space, leading to
faster and more efficient problem-solving.
Heuristic functions transform complex problems into more manageable subproblems by
providing estimates that guide the search process. This approach is particularly effective in
AI planning, where the goal is to sequence actions that lead to a desired outcome.
Applications of Heuristic Search
Heuristic search techniques find application in a wide range of problem-solving scenarios,
including:
1. Path finding: Discovery, of the shortest distance that can be found from the start point
to the destination at the point of coordinates or graph.
2. Optimization: Solving the problem of the optimal distribution of resources, planning or
posting to achieve maximum results.
3. Game Playing: The agency of AI with some board games, e.g., chess or Go, is on giving
guidance and making strategy-based decisions to the agents.
4. Robotics: Scheduling robots` location and movement to guide carefully expeditions and
perform given tasks with high efficiency.
5. Natural Language Processing: Language processing tasks involving search algorithms,
such as parsing or semantic analysis, should be outlined. That means.
Best First Search
Best First Search is a heuristic search algorithm that explores a graph by expanding the most
promising node first, according to a specified evaluation function. It continuously selects
nodes based on their estimated cost to reach the goal, typically using a priority queue. BFS is
suitable for finding paths in graphs and optimization problems where informed decision-
making is crucial.
Here's a concise explanation of the Best First Search algorithm in step-by-step form:
BFS uses the concept of a Priority queue and heuristic search. To search the graph space, the
BFS method uses two lists for tracking the traversal. An ‘Open’ list that keeps track of the
current ‘immediate’ nodes available for traversal and a ‘CLOSED’ list that keeps track of the
nodes already traversed.
Best First Search problem:
Hill climbing
1. Local Optima: Hill climbing is prone to getting stuck in local optima, especially in
complex, multi-modal landscapes where multiple peaks exist.
2. Lack of Exploration: It can be myopic, as it only explores nearby solutions. It may
miss a globally optimal solution if it requires moving away from the current position
initially.
3. Sensitivity to Initial State: The quality of the solution found is highly dependent on
the initial state, making it sensitive to the starting point.
Hill climbing comes in several flavors, each with its own approach to finding the optimal
solution:
Simple Hill Climbing is the most basic form of the algorithm. It iteratively makes small
moves to neighboring solutions, accepting a new solution only if it improves the objective
function. If it doesn't, the algorithm terminates. This method is limited by its tendency to get
stuck in local optima.
While Simple Hill Climbing has advantages such as simplicity and memory efficiency, it also
has limitations. It can get stuck in local optima, miss global optima, and its performance is
sensitive to the initial solution. To address these limitations, more advanced variants and
enhancements of hill climbing algorithms have been developed, such as steepest-ascent hill
climbing, simulated annealing, and genetic algorithms, which offer improved exploration of
the solution space and better convergence properties.
Steepest-Ascent Hill Climbing, also known as steepest ascent or gradient ascent, takes a more
rigorous approach. It explores all neighboring solutions and selects the one that offers the
most significant improvement in the objective function. This helps mitigate the problem of
getting stuck in local optima to some extent.
Steepest-Ascent Hill Climbing is called "steepest" because it rigorously explores all possible
moves before deciding on the best one. This approach helps mitigate the problem of getting
stuck in local optima, as it can escape from a local peak by considering all available options.
Stochastic Hill Climbing's stochastic nature allows it to explore a wider range of solutions,
potentially escaping local optima that deterministic hill climbing algorithms might get
trapped in. It is particularly useful in situations where a more exploratory approach is desired,
and it's not necessary to find the absolute best solution but rather a satisfactory one.
However, the randomness in Stochastic Hill Climbing can also be a drawback because it may
lead the algorithm to accept inferior solutions more frequently, making it less efficient in
converging to optimal or near-optimal solutions. To mitigate this, variants of Stochastic Hill
Climbing often include strategies for controlling the degree of randomness, such as simulated
annealing.
In the context of the Hill Climbing algorithm, the state space diagram is a visual
representation of the landscape of possible solutions for an optimization problem. It helps us
understand the different regions within this landscape.
To visualize how the hill climbing algorithm works, we can represent it using a state-space
diagram. In this diagram:
The algorithm starts at an initial state and follows arrows to explore neighboring states in
search of the highest peak.
The X-axis represents the potential states or configurations that our algorithm can attain.
Meanwhile, the Y-axis represents the respective values of the objective function associated
with each state.
Here's an in-depth explanation of the various regions in the state space diagram:
1. Local Optima: Local optima are points in the state space where the objective
function has a high value (in maximization problems) or a low value (in minimization
problems), and these points are surrounded by solutions with lower in maximization
or higher in minimization values of the objective function.
2. Plateaus: Plateaus are flat regions in the state space where the objective function
remains constant over a range of solutions. In other words, many neighboring
solutions have nearly identical objective function values.
3. Ridges: Ridges are narrow, elevated paths in the state space diagram that lead to
higher regions. These paths typically have a higher objective function value than the
surrounding solutions.
4. Global Optimum: The global optimum is the highest point (in maximization
problems) or the lowest point (in minimization problems) in the state space,
representing the best possible solution for the optimization problem.
The most common issue in Hill Climbing, is getting stuck in local optima. In a local
optimum, the algorithm perceives no direction of improvement, as all neighboring
solutions have worse objective function values. It terminates, assuming it has found
the best solution.
Plateaus are flat regions in the solution space where the objective function remains
constant over a range of solutions. Hill Climbing struggles on plateaus because it can't
discern the direction of improvement.
Ridges are elevated paths in the solution space that may not lead directly to a peak but
offer better objective function values than the surrounding solutions. Hill Climbing
can oscillate along ridges without significant progress.
The hill climbing algorithm finds applications in various domains within artificial
intelligence and optimization:
1. Machine Learning: Hill climbing can be used for hyperparameter tuning in machine
learning algorithms, finding the best combination of hyperparameters for a model.
2. Robotics: In robotics, hill climbing can help robots navigate through physical
environments, adjusting their paths to reach a destination.
3. Network Design: It can be used to optimize network topologies and configurations in
telecommunications and computer networks.
4. Game Playing: In game playing AI, hill climbing can be employed to develop
strategies that maximize game scores.
5. Natural Language Processing: It can optimize algorithms for tasks like text
summarization, machine translation, and speech recognition.
Local Maxima
Solution Space search
In the SAT problem, the objective is to determine whether there is an assignment of truth
values (true or false) to variables that make the Boolean formula true.
In AI, finding a solution to the SAT problem is often framed as a search in the solution
space. The solution space is made up of all possible assignments of truth values to the
Boolean variables. For a problem with nnn variables, the solution space has 2n2^n2n possible
assignments.
Brute Force Search: This involves checking all possible combinations of truth
assignments for the variables. This approach becomes impractical for large instances,
as the number of possible combinations grows exponentially.
Backtracking Search: A more efficient method, backtracking incrementally builds
solutions, checking constraints at each step. If an assignment of a variable violates a
clause in the formula, the algorithm "backtracks" to the previous step and tries a
different value.
variable neighbourhood descent
Variable Neighbourhood Descent (VND) is a local search algorithm used in optimization
and artificial intelligence (AI) that systematically changes the neighborhood structure during
the search process to avoid getting trapped in local optima. It is a deterministic variant of
Variable Neighbourhood Search (VNS), which explores different neighborhoods to
enhance the search for a global optimum in a given solution space.
VND Works:
VND starts with an initial solution and then applies local search within different
neighborhoods. If an improvement is found in a neighborhood, it resets the search to the first
neighborhood and continues. If no improvement is found, it switches to the next
neighborhood. The process continues until no better solution can be found across all
neighborhoods.
Algorithm of Variable neighbourhood Descent
Beam Search
Beam search is a heuristic search algorithm that explores a graph by expanding the most
optimistic node in a limited set. Beam search is an optimization of best-first search that
reduces its memory requirements.
Beam search uses breadth-first search to build its search tree. At each level of the tree, it
generates all successors of the states at the current level, sorting them in increasing order of
heuristic cost. However, it only stores a predetermined number (β), of best states at each
level called the beamwidth. Only those states are expanded next. 4M
For example, let's take the value of ß = 2 for the tree shown below. So, follow the following
steps to find the goal node.
Beam search operates by maintaining a fixed number of best nodes (partial solutions) at each
level of the search tree. It expands only the most promising candidates at each step and
discards the rest, making it more efficient in practice than BFS or exhaustive search.
Characteristics of Beam Search
Width of the Beam (W): This parameter defines the number of nodes considered at each
level. The beam width W directly influences the number of nodes evaluated and hence
the breadth of the search.
Branching Factor (B): If B is the branching factor, the algorithm evaluates W×B nodes
at every depth but selects only W for further expansion.
Completeness and Optimality: The restrictive nature of beam search, due to a limited
beam width, can compromise its ability to find the best solution as it may prune
potentially optimal paths.
Memory Efficiency: The beam width bounds the memory required for the search,
making beam search suitable for resource-constrained environments.
The process of Beam Search can be broken down into several steps:
1. Initialization: Start with the root node and generate its successors.
2. Node Expansion: From the current nodes, generate successors and apply the heuristic
function to evaluate them.
3. Selection: Select the top W nodes according to the heuristic values. These selected nodes
form the next level to explore.
4. Iteration: Repeat the process of expansion and selection for the new level of nodes until
the goal is reached or a certain condition is met (like a maximum number of levels).
5. Termination: The search stops when the goal is found or when no more nodes are
available to expand.
Tabu Search
Tabu search is augment exploitative stratergy of heuristic search with an explorative tendency
that looks for new areas in the search space..
The search follows the diktat of heuristic function as long as better .but there are no better
choices instead of termination local search ,it gives explorative tendency to continue search.
Tabu search modifies termination criteria. the algorithm dosnt terminate on reaching
maximum but continue searching beyond until other criteria is met.
One way getting most out of search would be keept rack of best solution found.. TS is guided
by heuristic function. even if go beyond local maximum. one way to search away from
maxima is keep finite closed list which nodes are recent nodes are stored. such a closed list
could be implemented as circular que of k elements where last k node are stored.
UNIT III
Iterated Hill Climbing is an extension of the basic hill climbing algorithm, a local search
method used in optimization problems and artificial intelligence (AI). Unlike basic hill
climbing, which can easily get stuck in local optima, iterated hill climbing repeatedly applies
the hill climbing process from different starting points to find better solutions and overcome
the limitations of local search.
To overcome the problem of getting stuck in local optima, iterated hill climbing restarts the
hill climbing process from different initial random states. The idea is that each restart gives
the algorithm a new chance to explore a different part of the solution space, increasing the
chances of finding the global optimum.
Steps:
1. Initial Random Solution: Choose an initial random solution from the solution space.
2. Local Search (Hill Climbing): Perform hill climbing on this solution until you reach
a local optimum.
3. Restart: Once you reach a local optimum, generate a new random initial solution and
restart the hill climbing process.
4. Best Solution Tracking: Keep track of the best solution found during each hill
climbing iteration.
5. Repeat: Repeat the process a predefined number of times or until a time/iteration
limit is reached.
Simulated Annealing
Simulated annealing is a stochastic global search optimization algorithm and it modified
version of stochastic hill climbing.
This algorithm appropriate for nonlinear objective functions, where other local search
algorithm do not operate well
The simulated annealing solution is to start by high temperature and then gradually reduce the
intensity of lower temperature.
Simulated annealing is very useful for situations where there are lot of local minima.
Simulated annealing improves this stratergy through the introduction of two tricks.
This algorithm picks a random move instead of picking the best move.
If the move improves result then it accepts this random move otherwise it accepts the move
with some probability less than 1.
Genetic Algorithm
Genetic Algorithms(GAs) are adaptive heuristic search algorithms that belong to the larger
part of evolutionary algorithms. Genetic algorithms are based on the ideas of natural
selection and genetics. These are intelligent exploitation of random searches provided with
historical data to direct the search into the region of better performance in solution
space. They are commonly used to generate high-quality solutions for optimization
problems and search problems.
Genetic algorithms simulate the process of natural selection which means those species
that can adapt to changes in their environment can survive and reproduce and go to the next
generation. In simple words, they simulate “survival of the fittest” among individuals of
consecutive generations to solve a problem. Each generation consists of a population of
individuals and each individual represents a point in search space and possible solution.
Each individual is represented as a string of character/integer/float/bits. This string is
analogous to the Chromosome.
Search space
The populations of individuals are maintained within search space. Each individual
represents a solution in search space for given problem. Each individual is coded as a finite
length vector (analogous to chromosome) of components. These variable components are
analogous to Genes. Thus a chromosome (individual) is composed of several genes
(variable components).
Fitness Score
A Fitness Score is given to each individual which shows the ability of an individual to
“compete”. The individual having optimal fitness score (or near optimal) are sought.
The GAs maintains the population of n individuals (chromosome/solutions) along with their
fitness scores.The individuals having better fitness scores are given more chance to
reproduce than others. The individuals with better fitness scores are selected who mate and
produce better offspring by combining chromosomes of parents. The population size is
static so the room has to be created for new arrivals. So, some individuals die and get
replaced by new arrivals eventually creating new generation when all the mating
opportunity of the old population is exhausted. It is hoped that over successive generations
better solutions will arrive while least fit die.
Each new generation has on average more “better genes” than the individual (solution) of
previous generations. Thus each new generations have better “partial solutions” than
previous generations. Once the offspring produced having no significant difference from
offspring produced by previous populations, the population is converged. The algorithm is
said to be converged to a set of solutions for the problem.
Once the initial generation is created, the algorithm evolves the generation using following
operators –
1) Selection Operator: The idea is to give preference to the individuals with good fitness
scores and allow them to pass their genes to successive generations.
2) Crossover Operator: This represents mating between individuals. Two individuals are
selected using selection operator and crossover sites are chosen randomly. Then the genes
at these crossover sites are exchanged thus creating a completely new individual
(offspring).
For example –
3) Mutation Operator: The key idea is to insert random genes in offspring to maintain the
diversity in the population to avoid premature convergence. For example –
12M
o Optimizing: In this case, the best solution is found. To find the best solution, it may
either find all the possible solutions to find the best solution or if the value of the best
solution is known, it stops finding when the best solution is found. For example:
Finding the best path for the travelling salesman problem. Here best path means that
travelling all the cities and the cost of travelling should be minimum.
o Satisficing: It stops finding the solution as soon as the satisfactory solution is found.
Or example, finding the travelling salesman path which is within 10% of optimal.
o Often Brute force algorithms require exponential time. Various heuristics and
optimization can be used:
o Heuristic: A rule of thumb that helps you to decide which possibilities we should
look at first.
o Optimization: A certain possibility are eliminated without exploring all of them.
Let's understand the brute force search through an example.
Suppose we have converted the problem in the form of the tree shown as below:
Brute force search considers each and every state of a tree, and the state is represented in the
form of a node. As far as the starting position is concerned, we have two choices, i.e., A state
and B state. We can either generate state A or state B. In the case of B state, we have two
states, i.e., state E and F.
In the case of brute force search, each state is considered one by one. As we can observe in
the above tree that the brute force search takes 12 steps to find the solution.
On the other hand, backtracking, which uses Depth-First search, considers the below states
only when the state provides a feasible solution. Consider the above tree, start from the root
node, then move to node A and then node C. If node C does not provide the feasible solution,
then there is no point in considering the states G and H. We backtrack from node C to node A.
Then, we move from node A to node D. Since node D does not provide the feasible solution,
we discard this state and backtrack from node D to node A.
We move to node B, then we move from node B to node E. We move from node E to node K;
Since k is a solution, so it takes 10 steps to find the solution. In this way, we eliminate a
greater number of states in a single iteration. Therefore, we can say that backtracking is faster
and more efficient than the brute force approach
Suppose if we try to apply the branch and bound technique to the TSP. Now let us assume
that we have seven cities as shown in the module no.8 and different paths between them are
available like in module 8.
One typical way to use refinement search for TSP is to pick up a city as a root node and
have all other cities connected as children. Thus each child represent a city other than the
root. The first level of tree depicts first move from starting city to all other cities
From those cities, we have second level of the tree, they have similar children indicating
cities other than the parent and itself. This second level describes second leg of the tour. We
can complete the entire tree like this. The tree is as long as the tours and thus the maximum
number of levels a tree can have is the length of the tour. In other words the tree describes
each possible tour begins from the city described as the root node. This tree, in a way,
describes a solution space for all solutions begin from root. We now need to search in this
solution space and get the cheapest path.
For solving the complete TSP problem, we need to have as many trees as the number of
cities. For example if we have seven cities A,B,C,D,E,F,G then we will have seven trees, one
tree with root node as A, another with root node as B and so on. Each tree contains other
cities as nodes at the second level. Each branch starting from the root node indicates the tour.
The edges of the tree is weighted and the number indicates the distance between the cities.
These seven trees describe the complete solution space for the TSP we have described. Let us
see how we search through it to find out the cheapest solution. We will show how we can get
cheapest path for one tree. We can do the same thing for all other trees. Now we can compare
all solutions that we have got so far and select the cheapest from the lot.
Look at figures 12.2 and table 12.1. The distances are depicted as weights of the arcs in the
graph in figure 12.23. Suppose now we assume one of the city as a root and draw a tree with
every city being a children. In case if we decide the root to be A, figure 12.3 showcases how a
tree indicating partial tours can be drawn. We can easily see that even with this trivial case
with seven cities, number of combinations are overwhelming.
At any given point of time, the tour cost so far can be calculated. For example, according
to the figure 12.3, the cost of the tour A-B-C-D is so far= 220+250+150 = 620. If we want to
estimate the total distance of tour A-B-C-D-E-F-G, the cost of remaining part may be
estimated using some assumption. One method to do so is to find out two shortest distances
in a given row for a city yet to be visited and divide it by two. For example if we pick up city
E, two of the shortest distances are 150 and 250 which sums up to 400 dividing by two yields
200. We are assuming, by picking up two shortest values, that the city is connected with
others using nearest neighbours, something we have already explored in module 8. Based on
these estimated values, all tours can be measured as summation of two components, one,
which is already calculated, and other, which is estimated. We can pick up the shortest tour
and when revise the estimate by replacing the estimate of the next level by a correct value.
We may need to refine estimates of each tour connected with that edge. For example if now
we have a revised distance for D-E, we may need to change estimates of both tours A-B-C-D-
E-F-G, A-B-C-D-E-G-F. Similarly, on the other hand, if currently B-D sound least cost, and
out estimation is 200 +150 /2 =175. Now we get the actual value to be 150, we will have to
revise estimation of all tours which starts with A-B-D. This might continue till we get a
complete tour with lowest actual value.
One may argue that we can calculate all tour correct values rather than taking estimates. In
our case of 7 cities, it is actually possible and we do not need to go for branch and bound.
Unfortunately it is not so for a real case of larger number of cities. We cannot have all values
calculated beforehand. We need to proceed with exploring children in this fashion.
Also, we are exploring the cases where the origin of the tour is A, what we will get at the
end is the shortest tour starting from A. We must take all possible cities as root nodes and
apply refinement search on them to find out shortest tours starting from other cities like tours
starting from B, tours starting from C and so on. At the end, we have to pick up the best tour
based on shortest tours that we found originating from all other cities.
This branch and bound helps us picking up shorter paths and avoid longer path, without
using any heuristic. This search is basically a blind search but little better than breadth first
search as we estimate and try going in right direction rather than looking for all options.
Does branch and bound possible to be used where one can use Breadth First? Not
advisable in all cases. Let us take the figure 12.1. We want to find shortest path between two
cities, say A and E. If we use refinement search, the algorithm tend to travel to cities which
are nearer to the originating city, i.e. A. Assume F is nearest to A, the search travels in that
direction, next may be F to D which is shortest and so on. Eventually the search algorithm
realizes that this is a bad path and take the next nearest neighbour but it wastes lot of time if
the cities are situated in a way that there are many nearer cities to the originating city and the
destination city is quite far from all of them. The refinement search tries to look for shortest
path without knowing anything about the direction of the destination city. That is the
problem. A breadth first search probably yields answer faster.
Dijstra’s Algorithm
Dijkstra’s algorithm is a popular algorithms for solving many single-source shortest path
problems having non-
negative edge weight in the graphs i.e., it is to find the shortest distance between two vertices
on a graph. It was
conceived by Dutch computer scientist Edsger W. Dijkstra in 1956.
Algorithm for Dijkstra’s Algorithm:
Mark the source node with a current distance of 0 and the rest with infinity.
Set the non-visited node with the smallest current distance as the current node.
For each neighbor, N of the current node adds the current distance of the adjacent node with
the weight of the
edge connecting 0->1. If it is smaller than the current distance of Node, set it as the new
current distance of N.
Mark the current node 1 as visited.
Go to step 2 if there are any nodes are unvisited.
Dijkstra’s Algorithm will generate the shortest path from Node 0 to all other Nodes in the
graph.
Consider the below graph:
Algorithm A* combines the advantages of two other search algorithms: Dijkstra's algorithm
and Greedy Best-First Search. Like Dijkstra's algorithm, A* ensures that the path found is as
short as possible but does so more efficiently by directing its search through a heuristic
similar to Greedy Best-First Search. A heuristic function, denoted h(n), estimates the cost of
getting from any given node n to the destination node.
1. g(n): the actual cost to get from the initial node to node n. It represents the sum of the
costs of node n outgoing edges.
2. h(n): Heuristic cost (also known as "estimation cost") from node n to destination node
n. This problem-specific heuristic function must be acceptable, meaning it never
overestimates the actual cost of achieving the goal. The evaluation function of node n
is defined as f(n) = g(n) h(n).
Algorithm A* selects the nodes to be explored based on the lowest value of f(n), preferring
the nodes with the lowest estimated total cost to reach the goal. The A* algorithm works:
Key Points:
The heuristic function h(n) is admissible if h(n) is never larger than h*(n) or if h(n) is
always less or equal to the true value.
If A* employs an admissible heuristic and h(goal)=0, then we can argue that A* is
admissible.
If the heuristic function is constantly tuned to be low with respect to the true cost,
i.e. h(n) ≤ h*(n), then you are going to get an optimal solution of 100%
Real-Life Examples:
Case 1:
Let’s suppose, you are going to purchase shoes and shoes have a price of $1000. Before
making the purchase, you estimated that the shoes will be worth $1200, When you went to
the store, the shopkeeper informed you that the shoe’s actual price was $1, 000, which is
less than your estimated value, indicating that you had overestimated their value by $200.
so this is the case of Overestimation.
1200 > 1000
i.e. h(n) ≥ h*(n) ∴ Overestimation
Case 2:
Similar to the last situation, you are planning to buy a pair of shoes. This time, you estimate
the shoe value to be $800. However, when you arrive at the store, the shopkeeper informs
you that the shoes’ true price is $1000, which is higher than your estimate.indicating that
you had understimated their value by $200. In this situation, Underestimation has
occurred.
800 < 1000
i.e. h(n) ≤ h*(n) ∴ Underestimation
Example:
Graph
where X is the start node and Y is the goal node in between these two nodes there are
intermediate nodes A, B and all values which are in the above diagram are actual cost
values means h*(n)
Case 1: Overestimation
Let’s suppose,
H(A)= 60, Estimated values i.e. h(n)]
H(B)= 50
So, using A* equation, f(n) = G(n) + h(n)
by putting values
f(A) = 100 + 60 = 160
f(B) = 100 + 50 = 150
by comparing f(A) & f(B), f(A) > f(B) so choose path of B node and apply A* equation
again
f(Y) = g(Y) + h(Y) [here h(Y) is 0, Goal state]
= 140 + 0 [g(Y)=100+40=140 this is actual cost i.e. h*(B)]
= 140
The least cost to get from X to Y, as shown in the mentioned graph is 130, however, in
Case 1, we took into consideration the expected costs h(n) of A & B, which were 60 & 50,
respectively. As a result,
140 > 130 according to the Overestimation condition h(n) ≥ h*(n), and here, since the
value of node f(A) is bigger than f(Y), we are unable to proceed along a different path
which is from node A.
Case 2: Underestimation
Let’s suppose,
H(A) = 20 [This are estimated values i.e. h(n)]
H(B) = 10
So, using A* equation, f(n) = G(n) + h(n)
by putting values
f(A) = 100 + 20 = 120
f(B) = 100 + 10 = 110, by comparing f(A) & f(B), f(A) > f(B), so choose path of B node and
apply A* equation again
f(Y) = g(Y) + h(Y) [here h(Y) is 0, because it is goal state]
= 140 + 0 [g(Y) = 100 + 40 = 140 this is actual cost i.e. h*(B)]
= 140
Now, notice that f(Y) is the same in both circumstances but, in 2nd case by comparing
the f(A) with f(Y) i.e. 120 < 140 as it means we can go from node A. Therefore A* will go
with f(A), which has a value of 120.
f(Y) = g(Y) + h(Y)
= 130 + 0 [g(Y) = 100 + 30 = 130 this is a= 130 + 0 [g(Y) = 100 + 30 = 130 this is
actual cost of f(A)]
= 130ctual cost of f(A)]
= 130
So, based on all of these calculations, we can say that this is the optimal value.
Iterative Depening A*
IDA* is a variant of depth-first search (DFS) that iteratively deepens its search by
incrementing the cost threshold, which controls the depth of the exploration. Unlike A*,
which explores all possible nodes within a threshold, IDA* uses a heuristic function to
evaluate and prioritize the most promising nodes. This allows it to prune less promising
paths, reducing memory usage while ensuring that the search focuses on optimal routes.
Step-by-Step Process of the IDA* Algorithm
1. Initialization: Set the root node as the current node and compute its f-score.
2. Set Threshold: Initialize a threshold based on the f-score of the starting node.
3. Node Expansion: Expand the current node’s children and calculate their f-scores.
4. Pruning: If the f-score exceeds the threshold, prune the node and store it for future
exploration.
5. Path Return: Once the goal node is found, return the path from the start node to the
goal.
6. Update Threshold: If the goal is not found, increase the threshold based on the
minimum pruned value and repeat the process.
In the below tree, the f score is written inside the nodes means the f score is already
computed and the start node is 2 whereas the goal node is 15. the explored node is colored
green color.
So now we have to go to a given goal by using IDA* algorithm.
Iteration 1
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
Iteration 6
Iteration 6
Dendral was an early expert system developed in the 1960s at Stanford University by Edward
Feigenbaum, Joshua Lederberg, and their colleagues.
It was designed to solve problems in organic chemistry, particularly in the analysis of mass
spectrometry data to identify the structure of organic molecules.
DENDRAL was built to add up a database of the known rules (valence requirements) and
exceptions in organic chemistry that determine the structures of molecules - the data and
knowledge a human chemist might possess and use. Therefore, by definition, it possesses and
utilizes this human knowledge.
Dendral used a knowledge base containing information about chemical structures, reactions,
and spectral data, along with inference rules to reason about possible molecular structures.
The system employed heuristic search strategies to explore the space of possible molecular
structures and evaluate them against the available spectral data.
Here's a simplified example of how Dendral might work:
Problem: Given a mass spectrum of an unknown compound, determine its molecular
structure.
Dendral Steps:
Analyze the mass spectrum to identify peaks corresponding to molecular fragments.
Generate candidate molecular structures consistent with the observed fragment masses and
their relationships.
Apply chemical knowledge and rules to refine the candidate structures and eliminate
inconsistencies.
Evaluate the remaining candidate structures against additional spectral data to determine the
best match.
Dendral demonstrated the feasibility of using expert systems to perform complex analysis
tasks in scientific domains, paving the way for future developments in artificial intelligence
and expert systems.
Both SAINT and Dendral represent pioneering efforts in the field of expert systems,
showcasing the potential of AI to tackle complex problem-solving tasks in specific domains.
Goal Tree
Since one has to traverse all the edges at an AND node, the solution obtained will not be a
path, but a subtree (or a subgraph) in the AND/OR search space. However, one can still use a
depth first search approach, with the modification that at each AND node, more than one
search will be spawned. In the above example, these will be three searches.
The first will search below the node labelled Outing, the second below the node labelled
Movie, and the third below the node Dinner. But since they will search independently, they
will not explore fruitless combinations as done by our first formulation. In general, of course,
an AND/OR search space will be much larger, with many AND and OR levels, and we will
still need to adopt a heuristic approach
Algorithm:
• Starting at the root, traverse the graph along marked paths till the algorithm reaches a set of
unsolved nodes U.
• Pick a node n from U and refine it.
• Propagate the revised estimate of n up via all ancestors.
• If for a node all AND successors along the marked path are marked
• SOLVED, mark it SOLVED as well.
• If a node has OR edges emanating from it, and the cheapest successor is marked SOLVED
then mark the node SOLVED.
• Terminate when the root node is marked SOLVED.
AO* ALGORITHM
Show the progress of AO* Algorithm on the following Synthetic problem given below.
Consider each edge with a cost of 1, and Nodes are labelled with Heuristic values.
Solved nodes are represented by double lined boxes have cost zero.
Rule based System
Rule-based systems, a foundational technology in artificial intelligence (AI), have long
been instrumental in decision-making and problem-solving across various domains. These
systems operate on a set of predefined rules and logic to make decisions, perform tasks, or
derive conclusions. Despite the rise of more advanced AI methodologies, such as machine
learning and neural networks, rule-based systems remain crucial due to their transparency,
ease of use, and interpretability.
XCon stands for expert configure . An expert configurer in artificial intelligence refers to a
specialized AI system designed to automate the process of configuring complex systems
based on specific requirements. This type of system typically encodes expert knowledge in a
domain (like hardware setup, software deployment, or product customization) to generate
solutions that are optimized, compatible, and tailored to customer needs. Here’s an overview
of expert configurers in AI, how they work, and their applications.
A Rule Looks at a Part of a State which Matches a Pattern and Modifies it to Result into
a New State.
• A Rule Associates an Action with a Pattern in the State known as Production.
• Unifying format for heuristic knowledge, business rules, and actions.
• Basis for a Turing complete programming language.
• The user or programmer only states the rules.
• Very popular in the business environment, e.g. lending by banks.
• The programmer only specifies the pattern action association.
• The programmer does not specify when an action should be executed.
• Different from imperative programming.
• Search Strategy
• Explores which rules are applicable, and
• Which one to apply
• User has a choice of strategies
• Working Memory(WM)
• Represents the current state. Contains a set of records or statements, known as working
memory elements (WMEs)
• A model of the short term memory (STM) of the problem solver.
• Each Production or A Rule.
• Represents a move
• Has a name or an identifier
• Has one or more pattern on the left hand side (LHS)
• Has one or more action on the right hand side (RHS)
• A model of the long term memory (LTM) of the problem solver.
• Inference Engine
• Matches patterns in all rules with all WMEs
• Picks one matching rule to fire or execute the actions in the rule
• Repeats the process till some termination criterion
Use Case: Detecting and monitoring neurological conditions like Alzheimer’s disease,
multiple sclerosis (MS), and stroke.
Examples:
o Alzheimer's Prediction: AI models analyzing MRI and PET scans can
identify early markers of Alzheimer’s disease, such as changes in brain
volume or amyloid plaque accumulation. Researchers use deep learning
models to detect subtle structural changes in the brain years before symptoms
appear.
o Stroke Detection: AI-powered platforms like Viz.ai analyze CT angiograms to
quickly identify large vessel occlusions (LVOs), speeding up stroke diagnosis
and enabling faster intervention.
Impact: AI accelerates time-sensitive diagnoses, such as stroke, allowing faster
response times and potentially reducing long-term neurological damage.
Use Case: Segmenting organs and anatomical structures in medical images for
surgical planning and radiation therapy.
Examples:
o Tumor Segmentation: AI-powered segmentation tools can identify tumor
boundaries in MRIs or CT scans. For instance, AI models can segment liver or
brain tumors, aiding surgeons in planning precise interventions and helping
radiologists in accurate dose targeting for radiation therapy.
o 3D Organ Reconstruction: AI models create 3D reconstructions of organs,
which can be particularly useful for complex surgeries. These reconstructions
allow surgeons to "navigate" around critical structures, improving outcomes in
surgeries such as spinal or cardiac procedures.
Impact: AI in organ segmentation ensures higher precision in complex surgeries,
reduces surgical risks, and enhances radiation therapy targeting accuracy.