0% found this document useful (0 votes)
29 views66 pages

AI - Unit 1

Uploaded by

Aarthy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views66 pages

AI - Unit 1

Uploaded by

Aarthy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

AI- ARTIFICIAL INTELLIGENCE

Unit 1: Problems and Search

Prof Aarthy G
REVA University- SoCIT
Email : [email protected]
Unit 1 -Syllabus and Textbook
• Problems and search: What is AI, AI Problems; AI Techniques; Problem Space and Problem
Search techniques; Defining the problem as a state space search, production systems; Problem
characteristics, production system characteristics, Issues in the design of search programs;
Heuristic search techniques, generate-and-test; Hill climbing, BFS, DFS; Problem reduction;
Constraint satisfaction.
• TEXT BOOKS:
o Russell & Norvig, “Artificial Intelligence: A Modern Approach”, Third Edition, Prentice-Hall, 2010.
AI_Russell_Norvig.pdf
o Elaine Rich, Kevin Knight, “Artificial Intelligence”, “, 3rdedition, TataMcgraw Hill, 2009
Kevin Knight, Elaine Rich, B. Nair - Artificial Intelligence (2010, Tata McGraw-Hill Education Pvt. Ltd.) - libgen.lc.pdf
• REFERENCE BOOKS:
o Nils J. Nilsson, Elsevier, “Principles of Artificial Intelligence”, 1980. “Artificial Neural Networks”,
o Krishan Mehrotra, Chilkuri K. Mohan, Sanjay Ranka, “Artificial Neural Networks”, Penram International Publishing,
1997.
o B. Yegananarayana, “Artificial Neural Networks”, PHI, 2001.

Aritificial Intelligence - Prof Aarthy G - [email protected] 2


What is AI?

• Artificial Intelligence (AI) refers to the simulation of human intelligence in machines that are designed
to think and learn like humans.
• AI systems can perform tasks that typically require human intelligence, such as understanding natural
language, recognizing patterns, solving problems, and making decisions.
• AI can be broadly categorized into two types:
• Narrow AI (Weak AI)

• General AI (Strong AI)

Aritificial Intelligence - Prof Aarthy G - [email protected] 3


• Narrow AI (Weak AI): This type of AI is designed to perform a specific task, such as facial
recognition, language translation, or playing a game.
• These systems operate within a limited domain and do not possess general intelligence.
• General AI (Strong AI): This is a more advanced form of AI that can perform any intellectual task
that a human can do.
• It has the ability to understand, learn, and apply knowledge across different domains. However,
this level of AI is still largely theoretical and has not yet been realized.

Aritificial Intelligence - Prof Aarthy G - [email protected] 4


AI Technologies
• AI technologies include machine learning, deep learning, natural language processing, robotics,
and more.
• These technologies enable AI systems to learn from data, adapt to new inputs, and improve their
performance over time.
• AI is widely used in various industries, including healthcare, finance, transportation, and
entertainment.

Aritificial Intelligence - Prof Aarthy G - [email protected] 5


AI Problems
• AI faces several challenges and problems, both technical and ethical. Here are some key issues:
• Here are the key issues related to AI:

1. Bias and Fairness


2. Explainability and Transparency
3. Data Privacy and Security
4. Ethical Concerns
5. Job Displacement
6. Generalization and Robustness
7. Scalability and Computational Resources
8. Legal and Regulatory Issues
9. Human-AI Interaction
10. Sustainability

Aritificial Intelligence - Prof Aarthy G - [email protected] 6


• Bias and Fairness
• Problem: AI systems can inherit biases present in their training data, leading to unfair outcomes.
For example, biased algorithms might discriminate against certain groups in hiring processes, loan
approvals, or law enforcement.
• Impact: This can perpetuate and even amplify societal inequalities, leading to a lack of trust in AI
systems.
• Explainability and Transparency
• Problem: Many AI models, especially deep learning systems, operate as "black boxes," meaning
their decision-making processes are not easily understandable.
• Impact: This lack of transparency makes it difficult to trust and verify AI decisions, especially in
critical areas like healthcare, finance, and legal systems.

Aritificial Intelligence - Prof Aarthy G - [email protected] 7


• Data Privacy and Security
• Problem: AI systems often require large amounts of data, raising concerns about data privacy and
the security of personal information.
• Impact: Misuse or breaches of data can lead to privacy violations, identity theft, and other
security issues.
• Ethical Concerns
• Problem: The deployment of AI in areas such as surveillance, autonomous weapons, and
decision-making can raise ethical questions about the appropriate use of AI.
• Impact: Misuse of AI can lead to human rights violations, loss of jobs, and other societal impacts.

