Ai Unit 1.1
Ai Unit 1.1
It is a branch of Computer Science that pursues creating the computers or machines as intelligent as human
beings.
It is the science and engineering of making intelligent machines, especially intelligent computer programs.
It is related to the similar task of using computers to understand human intelligence, but AI does not have to
confine itself to methods that are biologically observable
Definition: Artificial Intelligence is the study of how to make computers do things, which, at the moment,
people do better.
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 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.
It has gained prominence recently due, in part, to big data, or the increase in speed, size and variety of data
businesses are now collecting. AI can perform tasks such as identifying patterns in the data more efficiently
than humans, enabling businesses to gain more insight out of their data.
From a business perspective AI is a set of very powerful tools, and methodologies for using those tools to
solve business problems.
From a programming perspective, AI includes the study of symbolic programming, problem solving, and
search.
AI Vocabulary
Intelligence relates to tasks involving higher mental processes, e.g. creativity, solving problems, pattern
recognition, classification, learning, induction, deduction, building analogies, optimization, language
processing, knowledge and many more. Intelligence is the computational part of the ability to achieve goals.
Intelligent behaviour is depicted by perceiving one’s environment, acting in complex environments, learning
and understanding from experience, reasoning to solve problems and discover hidden knowledge, applying
knowledge successfully in new situations, thinking abstractly, using analogies, communicating with others
and more.
Science based goals of AI pertain to developing concepts, mechanisms and understanding biological
intelligent behaviour. The emphasis is on understanding intelligent behaviour.
Engineering based goals of AI relate to developing concepts, theory and practice of building intelligent
machines. The emphasis is on system building.
AI Techniques depict how we represent, manipulate and reason with knowledge in order to solve problems.
Knowledge is a collection of ‘facts’. To manipulate these facts by a program, a suitable representation is
required. A good representation facilitates problem solving.
Learning means that programs learn from what facts or behaviour can represent. Learning denotes changes
in the systems that are adaptive in other words, it enables the system to do the same task(s) more efficiently
next time.
Applications of AI refers to problem solving, search and control strategies, speech recognition, natural
language understanding, computer vision, expert systems, etc.
Problems of AI:
Intelligence does not imply perfect understanding; every intelligent being has limited perception, memory and
computation. Many points on the spectrum of intelligence versus cost are viable, from insects to humans. AI
seeks to understand the computations required from intelligent behaviour and to produce computer systems
that exhibit intelligence. Aspects of intelligence studied by AI include perception, communicational using
human languages, reasoning, planning, learning and memory.
The following questions are to be considered before we can step forward:
1. What are the underlying assumptions about intelligence?
2. What kinds of techniques will be useful for solving AI problems?
3. At what level human intelligence can be modelled?
4. When will it be realized when an intelligent program has been built?
Branches of AI:
A list of branches of AI is given below. However some branches are surely missing, because no one has
identified them yet. Some of these may be regarded as concepts or topics rather than full branches.
Logical AI — In general the facts of the specific situation in which it must act, and its goals are all represented
by sentences of some mathematical logical language. The program decides what to do by inferring that certain
actions are appropriate for achieving its goals.
Search — Artificial Intelligence programs often examine large numbers of possibilities – for example, moves
in a chess game and inferences by a theorem proving program. Discoveries are frequently made about how to
do this more efficiently in various domains.
Pattern Recognition — When a program makes observations of some kind, it is often planned to compare
what it sees with a pattern. For example, a vision program may try to match a pattern of eyes and a nose in a
scene in order to find a face. More complex patterns are like a natural language text, a chess position or in the
history of some event. These more complex patterns require quite different methods than do the simple patterns
that have been studied the most.
Representation — Usually languages of mathematical logic are used to represent the facts about the world.
Inference — Others can be inferred from some facts. Mathematical logical deduction is sufficient for some
purposes, but new methods of non-monotonic inference have been added to the logic since the 1970s. The
simplest kind of non-monotonic reasoning is default reasoning in which a conclusion is to be inferred by
default. But the conclusion can be withdrawn if there is evidence to the divergent. For example, when we hear
of a bird, we infer that it can fly, but this conclusion can be reversed when we hear that it is a penguin. It is
the possibility that a conclusion may have to be withdrawn that constitutes the non-monotonic character of the
reasoning. Normal logical reasoning is monotonic, in that the set of conclusions can be drawn from a set of
premises, i.e. monotonic increasing function of the premises. Circumscription is another form of non-
monotonic reasoning.
Common sense knowledge and Reasoning — This is the area in which AI is farthest from the human level,
in spite of the fact that it has been an active research area since the 1950s. While there has been considerable
progress in developing systems of non-monotonic reasoning and theories of action, yet more new ideas are
needed.
Learning from experience — There are some rules expressed in logic for learning. Programs can only learn
what facts or behaviour their formalisms can represent, and unfortunately learning systems are almost all based
on very limited abilities to represent information.
Planning — Planning starts with general facts about the world (especially facts about the effects of actions),
facts about the particular situation and a statement of a goal. From these, planning programs generate a strategy
for achieving the goal. In the most common cases, the strategy is just a sequence of actions.
Epistemology — This is a study of the kinds of knowledge that are required for solving problems in the world.
Ontology — Ontology is the study of the kinds of things that exist. In AI the programs and sentences deal
with various kinds of objects and we study what these kinds are and what their basic properties are. Ontology
assumed importance from the 1990s.
Heuristics — A heuristic is a way of trying to discover something or an idea embedded in a program. The
term is used variously in AI. Heuristic functions are used in some approaches to search or to measure how far
a node in a search tree seems to be from a goal. Heuristic predicates that compare two nodes in a search tree
to see if one is better than the other, i.e. constitutes an advance toward the goal, and may be more useful.
Genetic programming — Genetic programming is an automated method for creating a working computer
program from a high-level problem statement of a problem. Genetic programming starts from a high-level
statement of ‘what needs to be done’ and automatically creates a computer program to solve the problem.
Applications of AI
AI has applications in all fields of human study, such as finance and economics, environmental engineering,
chemistry, computer science, and so on. Some of the applications of AI are listed below:
• Perception
Machine vision
Speech understanding
Touch ( tactile or haptic) sensation
• Robotics
• Natural Language Processing
Natural Language Understanding
Speech Understanding
Language Generation
Machine Translation
• Planning
• Expert Systems
• Machine Learning
• Theorem Proving
• Symbolic Mathematics
• Game Playing
AI Technique:
Artificial Intelligence research during the last three decades has concluded that Intelligence requires
knowledge. To compensate overwhelming quality, knowledge possesses less desirable properties.
A. It is huge.
B. It is difficult to characterize correctly.
C. It is constantly varying.
D. It differs from data by being organized in a way that corresponds to its application.
E. It is complicated.
An AI technique is a method that exploits knowledge that is represented so that:
• The knowledge captures generalizations that share properties, are grouped together, rather than being
allowed separate representation.
• It can be understood by people who must provide it—even though for many programs bulk of the data
comes automatically from readings.
• In many AI domains, how the people understand the same people must supply the knowledge to a
program.
• It can be easily modified to correct errors and reflect changes in real conditions.
• It can be widely used even if it is incomplete or inaccurate.
• It can be used to help overcome its own sheer bulk by helping to narrow the range of possibilities that
must be usually considered.
In order to characterize an AI technique, let us consider initially OXO or tic-tac-toe and use a series of different
approaches to play the game.
The programs increase in complexity, their use of generalizations, the clarity of their knowledge and
the extensibility of their approach. In this way they move towards being representations of AI techniques.
Example-1: Tic-Tac-Toe
1.1 The first approach (simple)
The Tic-Tac-Toe game consists of a nine-element vector called BOARD; it represents the numbers 1 to 9
in three rows.
An element contains the value 0 for blank, 1 for X and 2 for O. A MOVETABLE vector consists of 19,683
elements (39) and is needed where each element is a nine-element vector. The contents of the vector are
especially chosen to help the algorithm.
The algorithm makes moves by pursuing the following:
1. View the vector as a ternary number. Convert it to a decimal number.
2. Use the decimal number as an index in MOVETABLE and access the vector.
3. Set BOARD to this vector indicating how the board looks after the move. This approach is capable in time
but it has several disadvantages. It takes more space and requires stunning 8 effort to calculate the decimal
numbers. This method is specific to this game and cannot be completed.
1.2 The second approach
The structure of the data is as before but we use 2 for a blank, 3 for an X and 5 for an O. A variable called
TURN indicates 1 for the first move and 9 for the last. The algorithm consists of three actions:
MAKE2 which returns 5 if the centre square is blank; otherwise, it returns any blank non-corner square,
i.e. 2, 4, 6 or 8. POSSWIN (p) returns 0 if player p cannot win on the next move and otherwise returns the
number of the square that gives a winning move.
It checks each line using products 3*3*2 = 18 gives a win for X, 5*5*2=50 gives a win for O, and the
winning move is the holder of the blank. GO (n) makes a move to square n setting BOARD[n] to 3 or 5.
This algorithm is more involved and takes longer but it is more efficient in storage which compensates for
its longer time. It depends on the programmer’s skill.
1.3 The final approach
The structure of the data consists of BOARD which contains a nine-element vector, a list of board positions
that could result from the next move and a number representing an estimation of how the board position leads
to an ultimate win for the player to move.
This algorithm looks ahead to make a decision on the next move by deciding which the most promising
move or the most suitable move at any stage would be and selects the same.
Consider all possible moves and replies that the program can make. Continue this process for as long as
time permits until a winner emerges, and then choose the move that leads to the computer program winning,
if possible, in the shortest time.
Actually, this is most difficult to program by a good limit but it is as far that the technique can be extended
to in any game. This method makes relatively fewer loads on the programmer in terms of the game technique
but the overall game strategy must be known to the adviser.
Example-2: Question Answering
Let us consider Question Answering systems that accept input in English and provide answers also in English.
This problem is harder than the previous one as it is more difficult to specify the problem properly. Another
area of difficulty concerns deciding whether the answer obtained is correct, or not, and further what is meant
by ‘correct’. For example, consider the following situation:
2.1 Text
Rani went shopping for a new Coat. She found a red one she really liked.
When she got home, she found that it went perfectly with her favourite dress.
2.2 Question
1. What did Rani go shopping for?
2. What did Rani find that she liked?
3. Did Rani buy anything?
Method 1
2.3 Data Structures
A set of templates that match common questions and produce patterns used to match against inputs. Templates
and patterns are used so that a template that matches a given question is associated with the corresponding
pattern to find the answer in the input text. For example, the template who did x y generates x y z if a match
occurs and z is the answer to the question. The given text and the question are both stored as strings.
2.4 Algorithm
Answering a question requires the following four steps to be followed:
Compare the template against the questions and store all successful matches to produce a set of text patterns.
Pass these text patterns through a substitution process to change the person or voice and produce an expanded
set of text patterns.
Apply each of these patterns to the text; collect all the answers and then print the answers.
2.5 Example
In question 1 we use the template WHAT DID X Y which generates Rani go shopping for z and after
substitution we get Rani goes shopping for z and Rani went shopping for z giving z [equivalence] a new coat
In question 2 we need a very large number of templates and also a scheme to allow the insertion of ‘find’
before ‘that she liked’; the insertion of ‘really’ in the text; and the substitution of ‘she’ for ‘Rani’ gives the
answer ‘a red one’.
Question 3 cannot be answered.
2.6 Comments
This is a very primitive approach basically not matching the criteria we set for intelligence and worse than
that, used in the game. Surprisingly this type of technique was actually used in ELIZA which will be
considered later in the course.
Method 2
2.7 Data Structures
A structure called English consists of a dictionary, grammar and some semantics about the vocabulary
we are likely to come across. This data structure provides the knowledge to convert English text into a storable
internal form and also to convert the response back into English. The structured representation of the text is a
processed form and defines the context of the input text by making explicit all references such as pronouns.
There are three types of such knowledge representation systems: production rules of the form ‘if x then y’,
slot and filler systems and statements in mathematical logic. The system used here will be the slot and filler
system.
Take, for example sentence:
‘She found a red one she really liked’.
Event2 Event2
instance: finding instance: liking
tense: past tense: past
agent: Rani modifier: much
object: Thing1 object: Thing1
Thing1
instance: coat
colour: red
The question is stored in two forms: as input and in the above form.
2.8 Algorithm
• Convert the question to a structured form using English know how, then use a marker to indicate the
substring (like ‘who’ or ‘what’) of the structure, that should be returned as an answer. If a slot and filler
system is used a special marker can be placed in more than one slot.
• The answer appears by matching this structured form against the structured text.
• The structured form is matched against the text and the requested segments of the question are returned.
2.9 Examples
Both questions 1 and 2 generate answers via a new coat and a red coat respectively. Question 3 cannot be
answered, because there is no direct response.
2.10 Comments
This approach is more meaningful than the previous one and so is more effective. The extra power given must
be paid for by additional search time in the knowledge bases. A warning must be given here: that is – to
generate unambiguous English knowledge base is a complex task and must be left until later in the course.
The problems of handling pronouns are difficult.
For example:
Rani walked up to the salesperson: she asked where the toy department was.
Rani walked up to the salesperson: she asked her if she needed any help.
Whereas in the original text the linkage of ‘she’ to ‘Rani’ is easy, linkage of ‘she’ in each of the above sentences
to Rani and to the salesperson requires additional knowledge about the context via the people in a shop.
Method 3
2.11 Data Structures
World model contains knowledge about objects, actions and situations that are described in the input text. This
structure is used to create integrated text from input text. The diagram shows how the system’s knowledge of
shopping might be represented and stored. This information is known as a script and in this case is a shopping
script. (See figure next page)
2.12 Algorithm
Convert the question to a structured form using both the knowledge contained in Method 2 and the
World model, generating even more possible structures, since even more knowledge is being used. Sometimes
filters are introduced to prune the possible answers.
To answer a question, the scheme followed is: Convert the question to a structured form as before but
use the world model to resolve any ambiguities that may occur. The structured form is matched against the
text and the requested segments of the question are returned.
2.13 Example
Both questions 1 and 2 generate answers, as in the previous program. Question 3 can now be answered.
The shopping script is instantiated and from the last sentence the path through step 14 is the one used to form
the representation. ‘M’ is bound to the red coat-got home. ‘Rani buys a red coat’ comes from step 10 and the
integrated text generates that she bought a red coat.
2.14 Comments
This program is more powerful than both the previous programs because it has more knowledge. Thus,
like the last game program it is exploiting AI techniques. However, we are not yet in a position to handle any
English question. The major omission is that of a general reasoning mechanism known as inference to be used
when the required answer is not explicitly given in the input text. But this approach can handle, with some
modifications, questions of the following form with the answer—Saturday morning Rani went shopping. Her
brother tried to call her but she did not answer.
Question: Why couldn’t Rani’s brother reach her?
Answer: Because she was not in.
This answer is derived because we have supplied an additional fact that a person cannot be in two
places at once. This patch is not sufficiently general so as to work in all cases and does not provide the type
of solution we are really looking for.
Types of Artificial Intelligence:
Artificial Intelligence can be divided in various types, there are mainly two types of main categorization which
are based on capabilities and based on functionally of AI. Following is flow diagram which explain the types
of AI.
Types of AI Agents
Agents can be grouped into five classes based on their degree of perceived intelligence and capability. All
these agents can improve their performance and generate better action over the time. These are given below:
o Simple Reflex Agent
o Model-based reflex agent
o Goal-based agents
o Utility-based agent
o Learning agent
1. Simple Reflex agent:
o The Simple reflex agents are the simplest agents. These agents take decisions on the basis of the current
percepts and ignore the rest of the percept history.
o These agents only succeed in the fully observable environment.
o The Simple reflex agent does not consider any part of percepts history during their decision and action
process.
o The Simple reflex agent works on Condition-action rule, which means it maps the current state to
action. Such as a Room Cleaner agent, it works only if there is dirt in the room.
o Problems for the simple reflex agent design approach:
o They have very limited intelligence
o They do not have knowledge of non-perceptual parts of the current state
o Mostly too big to generate and to store.
o Not adaptive to changes in the environment.
4. Utility-based agents
o These agents are similar to the goal-based agent but provide an extra component of utility measurement
which makes them different by providing a measure of success at a given state.
o Utility-based agent act based not only goals but also the best way to achieve the goal.
o The Utility-based agent is useful when there are multiple possible alternatives, and an agent has to
choose in order to perform the best action.
o The utility function maps each state to a real number to check how efficiently each action achieves the
goals.
5. Learning Agents
o A learning agent in AI is the type of agent which can learn from its past experiences, or it has learning
capabilities.
o It starts to act with basic knowledge and then able to act and adapt automatically through learning.
o A learning agent has mainly four conceptual components, which are:
1. Learning element: It is responsible for making improvements by learning from environment
2. Critic: Learning element takes feedback from critic which describes that how well the agent is
doing with respect to a fixed performance standard.
3. Performance element: It is responsible for selecting external action
4. Problem generator: This component is responsible for suggesting actions that will lead to
new and informative experiences.
o Hence, learning agents are able to learn, analyze performance, and look for new ways to improve the
performance.
Problem: A problem is a specific task or challenge that requires finding a solution or making a decision. In
artificial intelligence, problems can vary in complexity and scope, ranging from simple tasks like arithmetic
calculations to complex challenges such as image recognition, natural language processing, game playing, and
optimization. Each problem has a defined set of initial states, possible actions or moves, and a goal state that
needs to be reached or achieved.
For example, in a game of chess, the problem is to find a sequence of moves that lead to checkmate, while in
route planning, the problem is to find the shortest path between two locations on a map.
Problem Space: The problem space is the set of all possible states, actions, and transitions that can be
encountered while attempting to solve a specific problem. It represents the entire landscape of potential
solutions and paths from the initial state to the goal state.
In other words, the problem space defines all the possible configurations or arrangements of elements involved
in the problem and the set of valid moves or actions that can be taken at each state. Each state in the problem
space represents a specific configuration, and each action represents a possible move or step from one state to
another.
For example, in the problem of route planning, the problem space includes all possible locations on the map as
states and all valid roads or paths between them as actions.
Search: Search is the process of exploring the problem space to find a sequence of actions or moves that lead
to the goal state or a satisfactory solution. In AI, search algorithms are used to systematically navigate through
the problem space and discover paths or solutions that satisfy the problem’s constraints and objectives.
The search process involves starting from the initial state and exploring possible actions to generate new states.
These states are then evaluated based on certain criteria (e.g., distance to the goal, cost, or utility) to determine
the most promising states to explore further. The process continues iteratively until the goal state is reached or
a satisfactory solution is found.
There are various search algorithms used in AI, such as depth-first search, breadth-first search, A* search, and
heuristic search. Each algorithm has its strengths and weaknesses, and the choice of search algorithm depends
on the problem’s characteristics, size of the problem space, and the resources available.
In summary, a problem is a task or challenge that requires a solution, the problem space represents all possible
configurations and actions related to the problem, and search involves exploring the problem space to find a
sequence of actions leading to the desired goal or solution. Efficient search algorithms are essential in AI
problem-solving to effectively navigate large and complex problem spaces and find optimal or near-optimal
solutions.
To solve the problem of building a system you should take the following steps:
1. Define the problem accurately including detailed specifications and what constitutes a suitable solution.
2. Scrutinize the problem carefully, for some features may have a central effect on the chosen method of
solution.
3. Segregate and represent the background knowledge needed in the solution of the problem.
4. Choose the best solving techniques for the problem to solve a solution
Problem characteristics are essential factors to consider when choosing the most suitable problem-solving
method for a particular task. Let’s explore these characteristics in detail:
Is the problem decomposable?
The question of whether a problem is decomposable refers to whether it can be broken down into smaller,
independent subproblems. Decomposable problems can be solved by tackling each subproblem individually,
and their solutions can then be combined to solve the overall problem. Some problems, like complex integrals,
can be decomposed into simpler subproblems, making it easier to find a solution using the divide-and-conquer
approach. However, not all problems are decomposable, and some may require addressing as a whole without
breaking them down into independent parts.
Can solution steps be ignored or undone?
The reversibility of solution steps refers to whether they can be ignored or undone if they prove to be unwise
or lead to a dead end. In some problems, certain solution steps can be ignored without affecting the final result.
In recoverable problems, solution steps can be undone to explore alternative paths. For instance, in the 8-puzzle,
moves can be undone to try different arrangements of tiles. On the other hand, some problems have irreversible
solution steps, like in chess, where once a move is made, it cannot be undone.
Is the problem’s universe predictable?
The predictability of a problem’s universe refers to whether the outcomes or states of the problem can be
determined with certainty or if they involve uncertainty. Some problems have deterministic outcomes, meaning
that the result is known and can be predicted with complete certainty based on the given conditions and rules.
Other problems may involve uncertainty or randomness, leading to non-deterministic outcomes. For example,
some optimization problems may have multiple potential solutions with different probabilities of being optimal.
Is a good solution absolute or relative?
The nature of a good solution can be either absolute or relative. An absolute solution is one where finding a
single correct path or outcome is sufficient to achieve the desired goal. In problems like the water jug puzzle,
finding any valid path to the solution is considered good enough. On the other hand, a relative solution is one
that requires evaluating multiple possible paths or outcomes to find the best or optimal solution. Problems like
the traveling salesman problem seek the shortest route among all possible routes, making it a relative solution.
Is the solution a state or a path?
The solution to a problem can be either a state or a path, depending on the nature of the problem. In some
problems, the desired outcome is a specific state or configuration that satisfies the problem’s requirements. For
instance, in the 8-puzzle, the solution is a specific arrangement of tiles in the goal state. In other problems, the
solution involves finding a path or sequence of steps to reach the desired goal state. For example, in maze-
solving, the solution is the path from the starting point to the exit.
What is the role of knowledge?
The role of knowledge in problem-solving varies based on the complexity and nature of the problem.
Knowledge plays a critical role in guiding the problem-solving process. In some problems, extensive domain-
specific knowledge is required to recognize patterns, constraints, and possible solutions. For example, chess
requires deep knowledge of the game rules and strategic principles to make informed moves. In contrast, other
problems may rely more on general problem-solving algorithms and heuristics, requiring less domain-specific
knowledge.
Can a computer give the problem solution, or interaction with humans is required?
The level of human interaction required in problem-solving depends on the problem’s complexity and the
capabilities of the problem-solving methods being used. In some cases, computers can autonomously find
solutions to problems without any interaction with humans. For example, algorithms can efficiently solve
mathematical equations or perform certain optimization tasks. However, in more complex and uncertain
problems, human interaction may be necessary to provide additional information, preferences, or guidance.
Conversational problem-solving, where the computer interacts with users to gather information or provide
assistance, can be valuable in addressing such challenges.
State Space Search
A state space is a way to mathematically represent a problem by defining all the possible states in which the
problem can be. This is used in search algorithms to represent the initial state, goal state, and current state of
the problem. Each state in the state space is represented using a set of variables.
The efficiency of the search algorithm greatly depends on the size of the state space, and it is important to
choose an appropriate representation and search strategy to search the state space efficiently.
One of the most well-known state space search algorithms is the A algorithm. Other commonly used state
space search algorithms include breadth-first search (BFS), depth-first search (DFS), hill
climbing, simulated annealing, and genetic algorithms.
Features of State Space Search
State space search has several features that make it an effective problem-solving technique in Artificial
Intelligence. These features include:
• Exhaustiveness: State space search explores all possible states of a problem to find a solution.
• Completeness: If a solution exists, state space search will find it.
• Optimality: Searching through a state space results in an optimal solution.
• Uninformed and Informed Search: State space search in artificial intelligence can be classified as
uninformed if it provides additional information about the problem.
In contrast, informed search uses additional information, such as heuristics, to guide the search process.
Steps in State Space Search
The steps involved in state space search are as follows:
• To begin the search process, we set the current state to the initial state.
• We then check if the current state is the goal state. If it is, we terminate the algorithm and return the
result.
• If the current state is not the goal state, we generate the set of possible successor states that can be
reached from the current state.
• For each successor state, we check if it has already been visited. If it has, we skip it, else we add it to
the queue of states to be visited.
• Next, we set the next state in the queue as the current state and check if it's the goal state. If it is, we
return the result. If not, we repeat the previous step until we find the goal state or explore all the states.
• If all possible states have been explored and the goal state still needs to be found, we return with no
solution.
State Space Representation
State space Representation involves defining an INITIAL STATE and a GOAL STATE and then
determining a sequence of actions, called states, to follow.
• State: A state can be an Initial State, a Goal State, or any other possible state that can be generated by
applying rules between them.
• Space: In an AI problem, space refers to the exhaustive collection of all conceivable states.
• Search: This technique moves from the beginning state to the desired state by applying good rules
while traversing the space of all possible states.
• Search Tree: To visualize the search issue, a search tree is used, which is a tree-like structure that
represents the problem. The initial state is represented by the root node of the search tree, which is the
starting point of the tree.
• Transition Model: This describes what each action does, while Path Cost assigns a cost value to each
path, an activity sequence that connects the beginning node to the end node. The optimal option has
the lowest cost among all alternatives.
Example of State Space Search
The 8-puzzle problem is a commonly used example of a state space search. It is a sliding puzzle game
consisting of 8 numbered tiles arranged in a 3x3 grid and one blank space. The game aims to rearrange the
tiles from their initial state to a final goal state by sliding them into the blank space.
To represent the state space in this problem, we use the nine tiles in the puzzle and their respective positions
in the grid. Each state in the state space is represented by a 3x3 array with values ranging from 1 to 8, and the
blank space is represented as an empty tile.
The initial state of the puzzle represents the starting configuration of the tiles, while the goal state represents
the desired configuration. Search algorithms utilize the state space to find a sequence of moves that will
transform the initial state into the goal state.
This algorithm guarantees a solution but can become very slow for larger state spaces. Alternatively, other
algorithms, such as A search, use heuristics to guide the search more efficiently. Our objective is to move
from the current state to the target state by sliding the numbered tiles through the blank space. Let's look closer
at reaching the target state from the current state.
To summarize, our approach involved exhaustively exploring all reachable states from the current state and
checking if any of these states matched the target state.
Applications of State Space Search
• State space search algorithms are used in various fields, such as robotics, game playing, computer
networks, operations research, bioinformatics, cryptography, and supply chain management. In
artificial intelligence, state space search algorithms can solve problems like pathfinding, planning,
and scheduling.
• They are also useful in planning robot motion and finding the best sequence of actions to achieve a
goal. In games, state space search algorithms can help determine the best move for a player given a
particular game state.
• State space search algorithms can optimize routing and resource allocation in computer networks
and operations research.
• In Bioinformatics, state space search algorithms can help find patterns in biological data and predict
protein structures.
• In Cryptography, state space search algorithms are used to break codes and find cryptographic keys.
Production System in AI
A production system in AI is a framework that assists in developing computer programs to automate a wide
range of tasks. It significantly impacts the creation of AI-based systems like computer software, mobile
applications, and manufacturing tools. By establishing rules, a production system empowers machines to
demonstrate particular behaviors and adapt to their surroundings.
In Artificial Intelligence, a production system serves as a cognitive architecture. It encompasses rules
representing declarative knowledge, allowing machines to make decisions and act based on different
conditions. Many expert systems and automation methodologies rely on the rules defined in production
systems to guide their behavior.
A production system’s architecture consists of rules structured as left-hand side (LHS) and right-hand side
(RHS) equations. The LHS specifies the condition to be evaluated, while the RHS determines the output or
action resulting from the estimated condition. This rule-based approach forms the foundation of production
systems in AI, enabling machines to process information and respond accordingly.
The representation of knowledge in AI comprises various components used for making intelligent machines.
In the next section, we will discuss the important components of a production system in Artificial Intelligence.
Components of a Production System in AI
For making an AI-based intelligent system that performs specific tasks, we need an architecture. The
architecture of a production system in Artificial Intelligence consists of production rules, a database, and the
control system.
Global Database
A global database consists of the architecture used as a central data structure. A database contains all the
necessary data and information required for the successful completion of a task. It can be divided into two
parts as permanent and temporary. The permanent part of the database consists of fixed actions, whereas the
temporary part alters according to circumstances.
Production Rules
Production rules in AI are the set of rules that operate on the data fetched from the global database. Also, these
production rules are bound with precondition and postcondition that gets checked by the database. If a
condition is passed through a production rule and gets satisfied by the global database, then the rule is
successfully applied. The rules are of the form A®B, where the right-hand side represents an outcome
corresponding to the problem state represented by the left-hand side.
Control System
The control system checks the applicability of a rule. It helps decide which rule should be applied and
terminates the process when the system gives the correct output. It also resolves the conflict of multiple
conditions arriving at the same time. The strategy of the control system specifies the sequence of rules that
compares the condition from the global database to reach the correct result.
Characteristics of a Production System
There are mainly four characteristics of the production system in AI that is simplicity, modifiability,
modularity, and knowledge-intensive.
Simplicity
The production rule in AI is in the form of an ‘IF-THEN’ statement. Every rule in the production system has
a unique structure. It helps represent knowledge and reasoning in the simplest way possible to solve real-world
problems. Also, it helps improve the readability and understanding of the production rules.
Modularity
The modularity of a production rule helps in its incremental improvement as the production rule can be in
discrete parts. The production rule is made from a collection of information and facts that may not have
dependencies unless there is a rule connecting them together. The addition or deletion of single information
will not have a major effect on the output. Modularity helps enhance the performance of the production system
by adjusting the parameters of the rules.
Modifiability
The feature of modifiability helps alter the rules as per requirements. Initially, the skeletal form of the
production system is created. We then gather the requirements and make changes in the raw structure of the
production system. This helps in the iterative improvement of the production system.
Knowledge-intensive
Production systems contain knowledge in the form of a human spoken language, i.e., English. It is not built
using any programming languages. The knowledge is represented in plain English sentences. Production rules
help make productive conclusions from these sentences.
Disadvantages of a Production System
We discussed various features of a production system in the previous section. However, many disadvantages
are also there in a production system in Artificial Intelligence, and they are as given below:
Opacity
Communication between the rule interpreter and the production rules creates difficulty for the understanding
of the control system and its strategies. This condition arises due to the impact of the combined operation of
the control program. There exist difficulties in understanding the hierarchy of operations.
Inefficiency
There are various rules that we employ for solving a problem. The rules can be effective in different ways.
There are conditions where multiple rules get activated during execution. All the individual rules apply
exhaustive searches in each cycle that reduces the efficiency of the production system.
Inability to Learn
A simple production system based on certain rules is not capable of learning through experience, unlike
advanced AI systems. They are simply bound to specific rules for actions. We can understand the rules and
break them.
Conflict Resolution
To satisfy a condition, various production rules are employed. The condition may arise when there is a
triggering of more than one rule. In that condition, the control system has to determine the best possible rule
from the set of conflicting rules. This may reduce the efficiency of the production system.
Classes of a Production System
There are four types of production systems that help in categorizing methodologies for solving different
varieties of problems. Let us have a look at each one of them.
This class helps create a production system that can give the results even by interchanging the states of rules.
If using a set of rules transforms State A into State B, then multiple combinations of those rules will be capable
to convert State A into State B.
This type of a production system increases efficiency in solving problems. The implementation of these
systems does not require backtracking to correct the previous incorrect moves. The non-monotonic production
systems are necessary from the implementation point of view to find an efficient solution.
Commutative System
Commutative systems are helpful where the order of an operation is not important. Also, problems where the
changes are reversible use commutative systems. On the other hand, partially commutative production systems
help in working on problems, where the changes are irreversible such as a chemical process. When dealing
with partially commutative systems, the order of processes is important to get the correct results.
Inference Rules
There are many production rules in Artificial Intelligence. One of them is the inference rule. It is a type of rule
that consists of a logical form used for transformation. Let us look at the types of inference rules:
It consists of a logic that helps reasoning with the help of multiple statements to reach a conclusion.
Let us understand with the help of an example:
Example:
Statement 1: All mammals are animals.
Statement 2: Dogs are mammals.
Conclusion: Therefore, dogs are animals.
In this example, we have two statements: “All mammals are animals” and “Dogs are mammals.” We can use
deductive inference to draw a logical conclusion based on these statements.
Using the deductive inference rule of categorical syllogism, which states that if the major premise (“All
mammals are animals”) and the minor premise (“Dogs are mammals”) are true, then the conclusion
(“Therefore, dogs are animals”) is also true.
By applying deductive inference to the given example, we can conclude that dogs are indeed animals based
on the statements provided.
This rule helps explain the conclusion most simply by using the given observations.
Let’s explore an example to understand the abductive inference rule:
Example:
Observation 1: The ground is wet.
Observation 2: There are dark clouds in the sky.
Conclusion: It might have rained.
In this example, we have two observations: “The ground is wet” and “There are dark clouds in the sky.” We
can use abductive inference to generate a plausible explanation or hypothesis that best explains these
observations.
The abductive inference rule suggests that the simplest and most likely explanation that can account for the
given observations should be considered. In this case, the most straightforward explanation is that it might
have rained. The wet ground and the presence of dark clouds in the sky are consistent with the hypothesis that
rain occurred.
Now, we will take a look at a use case to understand how to use production rules to solve a problem.
Use Case: Sorting a String in a Production System
In the previous sections of this blog, we discussed the details of a production rule. Now, we will understand
the use of production rules with an example of sorting a string.
Initial String: ‘cbaca’
Final String: ‘aabcc’
Let us look at the mechanism for sorting a string using the production system in AI.
• The production rules that we use for sorting will be enabled when it satisfies the condition by finding
the sub-string in memory.
• When a particular rule is selected, it replaces the matched string by the string present on the right-hand
side of the production rule.
• The loop of production rules will iterate until it finds the correct output.
Let us look at a basic production rule that can be used in this case:
1. ba -> ab
2. ca -> ac
3. cb -> bc
Now, the below diagram will show the execution of the rules for converting the string.
Here, the conflict set represents the set of all the rules that are applicable to the string. We have to decide
which rule should be used.
Hence, by using three production rules and seven iterations, we are able to convert the string ‘cbaca’ to ‘aabcc.’
Heuristics Technique
A heuristic is a technique that is used to solve a problem faster than the classic methods. These techniques are
used to find the approximate solution of a problem when classical methods do not. Heuristics are said to be
the problem-solving techniques that result in practical and quick solutions.
Heuristics are strategies that are derived from past experience with similar problems. Heuristics use practical
methods and shortcuts used to produce the solutions that may or may not be optimal, but those solutions are
sufficient in a given limited timeframe.
Why do we need heuristics?
Heuristics are used in situations in which there is the requirement of a short-term solution. On facing complex
situations with limited resources and time, Heuristics can help the companies to make quick decisions by
shortcuts and approximated calculations. Most of the heuristic methods involve mental shortcuts to make
decisions on past experiences.
The heuristic method might not always provide us the finest solution, but it is assured that it helps us
find a good solution in a reasonable time.
Based on context, there can be different heuristic methods that correlate with the problem's scope. The
most common heuristic methods are - trial and error, guesswork, the process of elimination, historical data
analysis. These methods involve simply available information that is not particular to the problem but is most
appropriate. They can include representative, affect, and availability heuristics.
We can perform the Heuristic techniques into two categories:
It includes Blind Search, Uninformed Search, and Blind control strategy. These search techniques are not
always possible as they require much memory and time. These techniques search the complete space for a
solution and use the arbitrary ordering of operations.
The examples of Direct Heuristic search techniques include Breadth-First Search (BFS) and Depth First
Search (DFS).
It includes Informed Search, Heuristic Search, and Heuristic control strategy. These techniques are helpful
when they are applied properly to the right types of tasks. They usually require domain-specific information.
The examples of Weak Heuristic search techniques include Best First Search (BFS) and A*.
Before describing certain heuristic techniques, let's see some of the techniques listed below:
• Bidirectional Search
• A* search
• Simulated Annealing
• Hill Climbing
• Best First search
• Beam search
Generate and Test Search
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 as it’s like looking for an exhibit at random
or finding an object in the British Museum by wandering randomly.
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. But there is
a technique to improve in complex cases as well by combining generate and test search with other techniques
so as to reduce the search space. For example, in Artificial Intelligence Program DENDRAL we make use
of two techniques, the first one is Constraint Satisfaction Techniques followed by Generate and Test
Procedure to work on reduced search space i.e. yield an effective result by working on a lesser number of
lists generated in the very first step.
Algorithm
1. Generate a possible solution. For example, generating a particular point in the problem space
or generating a path for a start state.
2. 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
3. If a solution is found, quit. Otherwise go to Step 1
The total number of solutions in this case is (100)3 which is approximately 1M. So, if we do not make use
of any informed search technique then it results in exponential time complexity. Now let’s say if we generate
5 solutions every minute. Then the total numbers generated in 1 hour are 5*60=300 and the total number of
solutions to be generated are 1M. Let us consider the brute force search technique for example linear search
whose average time complexity is N/2. Then on an average, the total number of the solutions to be generated
are approximately 5 lakhs. Using this technique even if you work for about 24 hrs a day then also you will
need 10 weeks to complete the task.
Now consider using heuristic function where we have domain knowledge that every number is a prime
number between 0-99 then the possible number of solutions are (25)3 which is approximately 15,000. Now
consider the same case that you are generating 5 solutions every minute and working for 24 hrs then you
can find the solution in less than 2 days which was being done in 10 weeks in the case of uninformed search.
We can conclude for here that if we can find a good heuristic then time complexity can be reduced gradually.
But in the worst-case time and space complexity will be exponential. It all depends on the generator i.e.
better the generator lesser is the time complexity.
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.
Search flow with Generate and Test
1 ABCD 19
2 ABDC 18
3 ACBD 12
4 ACDB 13
5 ADBC 16
Continued
Finally, select the path whose length is less.
• If a sufficient number of monkeys were placed in front of a set of typewriters, and left alone long
enough, then they would eventually produce all the works of Shakespeare.
• Dendral which infers the structure of organic compounds using NMR spectrogram also uses plan-
generate-test.
Hill climbing algorithm
• Hill climbing algorithm is a local search algorithm which continuously moves in the direction of
increasing elevation/value to find the peak of the mountain or best solution to the problem. It
terminates when it reaches a peak value where no neighbor has a higher value.
• Hill climbing algorithm is a technique which is used for optimizing the mathematical problems. One
of the widely discussed examples of Hill climbing algorithm is Traveling-salesman Problem in which
we need to minimize the distance traveled by the salesman.
• It is also called greedy local search as it only looks to its good immediate neighbor state and not
beyond that.
• A node of hill climbing algorithm has two components which are state and value.
• Hill Climbing is mostly used when a good heuristic is available.
• In this algorithm, we don't need to maintain and handle the search tree or graph as it only keeps a
single current state.
Features of Hill Climbing:
Following are some main features of Hill Climbing Algorithm:
• Generate and Test variant: Hill Climbing is the variant of Generate and Test method. The Generate
and Test method produce feedback which helps to decide which direction to move in the search space.
• Greedy approach: Hill-climbing algorithm search moves in the direction which optimizes the cost.
• No backtracking: It does not backtrack the search space, as it does not remember the previous states.
State-space Diagram for Hill Climbing:
The state-space landscape is a graphical representation of the hill-climbing algorithm which is showing a
graph between various states of algorithm and Objective function/Cost.
On Y-axis we have taken the function which can be an objective function or cost function, and state-space on
the x-axis. If the function on Y-axis is cost then, the goal of search is to find the global minimum and local
minimum. If the function of Y-axis is Objective function, then the goal of the search is to find the global
maximum and local maximum.
Simple hill climbing is the simplest way to implement a hill climbing algorithm. It only evaluates the
neighbour node state at a time and selects the first one which optimizes current cost and set it as a
current state. It only checks it's one successor state, and if it finds better than the current state, then move
else be in the same state. This algorithm has the following features:
• Less time consuming
• Less optimal solution and the solution is not guaranteed
Step 1: Evaluate the initial state, if it is goal state then return success and Stop.
Step 2: Loop Until a solution is found or there is no new operator left to apply.
Step 3: Select and apply an operator to the current state.
Step 4: Check new state:
1. If it is goal state, then return success and quit.
2. Else if it is better than the current state then assigns new state as a current state.
3. Else if not better than the current state, then return to step2.
Step 5: Exit.
The steepest-Ascent algorithm is a variation of simple hill climbing algorithm. This algorithm examines all
the neighbouring nodes of the current state and selects one neighbour node which is closest to the goal state.
This algorithm consumes more time as it searches for multiple neighbours
Step 1: Evaluate the initial state, if it is goal state then return success and stop, else make current state as
initial state.
Step 2: Loop until a solution is found or the current state does not change.
1. Let SUCC be a state such that any successor of the current state will be better than it.
2. For each operator that applies to the current state:
i. Apply the new operator and generate a new state.
ii. Evaluate the new state.
iii. If it is goal state, then return it and quit, else compare it to the SUCC.
iv. If it is better than SUCC, then set new state as SUCC.
v. If the SUCC is better than the current state, then set current state to SUCC.
Step 5: Exit.
Stochastic hill climbing does not examine for all its neighbour before moving. Rather, this search algorithm
selects one neighbour node at random and decides whether to choose it as a current state or examine another
state.
Problems in Hill Climbing Algorithm:
1. Local Maximum: A local maximum is a peak state in the landscape which is better than each of its
neighbouring states, but there is another state also present which is higher than the local maximum.
Solution: Backtracking technique can be a solution of the local maximum in state space landscape. Create a
list of the promising path so that the algorithm can backtrack the search space and explore other paths as well.
2. Plateau: A plateau is the flat area of the search space in which all the neighbour states of the current state
contain the same value, because of this algorithm does not find any best direction to move. A hill-climbing
search might be lost in the plateau area.
Solution: The solution for the plateau is to take big steps or very little steps while searching, to solve the
problem. Randomly select a state which is far away from the current state so it is possible that the algorithm
could find non-plateau region.
3. Ridges: A ridge is a special form of the local maximum. It has an area which is higher than its surrounding
areas, but itself has a slope, and cannot be reached in a single move.
Solution: With the use of bidirectional search, or by moving in different directions, we can improve this
problem.
Simulated Annealing:
A hill-climbing algorithm which never makes a move towards a lower value guaranteed to be incomplete
because it can get stuck on a local maximum. And if algorithm applies a random walk, by moving a successor,
then it may complete but not efficient. Simulated Annealing is an algorithm which yields both efficiency and
completeness.
In mechanical term Annealing is a process of hardening a metal or glass to a high temperature then cooling
gradually, so this allows the metal to reach a low-energy crystalline state. The same process is used in
simulated annealing in which the algorithm picks a random move, instead of picking the best move. If the
random move improves the state, then it follows the same path. Otherwise, the algorithm follows the path
which has a probability of less than 1 or it moves downhill and chooses another path.
Greedy best-first search algorithm always selects the path which appears best at that moment. It is the
combination of depth-first search and breadth-first search algorithms. It uses the heuristic function and search.
Best-first search allows us to take the advantages of both algorithms. With the help of best-first search, at each
step, we can choose the most promising node. In the best first search algorithm, we expand the node which is
closest to the goal node and the closest cost is estimated by heuristic function, i.e.
1. f(n)= g(n).
Were, h(n)= estimated cost from node n to the goal.
The greedy best first algorithm is implemented by the priority queue.