Professional Documents
Culture Documents
The reflex agent of AI directly maps states into action. Whenever these agents fail to
operate in an environment where the state of mapping is too large and not easily
performed by the agent, then the stated problem dissolves and sent to a
problem-solving domain which breaks the large stored problem into the smaller
storage area and resolves one by one. The final integrated action will be the desired
outcomes.
On the basis of the problem and their working domain, different types of
problem-solving agents are defined and used at an atomic level without any internal
state visible with a problem-solving algorithm. The problem-solving agent performs
precisely by defining problems and several solutions. So we can say that problem
solving is a part of artificial intelligence that encompasses a number of techniques
such as a tree, B-tree, heuristic algorithms to solve a problem.
Steps problem-solving in AI: The problem of AI is directly associated with the nature
of humans and their activities. So we need a number of finite steps to solve a
problem which makes human work easy.
These are the following steps which require to solve a problem :
● Goal Formulation: This one is the first and simple step in problem-solving. It
organises finite steps to formulate a target/goals which require some action to
achieve the goal. Today the formulation of the goal is based on AI agents.
● Problem formulation: It is one of the core steps of problem-solving which
decides what action should be taken to achieve the formulated goal. In AI this
core part is dependent upon a software agent which consists of the following
components to formulate the associated problem.
Components to formulate the associated problem:
● Initial State: This state requires an initial state for the problem which starts
the AI agent towards a specified goal. In this state new methods also initialise
problem domain solving by a specific class.
● Action: This stage of problem formulation works with a function with a
specific class taken from the initial state and all possible actions done in this
stage.
● Transition: This stage of problem formulation integrates the actual action
done by the previous action stage and collects the final stage to forward it to
their next stage.
● Goal test: This stage determines if the specified goal is achieved by the
integrated transition model or not, whenever the goal is achieved, stop the
action and forward into the next stage to determine the cost to achieve the
goal.
● Path costing: This component of problem-solving is numerically assigned
what will be the cost to achieve the goal. It requires all hardware software and
human working costs.
An AI system is composed of an agent and its environment. The agents act in their
environment. The environment may contain other agents.
An agent is anything that can be viewed as :
● perceiving its environment through sensors and
● acting upon that environment through actuators
Agent = Architecture + Agent Program
Architecture is the machinery that the agent executes
on. It is a device with sensors and actuators, for
example, a robotic car, a camera, a PC. Agent
program is an implementation of an agent function.
Types of Agents
Agents can be grouped into five classes based on their degree of perceived
intelligence and capability :
● Simple Reflex Agents
● Model-Based Reflex Agents
● Goal-Based Agents
● Utility-Based Agents
● Learning Agent
Goal-based agents
Utility-based agents
Learning Agent :
In constraint satisfaction, domains are the spaces where the variables reside,
following the problem specific constraints. These are the three main elements of a
constraint satisfaction technique. The constraint value consists of a pair of {scope,
rel}. The scope is a tuple of variables which participate in the constraint and rel is a
relation which includes a list of values which the variables can take to satisfy the
constraints of the problem.
Constraint Propagation
In local state-spaces, the choice is only one, i.e., to search for a solution. But in CSP,
we have two choices either:
● We can search for a solution or
● We can perform a special type of inference called constraint propagation.
Constraint propagation is a special type of inference which helps in reducing the
legal number of values for the variables. The idea behind constraint propagation is
local consistency.
In local consistency, variables are treated as nodes, and each binary constraint is
treated as an arc in the given problem. There are following local consistencies which
are discussed below:
● Node Consistency: A single variable is said to be node consistent if all the
values in the variable’s domain satisfy the unary constraints on the variables.
● Arc Consistency: A variable is arc consistent if every value in its domain
satisfies the binary constraints of the variables.
● Path Consistency: When the evaluation of a set of two variables with respect
to a third variable can be extended over another variable, satisfying all the
binary constraints. It is similar to arc consistency.
● k-consistency: This type of consistency is used to define the notion of
stronger forms of propagation. Here, we examine the k-consistency of the
variables.
CSP Problems
Constraint satisfaction includes those problems which contain some constraints
while solving the problem. CSP includes the following problems:
Crossword: In crossword problems, the constraint is that there should be the correct
formation of the words, and it should be meaningful.
Latin square Problem: In this game, the task is to search the pattern which is
occurring several times in the game. They may be shuffled but will contain the same
digits.
It uses knowledge for the searching It doesn’t use knowledge for the
process. searching process.
1. Breadth-first Search
2. Depth-first Search
3. Depth-limited Search
4. Iterative deepening depth-first search
5. Uniform cost search
6. Bidirectional Search
1. Breadth-first Search:
● Breadth-first search is the most common search strategy for traversing a tree
or graph. This algorithm searches breadthwise in a tree or graph, so it is
called breadth-first search.
● The BFS algorithm starts searching from the root node of the tree and
expands all successor nodes at the current level before moving to nodes of
the next level.
● The breadth-first search algorithm is an example of a general-graph search
algorithm.
● Breadth-first search implemented using FIFO queue data structure.
Advantages:
Disadvantages:
● It requires lots of memory since each level of the tree must be saved into
memory to expand the next level.
● BFS needs lots of time if the solution is far away from the root node.
Example:
1. S---> A--->B---->C--->D---->G--->H--->E---->F---->I---->K
Space Complexity: Space complexity of BFS algorithm is given by the Memory size
of frontier which is O(bd).
Completeness: BFS is complete, which means if the shallowest goal node is at
some finite depth, then BFS will find a solution.
2. Depth-first Search
● Depth-first search isa recursive algorithm for traversing a tree or graph data
structure.
● It is called the depth-first search because it starts from the root node and
follows each path to its greatest depth node before moving to the next path.
● DFS uses a stack data structure for its implementation.
● The process of the DFS algorithm is similar to the BFS algorithm.
Advantage:
● DFS requires very less memory as it only needs to store a stack of the nodes
on the path from root node to the current node.
● It takes less time to reach the goal node than the BFS algorithm (if it traverses
in the right path).
Disadvantage:
● There is the possibility that many states keep reoccurring, and there is no
guarantee of finding the solution.
● The DFS algorithm goes for deep down searching and sometimes it may go to
the infinite loop.
Example:
In the below search tree, we have shown the flow of depth-first search, and it will
follow the order as:
Where, m= maximum depth of any node and this can be much larger than d
(Shallowest solution depth)
Space Complexity: DFS algorithm needs to store only a single path from the root
node, hence space complexity of DFS is equivalent to the size of the fringe set,
which is O(bm).
● Standard failure value: It indicates that the problem does not have any
solution.
● Cutoff failure value: It defines no solution for the problem within a given
depth limit.
Advantages:
Disadvantages:
Example:
Completeness: DLS search algorithm is complete if the solution is above the
depth-limit.
Advantages:
● Uniform cost search is optimal because at every state the path with the least
cost is chosen.
Disadvantages:
● It does not care about the number of steps involved in searching and is only
concerned about path cost. Due to which this algorithm may be stuck in an
infinite loop.
Example:
Space Complexity: The same logic is for space complexity so, the worst-case
space complexity of Uniform-cost search is O(b1 + [C*/ε]).
Optimal: Uniform-cost search is always optimal as it only selects a path with the
lowest path cost.
Advantages:
● It Combines the benefits of BFS and DFS search algorithms in terms of fast
search and memory efficiency.
Disadvantages:
● The main drawback of IDDFS is that it repeats all the work of the previous
phase.
Example:
1'st Iteration-----> A
2'nd Iteration----> A, B, C
3'rd Iteration------>A, B, D, E, C, F, G
4'th Iteration------>A, B, D, H, I, E, C, F, K, G
In the fourth iteration, the algorithm will find the goal node.
Optimal: The IDDFS algorithm is optimal if path cost is a non- decreasing function of
the depth of the node.
Bidirectional search algorithm runs two simultaneous searches, one from initial state
called as forward-search and other from goal node called as backward-search, to
find the goal node. Bidirectional search replaces one single search graph with two
small subgraphs in which one starts the search from an initial vertex and other starts
from goal vertex. The search stops when these two graphs intersect each other.
Bidirectional search can use search techniques such as BFS, DFS, DLS, etc.
Advantages:
Disadvantages:
Example:
The informed search algorithm is more useful for large search spaces. Informed
search algorithms use the idea of heuristic, so it is also called Heuristic search.
Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence heuristic cost
should be less than or equal to the estimated cost.
Pure heuristic search is the simplest form of heuristic search algorithms. It expands
nodes based on their heuristic value h(n). It maintains two lists, OPEN and CLOSED
list. In the CLOSED list, it places those nodes which have already expanded and in
the OPEN list, it places nodes which have yet not been expanded.
On each iteration, each node n with the lowest heuristic value is expanded and
generates all its successors and n is placed to the closed list. The algorithm
continues until a goal state is found.
In the informed search we will discuss two main algorithms which are given below:
Greedy best-first search algorithm always selects the path which appears best at
that moment. It is the combination of depth-first search and breadth-first search
algorithms. It uses the heuristic function and search. Best-first search allows us to
take the advantages of both algorithms. With the help of best-first search, at each
step, we can choose the most promising node. In the best first search algorithm, we
expand the node which is closest to the goal node and the closest cost is estimated
by heuristic function, i.e.
1. f(n)= g(n).
Advantages:
● Best first search can switch between BFS and DFS by gaining the advantages
of both the algorithms.
● This algorithm is more efficient than BFS and DFS algorithms.
Disadvantages:
Example:
Time Complexity: The worst case time complexity of Greedy best first search is
O(bm).
Space Complexity: The worst case space complexity of Greedy best first search is
O(bm). Where, m is the maximum depth of the search space.
Complete: Greedy best-first search is also incomplete, even if the given state space
is finite.
A* search is the most commonly known form of best-first search. It uses the heuristic
function h(n), and the cost to reach the node n from the start state g(n). It has
combined features of UCS and greedy best-first search, by which it solves the
problem efficiently. A* search algorithm finds the shortest path through the search
space using the heuristic function. This search algorithm expands the search tree
and provides optimal results faster. A* The algorithm is similar to UCS except that it
uses g(n)+h(n) instead of g(n).
In A* search algorithm, we use search heuristic as well as the cost to reach the
node. Hence we can combine both costs as follows, and this sum is called a fitness
number.
Algorithm of A* search:
Step 2: Check if the OPEN list is empty or not, if the list is empty then return failure
and stop.
Step 3: Select the node from the OPEN list which has the smallest value of
evaluation function (g+h), if node n is goal node then return success and stop,
otherwise
Step 4: Expand node n and generate all of its successors, and put n into the closed
list. For each successor n', check whether n' is already in the OPEN or CLOSED list,
if not then compute the evaluation function for n' and place it into the Open list.
Step 5: Else if node n' is already in OPEN and CLOSED, then it should be attached
to the back pointer which reflects the lowest g(n') value.
Advantages:
Disadvantages:
Example:
In this example, we will traverse the given graph using the A* algorithm. The
heuristic value of all states is given in the below table so we will calculate the f(n) of
each state using the formula f(n)= g(n) + h(n), where g(n) is the cost to reach any
node from the start state.
Here we will use an OPEN and CLOSED list.
Initialization: {(S, 5)}
Iteration3: {(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S--> A-->B, 7), (S-->G, 10)}
Iteration 4 will give the final result, as S--->A--->C--->G it provides the optimal path
with cost 6.
● Admissible: the first condition requires for optimality is that h(n) should be an
admissible heuristic for A* tree search. An admissible heuristic is optimistic in
nature.
● Consistency: Second required condition is consistency for only A*
graph-search.
If the heuristic function is admissible, then A* tree search will always find the least
cost path.
Genetic Algorithms
Genetic Algorithms(GAs) are adaptive heuristic search algorithms that belong to the
larger part of evolutionary algorithms. Genetic algorithms are based on the ideas of
natural selection and genetics. These are intelligent exploitation of random search
provided with historical data to direct the search into the region of better performance
in solution space. They are commonly used to generate high-quality solutions for
optimization problems and search problems.
Genetic algorithms simulate the process of natural selection which means those
species who can adapt to changes in their environment are able to survive and
reproduce and go to the next generation. In simple words, they simulate “survival of
the fittest” among individuals of consecutive generations for solving a problem. Each
generation consists of a population of individuals and each individual represents a
point in search space and possible solution. Each individual is represented as a
string of character/integer/float/bits. This string is analogous to the Chromosome.
Foundation of Genetic Algorithms
Genetic algorithms are based on an analogy with genetic structure and behaviour of
chromosomes of the population. Following is the foundation of GAs based on this
analogy –
1. Individual in population compete for resources and mate
2. Those individuals who are successful (fittest) then mate to create more
offspring than others
3. Genes from “fittest” parents propagate throughout the generation, that is
sometimes parents create offspring which are better than either parent.
4. Thus each successive generation is more suited for their environment.
The minimax algorithm performs a depth-first search algorithm for the exploration of
the complete game tree. The minimax algorithm proceeds all the way down to the
terminal node of the tree, then backtrack the tree as the recursion.
Working of Min-Max Algorithm:
Alpha: The best (highest-value) choice we have found so far at any point along the
path of Maximizer. The initial value of alpha is -∞.
Beta: The best (lowest-value) choice we have found so far at any point along the
path of Minimizer. The initial value of beta is +∞.
The Alpha-beta pruning to a standard minimax algorithm returns the same move as
the standard algorithm does, but it removes all the nodes which are not really
affecting the final decision but making the algorithm slow. Hence by pruning these
nodes, it makes the algorithm fast.
Knowledge representation
What to Represent:
● Object: All the facts about objects in our world domain. E.gGuitars contain
strings, trumpets are brass instruments.
● Events: Events are the actions which occur in our world.
● Performance: It describes behaviour which involves knowledge about how to
do things.
● Meta-knowledge: It is knowledge about what we know.
● Facts: Facts are the truths about the real world and what we represent.
● Knowledge-Base: The central component of the knowledge-based agents is
the knowledge base. It is represented as KB. The Knowledgebase is a group
of the Sentences (Here, sentences are used as a technical term and not
identical with the English language).
Types of knowledge
1. Declarative Knowledge:
2. Procedural Knowledge:
3. Meta-knowledge:
4. Heuristic knowledge:
5. Structural knowledge:
There are mainly four ways of knowledge representation which are given as follows:
1. Logical Representation
2. Semantic Network Representation
3. Frame Representation
4. Production Rules
1. Logical Representation
Logical representation is a language with some concrete rules which deals with
propositions and has no ambiguity in representation. Logical representation means
drawing a conclusion based on various conditions. This representation lays down
some important communication rules. It consists of precisely defined syntax and
semantics which supports the sound inference. Each sentence can be translated into
logic using syntax and semantics.
Syntax: Syntaxes are the rules which decide how we can construct legal sentences
in logic. It determines which symbol we can use in knowledge representation. How to
write those symbols.
Semantics: Semantics are the rules by which we can interpret the sentence in the
logic. Semantic also involves assigning a meaning to each sentence.
a. Propositional Logics
b. Predicate logics
Example: Following are some statements which we need to represent in the form of
nodes and arcs.
Statements:
a. Jerry is a cat.
b. Jerry is a mammal
c. Jerry is owned by Priya.
d. Jerry is brown.
e. All Mammals are animals.
3. Frame Representation
Facets: The various aspects of a slot are known as Facets. Facets are features of
frames which enable us to put constraints on the frames. Example: IF-NEEDED facts
are called when data of any particular slot is needed. A frame may consist of any
number of slots, and a slot may include any number of facets and facets may have
any number of values. A frame is also known as slot-filter knowledge representation
in artificial intelligence.
Frames are derived from semantic networks and later evolved into our modern-day
classes and objects. A single frame is not very useful. Frames systems consist of a
collection of frames which are connected. In the frame, knowledge about an object or
event can be stored together in the knowledge base. The frame is a type of
technology which is widely used in various applications including Natural language
processing and machine visions.
4. Production Rules
Production rules system consists of (condition, action) pairs which mean, "If
condition then action". It has mainly three parts:
In production rules agent checks for the condition and if the condition exists then
production rule fires and corresponding action is carried out. The condition part of
the rule determines which rule may be applied to a problem. And the action part
carries out the associated problem-solving steps. This complete process is called a
recognize-act cycle.
If there is a new situation (state) generated, then multiple production rules will be
fired together, this is called conflict set. In this situation, the agent needs to select a
rule from these sets, and it is called a conflict resolution.
Example:
● IF (at bus stop AND bus arrives) THEN action (get into the bus)
● IF (on the bus AND paid AND empty seat) THEN action (sit down).
● IF (on bus AND unpaid) THEN action (pay charges).
● IF (bus arrives at destination) THEN action (get down from the bus).
1. Production rule system does not exhibit any learning capabilities, as it does
not store the result of the problem for future use.
2. During the execution of the program, many rules may be active hence
rule-based production systems are inefficient.
Example:
1. a) It is Sunday.
2. b) The Sun rises from West (False proposition)
3. c) 3+3= 7(False proposition)
4. d) 5 is a prime number.
What is Unification?
● The UNIFY algorithm is used for unification, which takes two atomic
sentences and returns a unifier for those sentences (If any exist).
● Unification is a key component of all first-order inference algorithms.
● It fails if the expressions do not match with each other.
● The substitution variables are called Most General Unifier or MGU.
Resolution
Bayes' theorem:
Bayes' theorem is also known as Bayes' rule, Bayes' law, or Bayesian reasoning,
which determines the probability of an event with uncertain knowledge. In probability
theory, it relates the conditional probability and marginal probabilities of two random
events. Bayes' theorem was named after the British mathematician Thomas Bayes.
The Bayesian inference is an application of Bayes' theorem, which is fundamental to
Bayesian statistics. It is a way to calculate the value of P(B|A) with the knowledge of
P(A|B). Bayes' theorem allows updating the probability prediction of an event by
observing new information of the real world.
Example: If cancer corresponds to one's age then by using Bayes' theorem, we can
determine the probability of cancer more accurately with the help of age.
Bayes' theorem can be derived using product rule and conditional probability of
event A with known event B:
Bayesian Network can be used for building models from data and experts opinions,
and it consists of two parts:
The generalised form of Bayesian network that represents and solves decision
problems under uncertain knowledge is known as an Influence diagram.