Aritificial Intelligence - Prof Aarthy G - [email protected] 8


• Job Displacement
• Problem: Automation and AI-driven systems can replace jobs, particularly in industries
like manufacturing, customer service, and transportation.
• Impact: This can lead to significant economic and social challenges, including
unemployment and the need for workforce reskilling.
• Generalization and Robustness
• Problem: AI models often struggle to generalize beyond the specific data they were
trained on and can perform poorly when faced with new, unseen data.
• Impact: This limits the reliability of AI systems in dynamic real-world environments.

Aritificial Intelligence - Prof Aarthy G - [email protected] 9


• Scalability and Computational Resources
• Problem: Developing and deploying AI models, especially large-scale deep learning models,
requires significant computational resources and energy.
• Impact: This can limit the accessibility of AI technologies and raise environmental concerns due to
the high energy consumption of data centers.
• Legal and Regulatory Issues
• Problem: The rapid advancement of AI has outpaced the development of laws and regulations,
leading to uncertainty about liability, accountability, and compliance.
• Impact: This can create challenges in enforcing regulations and ensuring that AI systems operate
within legal boundaries.

Aritificial Intelligence - Prof Aarthy G - [email protected] 10


AI Techniques
1. Machine Learning
2. Deep Learning
3. Natural Language Processing (NLP)
4. Computer Vision
5. Reinforcement Learning
6. Supervised Learning
7. Unsupervised Learning
8. Semi-Supervised Learning
9. Transfer Learning
10. Neural Networks
11. Genetic Algorithms
12. Expert Systems
13. Bayesian Networks
14. Fuzzy Logic
15. Support Vector Machines (SVM)

Aritificial Intelligence - Prof Aarthy G - [email protected] 11


AI Problem Space
• In AI, the problem space refers to the environment in which an AI system operates, including all
possible states, actions, and outcomes related to solving a particular problem.
• Key concepts in the problem space of AI include:
• State Space
• Represents all possible configurations or states that can exist in the problem environment.
• Initial State
• The starting point or condition from which the AI system begins to solve the problem.
• Goal State
• The desired outcome or solution that the AI system aims to achieve.
• Operators (Actions)
• The set of possible actions or moves that the AI system can take to transition from one state to another.

Aritificial Intelligence - Prof Aarthy G - [email protected] 12


• Path
• A sequence of states and actions leading from the initial state to the goal state.
• Search Space
• The subset of the state space that is explored by the AI system in its attempt to find the
solution.
• Cost Function
• A metric used to evaluate the cost or effort associated with transitioning between states,
often used in pathfinding and optimization problems.
• Heuristic Function
• A technique or rule-of-thumb used to guide the search process, often used to estimate the
cost from a current state to the goal state

Aritificial Intelligence - Prof Aarthy G - [email protected] 13


• Solution
• A sequence of actions or a path that successfully leads from the initial state to the goal state
within the problem space.
• Complexity
• The difficulty of exploring the problem space, often determined by the number of possible
states and actions.

Aritificial Intelligence - Prof Aarthy G - [email protected] 14


AI Search Techniques

Aritificial Intelligence - Prof Aarthy G - [email protected] 15


Informed Search
• Algorithms have information on the goal state which helps in more efficient searching
• This information is obtained by a function that estimates how close a state is to the goal state.
• Informed search in AI is a type of search algorithm that uses additional information to guide the
search process, allowing for more efficient problem-solving compared to uninformed search
algorithms.
• This information can be in the form of heuristics, estimates of cost, or other relevant data to
prioritize which states to expand and explore.

Aritificial Intelligence - Prof Aarthy G - [email protected] 16


Features of Informed Search
• Use of Heuristics – informed search algorithms use heuristics, or additional information, to guide
the search process and prioritize which nodes to expand.
• More efficient – informed search algorithms are designed to be more efficient than uninformed
search algorithms, such as breadth-first search or depth-first search, by avoiding the exploration
of unlikely paths and focusing on more promising ones.
• Goal-directed – informed search algorithms are goal-directed, meaning that they are designed to
find a solution to a specific problem.
• Cost-based – informed search algorithms often use cost-based estimates to evaluate nodes, such
as the estimated cost to reach the goal or the cost of a particular path.
• Prioritization – informed search algorithms prioritize which nodes to expand based on the
additional information available, often leading to more efficient problem-solving.
• Optimality – informed search algorithms may guarantee an optimal solution if the heuristics used
are admissible (never overestimating the actual cost) and consistent (the estimated cost is a
lower bound on the actual cost).

Aritificial Intelligence - Prof Aarthy G - [email protected] 17


Uninfomred Search
• Algorithms have no additional information on the goal node other than the one provided in the
problem definition.
• The plans to reach the goal state from the start state differ only by the order and length of
actions.
• Uninformed search in AI refers to a type of search algorithm that does not use additional
information to guide the search process.
• Instead, these algorithms explore the search space in a systematic, but blind, manner without
considering the cost of reaching the goal or the likelihood of finding a solution.
• Not guaranteed to find optimal solution – uninformed search algorithms do not guarantee an
optimal solution, as they do not consider the cost of reaching the goal or other relevant
information.

Aritificial Intelligence - Prof Aarthy G - [email protected] 18


Features of Uninformed Search

• Systematic exploration – uninformed search algorithms explore the search space systematically,
either by expanding all children of a node (e.g. BFS) or by exploring as deep as possible in a single
path before backtracking (e.g. DFS).
• No heuristics – uninformed search algorithms do not use additional information, such as
heuristics or cost estimates, to guide the search process.
• Blind search – uninformed search algorithms do not consider the cost of reaching the goal or the
likelihood of finding a solution, leading to a blind search process.
• Simple to implement – uninformed search algorithms are often simple to implement and
understand, making them a good starting point for more complex algorithms.
• Inefficient in complex problems – uninformed search algorithms can be inefficient in complex
problems with large search spaces, leading to an exponential increase in the number of states
explored.

Aritificial Intelligence - Prof Aarthy G - [email protected] 19


Defining the problem as a state space search
• Defining a problem as a state space search involves representing it in terms of states, actions, and
transitions between states.
• This approach is widely used in artificial intelligence (AI) for problem-solving, especially in fields
like search algorithms and automated planning.

Aritificial Intelligence - Prof Aarthy G - [email protected] 20


• State:
• A state represents a specific configuration or situation in which the problem can be. In a
puzzle, for example, each arrangement of pieces constitutes a different state.
• Initial State:
• The starting point of the problem from which the search begins.
• Goal State:
• The desired outcome or solution that the search aims to reach.
• Actions:
• Actions are the possible moves or operations that can be performed to transition from one
state to another. Each action has preconditions that must be satisfied in the current state.
• Transition:
• The process of moving from one state to another through the application of an action. This
defines the relationships between states.

Aritificial Intelligence - Prof Aarthy G - [email protected] 21


• State Space:
• The complete set of all possible states and transitions, forming a graph or tree structure. Each
node represents a state, and edges represent actions leading to new states.
• Search Algorithms:
• Various algorithms can be used to explore the state space and find a solution. Common
search strategies include:
• Breadth-First Search (BFS): Explores all nodes at the present depth before moving on to
nodes at the next depth level.
• Depth-First Search (DFS): Explores as far as possible along a branch before backtracking.
• A*: An informed search algorithm that uses heuristics to estimate the cost of reaching
the goal.

Aritificial Intelligence - Prof Aarthy G - [email protected] 22


Example Tic – Tac - Toe
• State: Each configuration of the 3x3 board (e.g., filled with X's, O's,
and empty spaces).
• Initial State: All cells are empty.
• Goal State:
o Win for Player X: Three X's in a row, column, or diagonal.
o Win for Player O: Three O's in a row, column, or diagonal.
o Draw: No empty spaces remain and no player has three in a row.
• Actions: Placing an X or an O in any of the empty cells.
• Transition: Each move changes the configuration of the board.

Aritificial Intelligence - Prof Aarthy G - [email protected] 23


• State Space: All possible configurations of the board resulting from the actions taken by both
players.
o 3^9=19,683, the number 3 represents the number of possible values for each position on the
tic-tac-toe board. Specifically, each cell in the 3x3 grid can be in one of three states:
o Empty: The cell is not occupied by either player.
o X: The cell is occupied by Player X.
o O: The cell is occupied by Player O.

• Search Algorithm: The Minimax algorithm can be used to evaluate potential moves and
determine the best strategy for each player, aiming to maximize their chances of winning while
minimizing the opponent's chances.

Aritificial Intelligence - Prof Aarthy G - [email protected] 24


Production System in AI
• Artificial intelligence and automation have become an integral part of our daily lives.
• Every automation machinery equipped with certain algorithms needs some set of rules for their
proper functioning and execution of different tasks.
• The production system in AI is the collection of those rules which work on different behaviors and
settings.
• These production systems help set up the AI algorithms and look into the proper functioning of
the AI software.

Aritificial Intelligence - Prof Aarthy G - [email protected] 25


• A production system in AI, also known as a production rule system, is a framework that can be
implemented to create various software programs for executing different tasks.
• It is a unique and advanced kind of intellectual design that may be used to simulate human
problem-solving abilities and build search algorithms for different programs.
• The AI production system retains tiny quanta referred to as productions, which help in
understanding the process of problem-solving abilities.
• The rule and action are two fundamental elements in each production system.
• Declarative statements are used to encode the data in production systems.
• Knowledge representation is used to develop a production system that executes AI
applications.

Aritificial Intelligence - Prof Aarthy G - [email protected] 26


• A production system in AI provides automation based on a particular set of rules to exhibit
particular traits while participating in different situations.
• A production system, also known as a rule-based system, is a type of artificial intelligence
software designed to mimic the problem-solving ability of human experts.
• It consists of a knowledge base of rules and a inference engine that applies those rules to solve
problems or make decisions within a specific domain.

Aritificial Intelligence - Prof Aarthy G - [email protected] 27


Components of Production System

Aritificial Intelligence - Prof Aarthy G - [email protected] 28


• Global Database / Working Memory: Also called the global database, this is a temporary storage
area that holds facts about the current state of the problem or situation being analyzed by the
system.
• Production Rules / Knowledge Base: This is a collection of rules that encode domain-specific
knowledge.
• Rules typically take the form of “IF (condition) THEN (action)”.
• For example, an expert system for medical diagnosis might have a rule like
• “IF the patient has a fever AND a rash, THEN there is a possibility of measles.”
• Control System / Inference Engine: This is the control mechanism that iteratively evaluates the
rules from the knowledge base against the contents of the working memory.
• It determines which rules are applicable and fires (executes) them, updating the working
memory with new facts derived from applying the rules.

Aritificial Intelligence - Prof Aarthy G - [email protected] 29


How a Production System Works

• The working memory is initialized with the known facts about the problem.
• The inference engine matches the rules in the knowledge base against the facts in working
memory.
• Rules whose conditions are satisfied are placed on the agenda.
• A conflict resolution strategy (e.g. priority, recency, etc.) is used to select one rule from the
agenda to fire.
• The selected rule is fired, and its actions update the working memory.
• The cycle repeats from step 2 until a solution is found or no more rules can be fired.

Aritificial Intelligence - Prof Aarthy G - [email protected] 30


Example:

• Let’s create a simple production system for identifying types of geometric shapes based on their
properties:
• Knowledge Base Rules:
• IF the shape has 3 sides AND 3 angles, THEN it is a triangle
• IF the shape has 4 equal sides AND 4 right angles, THEN it is a square
• IF the shape has 4 sides AND opposite sides are parallel, THEN it is a parallelogram.
• Working Memory (initial facts):
• The shape has 3 sides
• The shape has 3 angles
• The inference engine would match the first rule, place it on the agenda, and fire it – updating
working memory with the fact that the shape is a triangle.

Aritificial Intelligence - Prof Aarthy G - [email protected] 31


Characteristics of Production System in AI

Aritificial Intelligence - Prof Aarthy G - [email protected] 32


• Simplicity: Production Systems offer a straightforward way to encode and execute rules, making
them accessible for developers and domain experts.
• Modularity: These systems are composed of modular components, allowing for the addition,
removal, or modification of rules without disrupting the entire system.
• This modularity enhances flexibility and ease of maintenance.
• Modifiability: AI Production Systems are highly adaptable.
• Rules can be updated or replaced without extensive reengineering, ensuring the system
remains up-to-date and aligned with evolving requirements.
• Knowledge-intensive: They excel in handling knowledge-rich tasks, relying on a comprehensive
global database.
• Adaptability: AI Production Systems can dynamically adapt to new data and scenarios.
• This adaptability allows them to continuously improve.

Aritificial Intelligence - Prof Aarthy G - [email protected] 33


• Can production systems be described by a set of characteristics? And how can they be easily
implemented?
• What relationships are there between the problem types and the types of production systems
well suited for solving the problems?
To answer these questions, first consider the following definitions of classes of production systems:
1. A monotonic production system is a production system in which the application of a
rule never prevents the later application of another rule that could also have been applied at the
time the first rule was selected.
2. A non-monotonic production system is one in which this is not true.
3. A partially communicative production system is a production system with the property
that if the application of a particular sequence of rules transforms state P into state Q, then any
combination of those rules that is allowable also transforms state P into state Q.
4. A commutative production system is a production system that is both monotonic and
partially commutative.

Aritificial Intelligence - Prof Aarthy G - [email protected] 34


Characteristics of AI Problems

• Problems in Artificial Intelligence (AI) come in different forms, each with its own set of challenges
and potential for innovation.
• From image recognition to natural language processing, AI problems exhibit distinct
characteristics that shape the strategies and techniques used to tackle them effectively.

Aritificial Intelligence - Prof Aarthy G - [email protected] 35


• Learning and adaptation:
• AI systems should be capable of learning from data or experiences and adapting their
behavior accordingly.
• This enables them to improve performance over time and handle new situations more
effectively.
• Complexity:
• AI problems often involve dealing with complex systems or large amounts of data.
• AI systems must be able to handle this complexity efficiently to produce meaningful results.
• Uncertainty:
• AI systems frequently operate in environments where outcomes are uncertain or incomplete
information is available.
• They must be equipped to make decisions or predictions under such conditions.
• Dynamism:
• Environments in which AI systems operate can change over time.
• These changes may occur unpredictably or according to specific rules, requiring AI systems to
continually adjust their strategies or models.

Aritificial Intelligence - Prof Aarthy G - [email protected] 36


• Interactivity:
• Many AI applications involve interaction with users or other agents.
• Effective AI systems should be able to perceive, interpret, and respond to these interactions
in a meaningful way.
• Context dependence:
• The behavior or performance of AI systems may depend on the context in which they
operate.
• Understanding and appropriately responding to different contexts is essential for achieving
desired outcomes.
• Multi-disciplinary:
• AI problems often require knowledge and techniques from multiple disciplines, including
computer science, mathematics, statistics, psychology, and more.
• Integrating insights from these diverse fields is necessary for developing effective AI
solutions.
• Goal-oriented Design:
• AI systems are typically designed to achieve specific objectives or goals.
• Designing AI systems with clear objectives in mind helps guide the development process and
ensures that the resulting systems are focused on achieving meaningful outcomes.

Aritificial Intelligence - Prof Aarthy G - [email protected] 37


Issues in the Design of Search Programs
• Each search process can be considered to be a tree traversal.
• The object of the search is to find a path from the initial state to a goal state using a tree.
• The number of nodes generated might be huge; and in practice many of the nodes would not be
needed.
• The secret of a good search routine is to generate only those nodes that are likely to be useful,
rather than having a precise tree.
• The rules are used to represent the tree implicitly and only to create nodes explicitly if they are
actually to be of use.

Aritificial Intelligence - Prof Aarthy G - [email protected] 38


• The following issues arise when searching:
• The tree can be searched forward from the initial node to the goal state or backwards from
the goal state to the initial state.
• To select applicable rules, it is critical to have an efficient procedure for matching rules
against states.
• How to represent each node of the search process? This is the knowledge representation
problem or the frame problem.
• In games, an array suffices; in other problems, more complex data structures are needed.

Aritificial Intelligence - Prof Aarthy G - [email protected] 39


• Check duplicate nodes
• Observe all nodes that are already generated, if a new node is present. If it exists add it to the
graph.
• If it already exists, then
• Set the node that is being expanded to the point to the already existing node corresponding
to its successor rather than to the new one. The new one can be thrown away.
• If the best or shortest path is being determined, check to see if this path is better or worse
than the old one. If worse, do nothing.
• Better save the new path and work the change in length through the chain of successor
nodes if necessary.

Aritificial Intelligence - Prof Aarthy G - [email protected] 40


Example: Tic-Tac-Toe
The sequence of states formed by possible moves is called a search tree. Each level of the tree is called a ply.

Aritificial Intelligence - Prof Aarthy G - [email protected] 41


Solving problems using search
Given an informal description of the problem,
Construct a formal description as a state space:
• Define a data structure to represent the state.
• Make a representation for the initial state from the given data.
• Write programs to represent operators that change a given state representation to a new
state representation.
• Write a program to detect terminal states.
Choose an appropriate search technique:
• How large is the search space?
• Write programs to represent operators that change a given state representation to a new
state How well structured is the domain?
• What knowledge about the domain can be used to guide the search?

Aritificial Intelligence - Prof Aarthy G - [email protected] 42


Heuristic search techniques
• Heuristic search techniques are strategies used in AI and computer science to solve problems
more efficiently by making educated guesses or applying rules of thumb (heuristics) to guide the
search process.
• These techniques are particularly useful in scenarios where the search space is large, and an
exhaustive search would be computationally infeasible.
• Heuristic search helps to find satisfactory solutions more quickly, even if those solutions are not
guaranteed to be optimal.
• They use domain-specific knowledge to guide the search, making them more efficient than
exhaustive search methods.
• However, the effectiveness of these techniques depends heavily on the choice of heuristic and
the nature of the problem.

Aritificial Intelligence - Prof Aarthy G - [email protected] 43


Aritificial Intelligence - Prof Aarthy G - [email protected] 44
Greedy Best-First Search

• Overview: This technique expands the node that appears to be closest to the goal, according to a
heuristic function h(n).
• Heuristic: h(n)estimates the cost to reach the goal from node n.
• Pros: Fast and often finds a good solution quickly.
• Cons: It can get stuck in local optima or fail to find the optimal solution because it doesn't
consider the cost already incurred (path cost).
• Example: Finding the shortest path in a maze where the heuristic is the straight-line distance to
the goal.

Aritificial Intelligence - Prof Aarthy G - [email protected] 45


• In a pathfinding problem like navigating a grid, if the goal is at position (10, 10) and the current
node is at (5, 5), a common heuristic might be the Euclidean distance:
• For this specific case, if n is at (5, 5) and the goal is at (10, 10):

2 2 ͌͌ 7.07
• H(n) = 𝑥𝑔𝑜𝑎𝑙 − 𝑥𝑛 + 𝑦𝑔𝑜𝑎𝑙 − 𝑦𝑛
• Here, h(n) would be 7.07, guiding the algorithm to prefer paths that seem closest to the goal
according to this distance measure

Aritificial Intelligence - Prof Aarthy G - [email protected] 46


A* Search
• Overview: A* combines the advantages of Dijkstra’s Algorithm and Greedy Best-First Search.
• It uses both the cost to reach the node g(n) and the estimated cost to reach the goal h(n).
• Evaluation Function: f(n)=g(n)+h(n)
• Pros: It’s optimal and complete if the heuristic h(n) never overestimates the actual cost and
consistent.
• Cons: Can be slow or require a lot of memory if the search space is large.
• Example: Pathfinding in games or GPS systems where g(n) is the distance from the start and h(n)
is the estimated distance to the goal.

Aritificial Intelligence - Prof Aarthy G - [email protected] 47


Generate and Test 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.
• In this technique, all the solutions are generated and tested for the
best solution.
• It ensures that the best solution is checked against all possible
generated solutions.
• It is also known as British Museum Search Algorithm.

Aritificial Intelligence - Prof Aarthy G - [email protected] 48


• The evaluation is carried out by the heuristic function as all the solutions are generated
systematically in generate and test algorithm but if there are some paths which are most unlikely
to lead us to result then they are not considered.
• The heuristic does this by ranking all the alternatives and is often effective in doing so.
• Systematic Generate and Test may prove to be ineffective while solving complex problems.
• Algorithm
• Generate a possible solution. For example, generating a particular point in the problem space or generating a path
for a start state.
• Test to see if this is a actual solution by comparing the chosen point or the endpoint of the chosen path to the set of
acceptable goal states
• If a solution is found, quit. Otherwise go to Step 1

Aritificial Intelligence - Prof Aarthy G - [email protected] 49


Example – Travelling Salesman Problem
• A salesman has a list of cities, each of which he must
visit exactly once. There are direct roads between
each pair of cities on the list. Find the route the
salesman should follow for the shortest possible
round trip that both starts and finishes at any one of
the cities.
• Traveler needs to visit n cities.
• Know the distance between each pair of cities.
• Want to know the shortest route that visits all
the cities once.

Aritificial Intelligence - Prof Aarthy G - [email protected] 50


Starting at A: Starting at B:
• A -> B -> C -> D -> A: • B -> A -> C -> D -> B:
• Total Distance = 6 + 3 + 4 + 5 = 18 • Total Distance = 6 + 1 + 4 + 2 = 13
• A -> B -> D -> C -> A: • B -> A -> D -> C -> B:
• Total Distance = 6 + 2 + 4 + 1 = 13 • Total Distance = 6 + 5 + 4 + 3 = 18
• A -> C -> B -> D -> A: • B -> C -> A -> D -> B:
• Total Distance = 1 + 3 + 2 + 5 = 11 • Total Distance = 3 + 1 + 5 + 2 = 11
• A -> C -> D -> B -> A: • B -> C -> D -> A -> B:
• Total Distance = 1 + 4 + 2 + 6 = 13 • Total Distance = 3 + 4 + 5 + 6 = 18
• A -> D -> B -> C -> A: • B -> D -> A -> C -> B:
• Total Distance = 5 + 2 + 3 + 1 = 11 • Total Distance = 2 + 5 + 1 + 3 = 11
• A -> D -> C -> B -> A: • B -> D -> C -> A -> B:
• Total Distance = 5 + 4 + 3 + 6 = 18 • Total Distance = 2 + 4 + 1 + 6 = 13

Aritificial Intelligence - Prof Aarthy G - [email protected] 51


Starting at C: Starting at D:
• C -> A -> B -> D -> C: • D -> A -> B -> C -> D:
• Total Distance = 1 + 6 + 2 + 4 = 13 • Total Distance = 5 + 6 + 3 + 4 = 18
• C -> A -> D -> B -> C: • D -> A -> C -> B -> D:
• Total Distance = 1 + 5 + 2 + 3 = 11 • Total Distance = 5 + 1 + 3 + 2 = 11
• C -> B -> A -> D -> C: • D -> B -> A -> C -> D:
• Total Distance = 2 + 6 + 1 + 4 = 13
• Total Distance = 3 + 6 + 5 + 4 = 18
• D -> B -> C -> A -> D:
• C -> B -> D -> A -> C:
• Total Distance = 2 + 3 + 1 + 5 = 11
• Total Distance = 3 + 2 + 5 + 1 = 11 • D -> C -> A -> B -> D:
• C -> D -> A -> B -> C: • Total Distance = 4 + 1 + 6 + 2 = 13
• Total Distance = 4 + 5 + 6 + 3 = 18 • D -> C -> B -> A -> D:
• C -> D -> B -> A -> C: • Total Distance = 4 + 3 + 6 + 5 = 18
• Total Distance = 4 + 2 + 6 + 1 = 13

Aritificial Intelligence - Prof Aarthy G - [email protected] 52


• For each starting node, the best routes (with the shortest total distance) are:
• Starting at A: A -> C -> B -> D -> A or A -> D -> B -> C -> A with a distance of 11.

• Starting at B: B -> C -> A -> D -> B or B -> D -> A -> C -> B with a distance of 11.

• Starting at C: C -> A -> D -> B -> C or C -> B -> D -> A -> C with a distance of 11.

• Starting at D: D -> A -> C -> B -> D or D -> B -> C -> A -> D with a distance of 11.

• So, no matter which node you start at, the shortest possible route that visits all
cities and returns to the starting city has a total distance of 11.

Aritificial Intelligence - Prof Aarthy G - [email protected] 53


Hill Climbing
• Overview: This technique starts with an arbitrary solution and iteratively makes small changes to
improve it, moving uphill in the solution space.
• Hill Climbing is a search algorithm used in artificial intelligence (AI) for finding optimal or near-
optimal solutions to a problem.
• It is particularly useful for problems where the goal is to find the maximum or minimum value of a
function.
• Variants:
• Simple Hill Climbing: Always moves to the neighbor with the highest value.
• Steepest-Ascent Hill Climbing: Considers all neighbors and moves to the one with the highest
improvement.
• Pros: Simple and memory-efficient.
• Cons: Can get stuck in local maxima, plateaus, or ridges.

Aritificial Intelligence - Prof Aarthy G - [email protected] 54


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.
Current state: It is a state in a landscape diagram where an
agent is currently present.
Flat local maximum: It is a flat space in the landscape
where all the neighbor states of current states have the
same value.
Shoulder: It is a plateau region which has an uphill edge.

Aritificial Intelligence - Prof Aarthy G - [email protected] 55


N Queen Problem
• The N Queen is the problem of placing N chess queens on an N×N chessboard so that no two
queens attack each other.
• Input: N = 8

• Output:
00000010
01000000
00000100
00100000
10000000
00010000
00000001
00001000

Aritificial Intelligence - Prof Aarthy G - [email protected] 56


• In the context of the N-Queen problem, solving it using hill climbing with random neighbors
involves navigating through different states of the problem, where each state represents a
possible configuration of the queens on the chessboard.
• Hill climbing attempts to improve the current state by moving to a neighboring state that has a
lower "cost" (fewer queens attacking each other).
• State: A state in the hill climbing algorithm is a specific arrangement of N queens on an N×N times
N×N chessboard.
• The state is represented as a 1D array where each index represents a row, and the value at that
index represents the column in which the queen is placed.
• Cost: The cost of a state is the number of pairs of queens that are attacking each other.
• The goal is to minimize this cost, with a cost of zero indicating a solution to the N-Queen problem
(i.e., no queens are attacking each other).

Aritificial Intelligence - Prof Aarthy G - [email protected] 57


Steps
• Start with a random configuration:
• Generate an initial board configuration where N queens are placed on the board. Typically,
one queen is placed in each row, in a random column.
• Evaluate the current configuration:
• Calculate the number of conflicts or attacks between queens. This is the cost of the current
configuration. A conflict occurs if two queens share the same row, column, or diagonal.
• Find neighbors:
• A neighbor is generated by slightly altering the current configuration. In this case, it usually
means moving a queen within its row to another column.
• Select the best neighbor:
• From all possible neighbors, select the one with the lowest number of conflicts. If the best
neighbor has a lower cost than the current configuration, move to that neighbor.
• Repeat until a solution is found:
• Continue this process until a configuration is reached where there are no conflicts, meaning a
solution is found. If no improvement is possible, hill climbing can get stuck in a local
minimum.

Aritificial Intelligence - Prof Aarthy G - [email protected] 58


Q___
__Q_
_Q__
___Q
• Evaluate: Count the number of attacking pairs (on the same row, column, or diagonal).
• Generate neighbors: Move one queen within its row, and compute the new configuration’s cost.
• Move to the best neighbor and repeat.
• Challenges:
• Local maxima: The algorithm can get stuck in local maxima or plateaus where no neighbor
has a better evaluation than the current state.
• Plateaus: A large flat area of the search space where all neighbors have the same evaluation.

Aritificial Intelligence - Prof Aarthy G - [email protected] 59


• A local maximum happens when the hill-climbing algorithm reaches a board configuration where
no neighboring configuration improves the solution (i.e., reduces the number of conflicts
between queens), but the current board is not a solution (i.e., it still has queens attacking each
other).
Q___
__Q_
_Q__
___Q
• In this configuration, there are conflicts: Queen in row 1 and Queen in row 3 are attacking
diagonally.
• Queen in row 2 and Queen in row 4 are attacking diagonally.
• The algorithm checks for neighbors, meaning it moves one queen at a time within its row to see if
it can reduce the number of conflicts.
• For example, it might try moving the queen in row 1 to another column

Aritificial Intelligence - Prof Aarthy G - [email protected] 60


_Q__
__Q_
_Q__
___Q
• After checking all possible neighbors, the algorithm finds that every move results in either the
same or more conflicts.
• This means the current state is a local maximum: there are no better moves, but it’s not a
solution.

Aritificial Intelligence - Prof Aarthy G - [email protected] 61


• A plateau is when the algorithm finds itself in a part of the search space where all neighboring
configurations have the same evaluation (same number of conflicts between queens), giving the
algorithm no direction to move in.
_Q__
Q___
___Q
__Q_

• The algorithm evaluates this configuration and finds 2 conflicts:


• The queen in row 1 and queen in row 2 are attacking diagonally.
• The queen in row 3 and queen in row 4 are attacking diagonally

Aritificial Intelligence - Prof Aarthy G - [email protected] 62


Q___
Q___
___Q
__Q_
• Moving the queen in row 1 to column 1:
• Still 2 conflicts: the queens in row 1 and row 2 are attacking each other, and so are the
queens in row 3 and row 4.
• Moving the queen in row 1 to column 3:
• Still 2 conflicts: queen in row 1 and queen in row 4 are attacking diagonally, and so are
queens in row 3 and row 4.
• Every possible move leads to the same number of conflicts (2 conflicts), so the algorithm is on a
plateau.

Aritificial Intelligence - Prof Aarthy G - [email protected] 63


Problem Reduction in AI
• Problem reduction in AI refers to breaking down a complex problem into smaller, simpler sub
problems that can be solved individually.
• The idea is to reduce a difficult problem into a set of easier ones, and then combine the solutions
to solve the original problem.
• This method is widely used in AI for problem-solving, especially in areas like search, planning, and
decision-making.
• Decomposition
• Solve Sub problems
• Combine Solutions

Aritificial Intelligence - Prof Aarthy G - [email protected] 64


Constraint Satisfaction in AI
• Constraint Satisfaction Problems (CSPs) are a class of problems where the goal is to find a solution
that satisfies a set of constraints.
• In a CSP, we are typically given:
• Variables: A set of variables, each with a domain of possible values.
• Constraints: A set of constraints that specify allowable combinations of values for subsets of
variables.
• Example
• Variables: Each queen's position on the chessboard.
• Domains: The columns of the chessboard, since one queen is placed per row.
• Constraints: No two queens can be in the same row, column, or diagonal. The goal is to find
an arrangement where all constraints are satisfied.

Aritificial Intelligence - Prof Aarthy G - [email protected] 65


Flipped Class - Activity
• BFS
• DFS

Aritificial Intelligence - Prof Aarthy G - [email protected] 66

You might also like