Ai Course File
Ai Course File
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
AI has many intersections with other disciplines, and many approaches to the AI problem
Motion
Formal:
Board Game-Playing, chess, checkers, gobblet Logic
Calculus Algebra
Expert:
Design, engineering, graphics Art, creativity
Music
2) Strong AI. The study and design of machines that simulate the human mind to perform intelligent tasks. Borrow many ideas from
psychology, neuroscience. Goal is to perform tasks the way a human might do them – which makes sense, since we do have models of
human thought and problem solving. Includes psychological ideas in STM, LTM, forgetting, language, genetics, etc. Assumes that the
physical symbol hypothesis holds.
Evolutionary AI. The study and design of machines that simulate simple creatures, and attempt to evolve and have
higher level emergent behavior. For example, ants, bees, etc.
Theoretical Foundations of AI
Philosophy - Logic methods of reasoning, mind as physical system foundations of learning, language, rationality
Mathematics - Formal representation and proof algorithms, computation, (un)decidability, (in)tractability, probability
Economics - Utility, decision theory, game theory.
Neuroscience - Physical substrate for mental activity
Psychology - Phenomena of perception and motor control, experimental techniques
Computer Engineering - Building fast computers
Control theory- Design systems that maximize an objective function over time
Linguistics - Knowledge representation, grammar
Abridged History of AI
1943 McCulloch & Pitts: Boolean circuit model of brain
1950 Turing's "Computing Machinery and Intelligence"
1956 Dartmouth meeting: "Artificial Intelligence"
adopted 1952—69 Look, Ma, no hands!
1950s Early AI programs, including Samuel's checkers program, Newell & Simon's Logic
Theorist, Gelernter's Geometry Engine
1965 Robinson's complete algorithm for logical reasoning
1966—73 AI discovers computational complexity Neural network research almost disappears
1969—79 Early development of knowledge-based systems
1980-- AI becomes an industry
1986-- Neural networks return to popularity
1987-- AI becomes a science
1995-- The emergence of intelligent agents, genetic algorithms
AI Applications
3. Expert Systems. An expert system is a computer program with deep knowledge in a specific niche area that provides assistance
to a user. Famous examples include DENDREAL, an expert system that inferred the structure of organic molecules from their
spectrographic information, and MYCIN.
4. Machine Learning. Systems that can automatically classify data and learn from new examples has become more popular,
especially as the Internet has grown and spawned applications that require personalized agents to learn a user’s interests.
6. Modeling Human Performance. As described earlier, machine intelligence need not pattern itself after human intelligence.
7. Planning and Robotics. Planning research began as an effort to design robots that could perform their task. For example, the
Sojourner robot on Mars was able to perform some of its own navigation tasks since the time delay to earth makes real-time control
impossible.
Languages and Environments. LISP and PROLOG were designed to help support AI, along with constructs such as object-
oriented design and knowledge bases.
Intelligent agent
In artificial intelligence, an intelligent agent (IA) is an autonomous entity which observes through sensors and acts upon
an environment using actuators (i.e. it is an agent) and directs its activity towards achieving goals (i.e. it
is rational). Intelligent agents may also learn or use knowledge to achieve their goals.
They may be very simple or very complex: a reflex machine such as a thermostat is an intelligent agent, as is a human being,
as is a community of human beings working together towards a goal.
Intelligent agents are often described schematically as an abstract
functional system similar to a computer program. For this reason, intelligent agents are sometimes called abstract intelligent
agents (AIA) to distinguish them from their real world implementations as computer systems, biological systems, or organizations. Some
definitions of intelligent agents emphasize their autonomy, and so prefer the term autonomous intelligent agents.
Agent function is an abstract concept as it could incorporate various principles of decision making like calculation
of utility of individual options, deduction over logic rules, fuzzy logic, etc. The program agent, instead, maps every possible
percept to an action.
The term percept to refer to the agent's perceptional inputs at any given instant. In the following figures an agent is anything
that can be viewed as perceiving its environment through sensors and acting upon that environment through actuators.
4. utility-based agents
5. learning agents
Simple reflex agents
Simple reflex agents act only on the basis of the current percept, ignoring the rest of the percept history. The agent function is based on
the condition-action rule: if condition then action.
This agent function only succeeds when the environment is fully observable. Some reflex agents can also contain information on their
current state which allows them to disregard conditions whose actuators are already triggered.
Infinite loops are often unavoidable for simple reflex agents operating in partially observable environments. Note: If the agent can
randomize its actions, it may be possible to escape from infinite loops.
state INTERPRET-INPUT(percept)
rule RULE-MATCH(state,rules)
― A simple reflex agent. It works by finding a rule whose condition matches the current situation (as defined by the
percept) and then doing the action associated with that rule.‖
A model-based reflex agent should maintain some sort of internal model that depends on the percept history and
thereby reflects at least some of the unobserved aspects of the current state. It then chooses an action in the same way as
the reflex agent.
function REFLEX-AGENT-WITH-STATE( percept) returns action
static: state, a description of the current world state
rules, a set of condition-action rules action, the most recent action initially none
action RULE-ACTION[rule]
state UPDATE-STATE(state, action)
return action
Goal-based agents
Goal-based agents further expand on the capabilities of the model-based agents, by using "goal" information.
Goal information describes situations that are desirable. This allows the agent a way to choose among multiple possibilities, selecting
the one which reaches a goal state.
Search and planning are the subfields of artificial intelligence devoted to finding action sequences that achieve the agent's goals.
In some instances the goal-based agent appears to be less efficient; it is more flexible because the knowledge that supports its decisions
is represented explicitly and can be modified.
Utility-based agents
Goal-based agents only distinguish between goal states and non-goal states.
It is possible to define a measure of how desirable a particular state is. This measure can be obtained through the use of a utility
function which maps a state to a measure of the utility of the state.
A more general performance measure should allow a comparison of different world states according to exactly how happy they would
make the agent.
The term utility can be used to describe how "happy" the agent is.
A utility-based agent has to model and keep track of its environment, tasks that have involved a great deal of research on perception,
representation, reasoning, and learning.
Learning agents
Learning has an advantage that it allows the agents to initially operate in unknown environments and to become more competent than
its initial knowledge alone might allow.
The most important distinction is between the "learning element", which is responsible for making improvements, and the
"performance element", which is responsible for selecting external actions.
The learning element uses feedback from the "critic" on how the agent is doing and determines how the performance element should
be modified to do better in the future.
The performance element is what we have previously considered to be the entire agent: it takes in percepts and decides on actions.
The last component of the learning agent is the "problem generator". It is responsible for suggesting actions that will lead to new and
informative experiences.
PROBLEMS, PROBLEM SPACES AND SEARCH
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 affect 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 solving has been the key area of concern for Artificial Intelligence.
Problem solving is a process of generating solutions from observed or given data. It is however
not always possible to use direct methods (i.e. go directly from data to solution). Instead,
problem solving often needs to use indirect or modelbased methods.
General Problem Solver (GPS) was a computer program created in 1957 by Simon and Newell
to build a universal problem solver machine. GPS was based on Simon and Newell’s theoretical
work on logic machines. GPS in principle can solve any formalized symbolic problem, such as
theorems proof and geometric problems and chess playing. GPS solved many simple problems,
such as the Towers of Hanoi, that could be sufficiently formalized, but GPS could not solve
any real-world problems.
Problem definitions
A problem is defined by its ‘elements’ and their ‘relations’. To provide a formal description of a
problem, we need to do the following:
a. Define a state space that contains all the possible configurations of the relevant
objects, including some impossible ones.
b. Specify one or more states that describe possible situations, from which the problem-
solving process may start. These states are called initial states.
c. Specify one or more states that would be acceptable solution to the problem.
The problem can then be solved by using the rules, in combination with an appropriate
control strategy, to move through the problem space until a path from an initial state to a
goal state is found. This process is known as ‘search’. Thus:
A problem space is represented by a directed graph, where nodes represent search state and paths
represent the operators applied to change the state.
A tree is a graph in which any two vertices are connected by exactly one path. Alternatively,
any connected graph with no cycles is a tree.
• Problem solving: The term, Problem Solving relates to analysis in AI. Problem solving may be
characterized as a systematic search through a range of possible actions to reach some predefined
goal or solution. Problem-solving methods are categorized as special purpose and general
purpose.
To solve the problem of playing a game, we require the rules of the game and targets for winning
as well as representing positions in the game. The opening position can be defined as the initial
state and a winning position as a goal state. Moves from initial state to other states leading to the
goal state follow legally. However, the rules are far too abundant in most games— especially in
chess, where they exceed the number of particles in the universe. Thus, the rules cannot be
supplied accurately and computer programs cannot handle easily. The storage also presents
another problem but searching can be achieved by hashing.
The number of rules that are used must be minimized and the set can be created by expressing
each rule in a form as possible. The representation of games leads to a state space representation
and it is common for well-organized games with some structure. This representation allows for
the formal definition of a problem that needs the movement from a set of initial positions to one
of a set of target positions. It means that the solution involves using known techniques and a
systematic search. This is quite a common method in Artificial Intelligence.
In this problem, we use two jugs called four and three; four holds a maximum of four gallons of
water and three a maximum of three gallons of water. How can we get two gallons of water in
the four jug?
The state space is a set of prearranged pairs giving the number of gallons of water in the pair of
jugs at any time, i.e., (four, three) where four = 0, 1, 2, 3 or 4 and three = 0, 1, 2 or 3.
The start state is (0, 0) and the goal state is (2, n) where n may be any but it is limited to three
holding from 0 to 3 gallons of water or empty. Three and four shows the name and numerical
number shows the amount of water in jugs for solving the water jug problem. The major
production rules for solving this problem are shown below:
Initial condition Goal comment
1. (four, three) if four < 4 (4, three) fill four from tap
2. (four, three) if three< 3 (four, 3) fill three from tap
3. (four, three) If four > 0 (0, three) empty four into drain
4. (four, three) if three > 0 (four, 0) empty three into drain
5. (four, three) if four + three<4 (four + three, 0) empty three into
four
6. (four, three) if four + three<3 (0, four + three) empty four into
three
7. (0, three) If three > 0 (three, 0) empty three into four
8. (four, 0) if four > 0 (0, four) empty four into three
9. (0, 2) (2, 0) empty three into four
10.(2, 0) (0, 2) empty four into three
11.(four, three) if four < 4 (4, three-diff) pour diff, 4-four, into
four from three
12.(three, four) if three < 3 (four-diff, 3) pour diff, 3-three, into
three from four and a solution is
given below four three rule
(Fig. 2.2 Production Rules for the Water Jug Problem)
The problem solved by using the production rules in combination with an appropriate control
strategy, moving through the problem space until a path from an initial state to a goal state is
found. In this problem solving process, search is the fundamental concept. For simple problems
it is easier to achieve this goal by hand but there will be cases where this is far too difficult.
Production systems provide appropriate structures for performing and describing search
processes. A production system has four basic components as enumerated below.
A set of rules each consisting of a left side that determines the applicability of the
rule and a right side that describes the operation to be performed if the rule is
applied.
A database of current facts established during the process of inference.
A control strategy that specifies the order in which the rules will be compared
with facts in the database and also specifies how to resolve conflicts in selection
of several rules or selection of more facts.
A rule firing module.
The production rules operate on the knowledge database. Each rule has a precondition—that is,
either satisfied or not by the knowledge database. If the precondition is satisfied, the rule can be
applied. Application of the rule changes the knowledge database. The control system chooses
which applicable rule should be applied and ceases computation when a termination condition on
the knowledge database is satisfied.
The 8-puzzle is a 3 × 3 array containing eight square pieces, numbered 1 through 8, and
one empty space. A piece can be moved horizontally or vertically into the empty space, in effect
exchanging the positions of the piece and the empty space. There are four possible moves, UP
(move the blank space up), DOWN, LEFT and RIGHT. The aim of the game is to make a
sequence of moves that will convert the board from the start state into the goal state:
This example can be solved by the operator sequence UP, RIGHT, UP, LEFT, DOWN.
The Missionaries and Cannibals problem illustrates the use of state space search for planning
under constraints:
Three missionaries and three cannibals wish to cross a river using a two person boat. If
at any time the cannibals outnumber the missionaries on either side of the river, they will eat
the missionaries. How can a sequence of boat trips be performed that will get everyone to the
other side of the river without any missionaries being eaten?
State representation:
Operators:
2.4.1 Control Strategies
The word ‘search’ refers to the search for a solution in a problem space.
• Search proceeds with different types of ‘search control strategies’.
• A strategy is defined by picking the order in which the nodes expand.
The Search strategies are evaluated along the following dimensions: Completeness, Time
complexity, Space complexity, Optimality (the search- related terms are first explained, and then
the search algorithms and control strategies are illustrated next).
Search-related terms
• Algorithm’s performance and complexity
Ideally we want a common measure so that we can compare approaches in order to select
the most appropriate algorithm for a given situation.
Performance of an algorithm depends on internal and external factors.
• ‘Big - O’ notation
The Big-O, theoretical measure of the execution of an algorithm, usually indicates the time or the
memory needed, given the problem size n, which is usually the number of items.
• Big-O notation
The Big-O notation is used to give an approximation to the run-time- efficiency of an algorithm;
the letter ‘O’ is for order of magnitude of operations or space at run-time.
• The Big-O of an Algorithm A
If an algorithm A requires time proportional to f(n), then algorithm A is said to be
of order f(n), and it is denoted as O(f(n)).
If algorithm A requires time proportional to n2, then the order of the algorithm is
said to be O(n2).
If algorithm A requires time proportional to n, then the order of the algorithm is
said to be O(n).
The function f(n) is called the algorithm’s growth-rate function. In other words, if an algorithm
has performance complexity O(n), this means that the run-time t should be directly proportional
to n, ie t • n or t = k n where k is constant of proportionality.
Similarly, for algorithms having performance complexity O(log2(n)), O(log N), O(N log N),
O(2N) and so on.
PROBLEM CHARACTERISTICS
Heuristics cannot be generalized, as they are domain specific. Production systems provide ideal
techniques for representing such heuristics in the form of IF-THEN rules. Most problems
requiring simulation of intelligence use heuristic search extensively. Some heuristics are used to
define the control structure that guides the search process, as seen in the example described
above. But heuristics can also be encoded in the rules to represent the domain knowledge. Since
most AI problems make use of knowledge and guided search through the knowledge, AI can be
described as the study of techniques for solving exponentially hard problems in polynomial time
by exploiting knowledge about problem domain.
To use the heuristic search for problem solving, we suggest analysis of the problem for the
following considerations:
Decomposability of the problem into a set of independent smaller subproblems
Possibility of undoing solution steps, if they are found to be unwise
Predictability of the problem universe
Possibility of obtaining an obvious solution to a problem without comparison of all other
possible solutions
Type of the solution: whether it is a state or a path to the goal state
Role of knowledge in problem solving
Nature of solution process: with or without interacting with the user
Problem Decomposition
Suppose we are trying to prove a mathematical theorem: first we proceed considering that
proving a lemma will be useful. Later we realize that it is not at all useful. We start with another
one to prove the theorem. Here we simply ignore the first method.
Consider the 8-puzzle problem to solve: we make a wrong move and realize that mistake. But
here, the control strategy must keep track of all the moves, so that we can backtrack to the initial
state and start with some new move.
Consider the problem of playing chess. Here, once we make a move we never recover from that
step. These problems are illustrated in the three important classes of problems mentioned below:
1. Ignorable, in which solution steps can be ignored. Eg: Theorem Proving
2. Recoverable, in which solution steps can be undone. Eg: 8-Puzzle
3. Irrecoverable, in which solution steps cannot be undone. Eg: Chess
Consider the 8-Puzzle problem. Every time we make a move, we know exactly what will happen.
This means that it is possible to plan an entire sequence of moves and be confident what the
resulting state will be. We can backtrack to earlier moves if they prove unwise.
Suppose we want to play Bridge. We need to plan before the first play, but we cannot play with
certainty. So, the outcome of this game is very uncertain. In case of 8-Puzzle, the outcome is
very certain. To solve uncertain outcome problems, we follow the process of plan revision as the
plan is carried out and the necessary feedback is provided. The disadvantage is that the planning
in this case is often very expensive.
We are interested to answer the question; it does not matter which path we follow. If we follow
one path successfully to the correct answer, then there is no reason to go back and check another
path to lead the solution.
Partially commutative, monotonic productions systems are useful for solving ignorable
problems. These are important from an implementation point of view without the ability to
backtrack to previous states when it is discovered that an incorrect path has been followed. Both
types of partially commutative production systems are significant from an implementation point;
they tend to lead to many duplications of individual states during the search process. Production
systems that are not partially commutative are useful for many problems in which permanent
changes occur.
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.
Finally in terms of data structures, considering the water jug as a typical problem do we use a
graph or tree? The breadth-first structure does take note of all nodes generated but the depth-first
one can be modified.
Check duplicate nodes
1. Observe all nodes that are already generated, if a new node is present.
2. If it exists add it to the graph.
3. If it already exists, then
a. 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.
b. 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.
Example: Tic-Tac-Toe
State spaces are good representations for board games such as Tic-Tac-Toe. The position of a
game can be explained by the contents of the board and the player whose turn is next. The board
can be represented as an array of 9 cells, each of which may contain an X or O or be empty.
• State:
Player to move next: X or O.
Board configuration:
Search Tree
The sequence of states formed by possible moves is called a search tree. Each level of the tree is
called a ply.
Since the same state may be reachable by different sequences of moves, the state space may in
general be a graph. It may be treated as a tree for simplicity, at the cost of duplicating states.
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.
Search Algorithms
Many traditional search algorithms are used in AI applications. For complex problems, the
traditional algorithms are unable to find the solutions within some practical time and space
limits. Consequently, many special techniques are developed, using heuristic functions.
The algorithms that use heuristic functions are called heuristic algorithms.
• Heuristic algorithms are not really intelligent; they appear to be intelligent because they
achieve better performance.
• Heuristic algorithms are more efficient because they take advantage of feedback from the
data to direct the search path.
• Uninformed search algorithms or Brute-force algorithms, search through the search space all
possible candidates for the solution checking whether each candidate satisfies the problem’s
statement.
• Informed search algorithms use heuristic functions that are specific to the problem, apply
them to guide the search through the search space to try to reduce the amount of time spent in
searching.
A good heuristic will make an informed search dramatically outperform any uninformed search:
for example, the Traveling Salesman Problem (TSP), where the goal is to find is a good solution
instead of finding the best solution.
In such problems, the search proceeds using current information about the problem to predict
which path is closer to the goal and follow it, although it does not always guarantee to find the
best possible solution. Such techniques help in finding a solution within reasonable time and
space (memory). Some prominent intelligent search algorithms are stated below:
1. Generate and Test Search
2. Best-first Search
3. Greedy Search
4. A* Search
5. Constraint Search
6. Means-ends analysis
There are some more algorithms. They are either improvements or combinations of these.
• Hierarchical Representation of Search Algorithms: A Hierarchical representation of most
search algorithms is illustrated below. The representation begins with two types of search:
• Uninformed Search: Also called blind, exhaustive or brute-force search, it uses no
information about the problem to guide the search and therefore may not be very efficient.
• Informed Search: Also called heuristic or intelligent search, this uses information about the
problem to guide the search—usually guesses the distance to a goal state and is therefore
efficient, but the search may not be always possible.
The first requirement is that it causes motion, in a game playing program, it moves on the board
and in the water jug problem, filling water is used to fill jugs. It means the control strategies
without the motion will never lead to the solution.
The second requirement is that it is systematic, that is, it corresponds to the need for global
motion as well as for local motion. This is a clear condition that neither would it be rational to
fill a jug and empty it repeatedly, nor it would be worthwhile to move a piece round and round
on the board in a cyclic way in a game. We shall initially consider two systematic approaches for
searching. Searches can be classified by the order in which operators are tried: depth-first,
breadth-first, bounded depth-first.
Breadth-first search
A Search strategy, in which the highest layer of a decision tree is searched completely before
proceeding to the next layer is called Breadth-first search (BFS).
• In this strategy, no viable solutions are omitted and therefore it is guaranteed that an optimal
solution is found.
• This strategy is often not feasible when the search space is large.
Algorithm
1. Create a variable called LIST and set it to be the starting state.
2. Loop until a goal state is found or LIST is empty, Do
a. Remove the first element from the LIST and call it E. If the LIST is empty, quit.
b. For every path each rule can match the state E, Do
(i) Apply the rule to generate a new state.
(ii) If the new state is a goal state, quit and return this state.
(iii) Otherwise, add the new state to the end of LIST.
Advantages
1. Guaranteed to find an optimal solution (in terms of shortest number of
steps to reach the goal).
2. Can always find a goal node if one exists (complete).
Disadvantages
1. High storage requirement: exponential with tree depth.
Depth-first search
A search strategy that extends the current path as far as possible before backtracking to the last
choice point and trying the next alternative path is called Depth-first search (DFS).
• This strategy does not guarantee that the optimal solution has been found.
• In this strategy, search reaches a satisfactory solution more rapidly than breadth first, an
advantage when the search space is large.
Algorithm
Depth-first search applies operators to each newly generated state, trying to drive directly toward
the goal.
1. If the starting state is a goal state, quit and return success.
2. Otherwise, do the following until success or failure is signalled:
a. Generate a successor E to the starting state. If there are no more successors, then signal failure.
b. Call Depth-first Search with E as the starting state.
c. If success is returned signal success; otherwise, continue in the loop.
Advantages
1. Low storage requirement: linear with tree depth.
2. Easily programmed: function call stack does most of the work of maintaining state of the
search.
Disadvantages
1. May find a sub-optimal solution (one that is deeper or more costly than the best solution).
2. Incomplete: without a depth bound, may not find a solution even if one exists.
2.4.2.3 Bounded depth-first search
Depth-first search can spend much time (perhaps infinite time) exploring a very deep path that
does not contain a solution, when a shallow solution exists. An easy way to solve this problem is
to put a maximum depth bound on the search. Beyond the depth bound, a failure is generated
automatically without exploring any deeper.
Problems:
1. It’s hard to guess how deep the solution lies.
2. If the estimated depth is too deep (even by 1) the computer time used is dramatically
increased, by a factor of bextra.
3. If the estimated depth is too shallow, the search fails to find a solution; all that computer time
is wasted.
Heuristics
A heuristic is a method that improves the efficiency of the search process. These are like tour
guides. There are good to the level that they may neglect the points in general interesting
directions; they are bad to the level that they may neglect points of interest to particular
individuals. Some heuristics help in the search process without sacrificing any claims to entirety
that the process might previously had. Others may occasionally cause an excellent path to be
overlooked. By sacrificing entirety it increases efficiency. Heuristics may not find the best
solution every time but guarantee that they find a good solution in a reasonable time. These are
particularly useful in solving tough and complex problems, solutions of which would require
infinite time, i.e. far longer than a lifetime for the problems which are not solved in any other
way.
Heuristic search
To find a solution in proper time rather than a complete solution in unlimited time we use
heuristics. ‘A heuristic function is a function that maps from problem state descriptions to
measures of desirability, usually represented as numbers’. Heuristic search methods use
knowledge about the problem domain and choose promising operators first. These heuristic
search methods use heuristic functions to evaluate the next state towards the goal state. For
finding a solution, by using the heuristic technique, one should carry out the following steps:
1. Add domain—specific information to select what is the best path to continue searching along.
2. Define a heuristic function h(n) that estimates the ‘goodness’ of a node n.
Specifically, h(n) = estimated cost(or distance) of minimal cost path from n to a goal state.
3. The term, heuristic means ‘serving to aid discovery’ and is an estimate, based on domain
specific information that is computable from the current state description of how close we are to
a goal.
Finding a route from one city to another city is an example of a search problem in which
different search orders and the use of heuristic knowledge are easily understood.
1. State: The current city in which the traveller is located.
2. Operators: Roads linking the current city to other cities.
3. Cost Metric: The cost of taking a given road between cities.
4. Heuristic information: The search could be guided by the direction of the goal city from the
current city, or we could use airline distance as an estimate of the distance to the goal.
Heuristic search techniques
For complex problems, the traditional algorithms, presented above, are unable to find the
solution within some practical time and space limits. Consequently, many special techniques are
developed, using heuristic functions.
• Blind search is not always possible, because it requires too much time or Space (memory).
Comparison of Algorithms
No knowledge about how far a node Guides search process toward goal
node from goal state
Prefers states (nodes) that lead
close to and not away from goal
state
Suppose there are N cities, then a solution would be to take N! possible combinations to find the
shortest distance to decide the required route. This is not efficient as with N=10 there are
36,28,800 possible routes. This is an example of combinatorial explosion.
There are better methods for the solution of such problems: one is called branch and bound.
First, generate all the complete paths and find the distance of the first complete path. If the next
path is shorter, then save it and proceed this way avoiding the path when its length exceeds the
saved shortest path length, although it is better than the previous method.
Generate-And-Test Algorithm
Generate-and-test search algorithm is a very simple algorithm that guarantees to find a solution if
done systematically and there exists a solution.
Algorithm: Generate-And-Test
1. Generate a possible solution.
2. Test to see if this is the expected solution.
3. If the solution has been found quit else go to step 1.
Potential solutions that need to be generated vary depending on the kinds of problems. For some
problems the possible solutions may be particular points in the problem space and for some
problems, paths from the start state.
Figure: Generate And Test
Generate-and-test, like depth-first search, requires that complete solutions be generated for
testing. In its most systematic form, it is only an exhaustive search of the problem space.
Solutions can also be generated randomly but solution is not guaranteed. This approach is what is
known as British Museum algorithm: finding an object in the British Museum by wandering
randomly.
Systematic Generate-And-Test
While generating complete solutions and generating random solutions are the two extremes there
exists another approach that lies in between. The approach is that the search process proceeds
systematically but some paths that unlikely to lead the solution are not considered. This
evaluation is performed by a heuristic function.
Depth-first search tree with backtracking can be used to implement systematic generate-and-test
procedure. As per this procedure, if some intermediate states are likely to appear often in the
tree, it would be better to modify that procedure to traverse a graph rather than a tree.
Generate-And-Test And Planning
Exhaustive generate-and-test is very useful for simple problems. But for complex problems even
heuristic generate-and-test is not very effective technique. But this may be made effective by
combining with other techniques in such a way that the space in which to search is restricted. An
AI program DENDRAL, for example, uses plan-Generate-and-test technique. First, the planning
process uses constraint-satisfaction techniques and creates lists of recommended and
contraindicated substructures. Then the generate-and-test procedure uses the lists generated and
required to explore only a limited set of structures. Constrained in this way, generate-and-test
proved highly effective. A major weakness of planning is that it often produces inaccurate
solutions as there is no feedback from the world. But if it is used to produce only pieces of
solutions then lack of detailed accuracy becomes unimportant.
Hill Climbing
Hill Climbing is heuristic search used for mathematical optimization problems in the field of
Artificial Intelligence .
Given a large set of inputs and a good heuristic function, it tries to find a sufficiently good
solution to the problem. This solution may not be the global optimal maximum.
In the above definition, mathematical optimization problems implies that hill climbing
solves the problems where we need to maximize or minimize a given real function by
choosing values from the given inputs. Example-Travelling salesman problem where we
need to minimize the distance traveled by salesman.
‘Heuristic search’ means that this search algorithm may not find the optimal solution to
the problem. However, it will give a good solution in reasonable time.
A heuristic function is a function that will rank all the possible alternatives at any
branching step in search algorithm based on the available information. It helps the
algorithm to select the best route out of possible routes.
Features of Hill Climbing
1. Variant of generate and test algorithm : It is a variant of generate and test algorithm. The
generate and test algorithm is as follows :
1. Simple Hill climbing : It examines the neighboring nodes one by one and selects the first
neighboring node which optimizes the current cost as next node.
Algorithm for Simple Hill climbing :
Step 1 : Evaluate the initial state. If it is a goal state then stop and return success. Otherwise,
make initial state as current state.
Step 2 : Loop until the solution state is found or there are no new operators present which can
be applied to current state.
a) Select a state that has not been yet applied to the current state and apply it to produce a
new state.
b) Perform these to evaluate new state
i. If the current state is a goal state, then stop and return success.
ii. If it is better than the current state, then make it current state and proceed further.
iii. If it is not better than the current state, then continue in the loop until a solution is found.
Step 3 : Exit.
2. Steepest-Ascent Hill climbing : It first examines all the neighboring nodes and then
selects the node closest to the solution state as next node.
Step 1 : Evaluate the initial state. If it is goal state then exit else make the current state as
initial state
Step 2 : Repeat these steps until a solution is found or current state does not change
i. Let ‘target’ be a state such that any successor of the current state will be better than it;
ii. for each operator that applies to the current state
a. apply the new operator and create a new state
b. evaluate the new state
c. if this state is goal state then quit else compare with ‘target’
d. if this state is better than ‘target’, set this state as ‘target’
e. if target is better than current state set current state to
Target Step 3 : Exit
3. Stochastic hill climbing : It does not examine all the neighboring nodes before deciding
which node to select .It just selects a neighboring node at random, and decides (based
on the amount of improvement in that neighbor) whether to move to that neighbor or to
examine another.
State Space diagram for Hill Climbing
State space diagram is a graphical representation of the set of states our search algorithm can
reach vs the value of our objective function(the function which we wish to maximize).
X- axis : denotes the state space ie states or configuration our algorithm may reach.
Y-axis : denotes the values of objective function corresponding to to a particular state.
The best solution will be that state space where objective function has maximum value(global
maximum).
In BFS and DFS, when we are at a node, we can consider any of the adjacent as next
node. So both BFS and DFS blindly explore paths without considering any cost function. The
idea of Best First Search is to use an evaluation function to decide which adjacent is most
promising and then explore. Best First Search falls under the category of Heuristic Search or
Informed Search.
We use a priority queue to store costs of nodes. So the implementation is a variation of BFS, we
just need to change Queue to PriorityQueue.
Algorithm:
Best-First-Search(Grah g, Node start)
1) Create an empty PriorityQueue
PriorityQueue pq;
2) Insert "start" in pq.
pq.insert(start)
3) Until PriorityQueue is empty
u = PriorityQueue.DeleteMin
If u is the goal
Exit
Else
Foreach neighbor v of u
If v "Unvisited"
Mark v "Visited"
pq.insert(v)
Mark v "Examined"
End procedure
Let us consider below example.
pq initially contains S
We remove s from and process unvisited
neighbors of S to pq.
pq now contains {A, C, B} (C is put
before B because C has lesser cost)
A* Search Algorithm
A* is a type of search algorithm. Some problems can be solved by representing the world in the
initial state, and then for each action we can perform on the world we generate states for what the
world would be like if we did so. If you do this until the world is in the state that we specified as
a solution, then the route from the start to this goal state is the solution to your problem.
In this tutorial I will look at the use of state space search to find the shortest path between
two points (pathfinding), and also to solve a simple sliding tile puzzle (the 8-puzzle). Let's
look at some of the terms used in Artificial Intelligence when describing this state space
search.
Some terminology
A node is a state that the problem's world can be in. In pathfinding a node would be just a 2d
coordinate of where we are at the present time. In the 8-puzzle it is the positions of all the tiles.
Next all the nodes are arranged in a graph where links between nodes represent valid steps in
solving the problem. These links are known as edges. In the 8-puzzle diagram the edges are
shown as blue lines. See figure 1 below.
State space search, then, is solving a problem by beginning with the start state, and then for each
node we expand all the nodes beneath it in the graph by applying all the possible moves that can
be made at each point.
At this point we introduce an important concept, the heuristic. This is like an algorithm, but with
a key difference. An algorithm is a set of steps which you can follow to solve a problem, which
always works for valid input. For example you could probably write an algorithm yourself for
multiplying two numbers together on paper. A heuristic is not guaranteed to work but is useful in
that it may solve a problem for which there is no algorithm.
We need a heuristic to help us cut down on this huge search problem. What we need is to use our
heuristic at each node to make an estimate of how far we are from the goal. In pathfinding we
know exactly how far we are, because we know how far we can move each step, and we can
calculate the exact distance to the goal.
But the 8-puzzle is more difficult. There is no known algorithm for calculating from a given
position how many moves it will take to get to the goal state. So various heuristics have been
devised. The best one that I know of is known as the Nilsson score which leads fairly directly to
the goal most of the time, as we shall see.
Cost
When looking at each node in the graph, we now have an idea of a heuristic, which can estimate
how close the state is to the goal. Another important consideration is the cost of getting to where
we are. In the case of pathfinding we often assign a movement cost to each square. The cost is
the same then the cost of each square is one. If we wanted to differentiate between terrain types
we may give higher costs to grass and mud than to newly made road. When looking at a node we
want to add up the cost of what it took to get here, and this is simply the sum of the cost of this
node and all those that are above it in the graph.
8 Puzzle
Let's look at the 8 puzzle in more detail. This is a simple sliding tile puzzle on a 3*3 grid where
one tile is missing and you can move the other tiles into the gap until you get the puzzle into the
goal position. See figure 1.
There are 362,880 different states that the puzzle can be in, and to find a solution the search has
to find a route through them. From most positions of the search the number of edges (that's the
blue lines) is two. That means that the number of nodes you have in each level of the search is
2^d where d is the depth. If the number of steps to solve a particular state is 18, then that�s
262,144 nodes just at that level.
The 8 puzzle game state is as simple as representing a list of the 9 squares and what's in them.
Here are two states for example; the last one is the GOAL state, at which point we've found
the solution. The first is a jumbled up example that you may start from.
Pathfinding
In a video game, or some other pathfinding scenario, you want to search a state space and find
out how to get from somewhere you are to somewhere you want to be, without bumping into
walls or going too far. For reasons we will see later, the A* algorithm will not only find a path,
if there is one, but it will find the shortest path. A state in pathfinding is simply a position in the
world. In the example of a maze game like Pacman you can represent where everything is using
a simple 2d grid. The start state for a ghost say, would be the 2d coordinate of where the ghost is
at the start of the search. The goal state would be where pacman is so we can go and eat him.
There is also example code to do pathfinding on the github site.
f=g+h
Using the OPEN and CLOSED list lets us be more selective about what we look at next in the
search. We want to look at the best nodes first. We will give each node a score on how good we
think it is. This score should be thought of as the cost of getting from the node to the goal plus
the cost of getting to where we are. Traditionally this has been represented by the letters f, g and
h. 'g' is the sum of all the costs it took to get here, 'h' is our heuristic function, the estimate of
what it will take to get to the goal. 'f' is the sum of these two. We will store each of these in our
nodes.
Using the f, g and h values the A* algorithm will be directed, subject to conditions we will look
at further on, towards the goal and will find it in the shortest route possible.
So far we have looked at the components of the A*, let's see how they all fit together to make the
algorithm :
Pseudocode
Hopefully the ideas we looked at in the preceding paragraphs will now click into place as we
look at the A* algorithm pseudocode. You may find it helpful to print this out or leave the
window open while we discuss it.
To help make the operation of the algorithm clear we will look again at the 8-puzzle problem in
figure 1 above. Figure 3 below shows the f,g and h scores for each of the tiles.
Figure 3 : 8-Puzzle state space showing f,g,h scores
First of all look at the g score for each node. This is the cost of what it took to get from the start
to that node. So in the picture the center number is g. As you can see it increases by one at each
level. In some problems the cost may vary for different state changes. For example in
pathfinding there is sometimes a type of terrain that costs more than other types.
Next look at the last number in each triple. This is h, the heuristic score. As I mentioned above I
am using a heuristic known as Nilsson's Sequence, which converges quickly to a correct solution
in many cases. Here is how you calculate this score for a given 8-puzzle state :
Advantages:
It is the best one from other techniques. It is used to solve very complex problems.
It is optimally efficient, i.e. there is no other optimal algorithm guaranteed to expand fewer nodes
than A*.
Disadvantages:
This algorithm is complete if the branching factor is finite and every action has fixed cost.
The speed execution of A* search is highly dependant on the accuracy of the heuristic algorithm
that is used to compute h (n).
AO* Search: (And-Or) Graph
The Depth first search and Breadth first search given earlier for OR trees or graphs can be easily
adopted by AND-OR graph. The main difference lies in the way termination conditions are
determined, since all goals following an AND nodes must be realized; where as a single goal
node following an OR node will do. So for this purpose we are using AO* algorithm.
Like A* algorithm here we will use two arrays and one heuristic function.
OPEN:
It contains the nodes that has been traversed but yet not been marked solvable or unsolvable.
CLOSE:
Algorithm:
Step 3: Select a node n that is both on OPEN and a member of T0. Remove it from OPEN and
place it in
CLOSE
Step 4: If n is the terminal goal node then leveled n as solved and leveled all the ancestors of n
as solved. If the starting node is marked as solved then success and exit.
Step 5: If n is not a solvable node, then mark n as unsolvable. If starting node is marked as
unsolvable, then return failure and exit.
Step 6: Expand n. Find all its successors and find their h (n) value, push them into OPEN.
Step 8: Exit.
Implementation:
Step 1:
In the above graph, the solvable nodes are A, B, C, D, E, F and the unsolvable nodes are G, H.
Take A as the starting node. So place A into OPEN.
Advantages:
It is an optimal algorithm.
If traverse according to the ordering of nodes. It can be used for both OR and AND graph.
Disadvantages:
Sometimes for unsolvable nodes, it can’t find the optimal path. Its complexity is than other
algorithms.
PROBLEM REDUCTION
When a problem can be divided into a set of sub problems, where each sub problem can be
solved separately and a combination of these will be a solution, AND-OR graphs or AND - OR
trees are used for representing the solution. The decomposition of the problem or problem
reduction generates AND arcs. One AND are may point to any number of successor nodes. All
these must be solved so that the arc will rise to many arcs, indicating several possible solutions.
Hence the graph is known as AND - OR instead of AND. Figure shows an AND - OR graph.
An algorithm to find a solution in an AND - OR graph must handle AND area appropriately. A*
algorithm can not search AND - OR graphs efficiently. This can be understand from the give
figure.
In figure (a) the top node A has been expanded producing two area one leading to B and leading
to C-D . the numbers at each node represent the value of f ' at that node (cost of getting to the
goal state from current state). For simplicity, it is assumed that every operation(i.e. applying a
rule) has unit cost, i.e., each are with single successor will have a cost of 1 and each of its
components. With the available information till now , it appears that C is the most promising
node to expand since its f ' = 3 , the lowest but going through B would be better since to use C
we must also use D' and the cost would be 9(3+4+1+1). Through B it would be 6(5+1).
Thus the choice of the next node to expand depends not only n a value but also on whether that
node is part of the current best path form the initial mode. Figure (b) makes this clearer. In
figure the node G appears to be the most promising node, with the least f ' value. But G is not on
the current beat path, since to use G we must use GH with a cost of 9 and again this demands
that arcs be used (with a cost of 27). The path from A through B, E-F is better with a total cost
of (17+1=18). Thus we can see that to search an AND-OR graph, the following three things
must be done.
1. traverse the graph starting at the initial node and following the current best path,
and accumulate the set of nodes that are on the path and have not yet been expanded.
2. Pick one of these unexpanded nodes and expand it. Add its successors to the graph
and computer f ' (cost of the remaining distance) for each of them.
3. Change the f ' estimate of the newly expanded node to reflect the new information
produced by its successors. Propagate this change backward through the graph. Decide which
of the current best path.
The propagation of revised cost estimation backward is in the tree is not necessary in A*
algorithm. This is because in AO* algorithm expanded nodes are re-examined so that the current
best path can be selected. The working of AO* algorithm is illustrated in figure as follows:
Referring the figure. The initial node is expanded and D is Marked initially as promising node. D
is expanded producing an AND arc E-F. f ' value of D is updated to 10. Going backwards we can
see that the AND arc B-C is better . it is now marked as current best path. B and C have to be
expanded next. This process continues until a solution is found or all paths have led to dead ends,
indicating that there is no solution. An A* algorithm the path from one node to the other is
always that of the lowest cost and it is independent of the paths through other nodes.
The algorithm for performing a heuristic search of an AND - OR graph is given below. Unlike
A* algorithm which used two lists OPEN and CLOSED, the AO* algorithm uses a single
structure G. G represents the part of the search graph generated so far. Each node in G points
down to its immediate successors and up to its immediate predecessors, and also has with it the
value of h' cost of a path from itself to a set of solution nodes. The cost of getting from the start
nodes to the current node "g" is not stored as in the A* algorithm. This is because it is not
possible to compute a single such value since there may be many paths to the same state. In AO*
algorithm serves as the estimate of goodness of a node. Also a there should value called
FUTILITY is used. The estimated cost of a solution is greater than FUTILITY then the search is
abandoned as too expansive to be practical.
For representing above graphs AO* algorithm is as follows
AO* ALGORITHM:
1. Let G consists only to the node representing the initial state call this node INTT. Compute
h' (INIT).
2. Until INIT is labeled SOLVED or hi (INIT) becomes greater than FUTILITY, repeat the
following procedure.
(I) Trace the marked arcs from INIT and select an unbounded node NODE.
(II) Generate the successors of NODE . if there are no successors then assign FUTILITY as
h' (NODE). This means that NODE is not solvable. If there are successors then for
each
one
called SUCCESSOR, that is not also an ancester of NODE do the following
(b) if successor is not a terminal node, mark it solved and assign zero to its h ' value.
(III) propagate the newly discovered information up the graph by doing the following . let S be
a set of nodes that have been marked SOLVED. Initialize S to NODE. Until S is empty
repeat
the following procedure;
(b)compute h' of each of the arcs emerging from CURRENT , Assign minimum h' to
CURRENT.
(c) Mark the minimum cost path a s the best out of CURRENT.
(d)Mark CURRENT SOLVED if all of the nodes connected to it through the new marked
are have been labeled SOLVED.
(e) If CURRENT has been marked SOLVED or its h ' has just changed, its new status
must
be propagate backwards up the graph . hence all the ancestors of CURRENT are added
to S.
(Refered From Artificial Intelligence TMH)
2. Using the search tree, compute the most promising solution tree TP .
3. Select node n that is both on open and a part of tp, remove n from open and place it no closed.
4. If n is a goal node, label n as solved. If the start node is solved, exit with success where tp
is the solution tree, remove all nodes from open with a solved ancestor.
5. If n is not solvable node, label n as unsolvable. If the start node is labeled as unsolvable, exit
with failure. Remove all nodes from open ,with unsolvable ancestors.
6. Otherwise, expand node n generating all of its successor compute the cost of for each newly
generated node and place all such nodes on open.
7. Go back to step(2)
CONSTRAINT SATISFACTION:-
Many problems in AI can be considered as problems of constraint satisfaction, in which the goal
state satisfies a given set of constraint. constraint satisfaction problems can be solved by using
any of the search strategies. The general form of the constraint satisfaction procedure is as
follows:
Until a complete solution is found or until all paths have led to lead ends, do
2. Apply the constraint inference rules to the selected node to generate all possible new
constraints.
3. If the set of constraints contains a contradiction, then report that this path is a dead end.
5. If neither a constraint nor a complete solution has been found then apply the rules to
generate new partial solutions. Insert these partial solutions into the search graph.
SEND
+ MORE
----------
MONEY
----------
Assign decimal digit to each of the letters in such a way that the answer to the problem is correct
to the same letter occurs more than once , it must be assign the same digit each time . no two
different letters may be assigned the same digit. Consider the crypt arithmetic problem.
SEND
+ MORE
-----------
MONEY
-----------
CONSTRAINTS:-
2. Assumption can be made at various levels such that they do not contradict each other.
Goal State: the digits to the letters must be assigned in such a manner so that the sum is satisfied.
Solution Process:
1. initial guess m=1 because the sum of two single digits can generate at most a carry '1'.
2. When n=1 o=0 or 1 because the largest single digit number added to m=1 can generate the
sum of either 0 or 1 depend on the carry received from the carry sum. By this we conclude
that o=0 because m is already 1 hence we cannot assign same digit another letter(rule no.)
3. We have m=1 and o=0 to get o=0 we have s=8 or 9, again depending on the carry
received from the earlier sum.
The same process can be repeated further. The problem has to be composed into various
constraints. And each constraints is to be satisfied by guessing the possible digits that the letters
can be assumed that the initial guess has been already made . rest of the process is being shown
in the form of a tree, using depth-first search for the clear understandability of the solution
process.
D>6(Controduction)
MEANS - ENDS ANALYSIS:-
Most of the search strategies either reason forward of backward however, often a mixture o the
two directions is appropriate. Such mixed strategy would make it possible to solve the major
parts of problem first and solve the smaller problems the arise when combining them together.
Such a technique is called "Means - Ends Analysis".
The means -ends analysis process centers around finding the difference between current state and
goal state. The problem space of means - ends analysis has an initial state and one or more goal
state, a set of operate with a set of preconditions their application and difference functions that
computes the difference between two state a(i) and s(j). A problem is solved using means - ends
analysis by
1. Computing the current state s1 to a goal state s2 and computing their difference D12.
2. Satisfy the preconditions for some recommended operator op is selected, then to reduce
the difference D12.
3. The operator OP is applied if possible. If not the current state is solved a goal is created and
means- ends analysis is applied recursively to reduce the sub goal.
4. If the sub goal is solved state is restored and work resumed on the original problem.
( the first AI program to use means - ends analysis was the GPS General problem solver)
means- ends analysis I useful for many human planning activities. Consider the example of
planing for an office worker. Suppose we have a different table of three rules:
1. If in out current state we are hungry , and in our goal state we are not hungry , then either
the "visit hotel" or "visit Canteen " operator is recommended.
2. If our current state we do not have money , and if in your goal state we have money, then
the "Visit our bank" operator or the "Visit secretary" operator is recommended.
3. If our current state we do not know where something is , need in our goal state we do
know, then either the "visit office enquiry" , "visit secretary" or "visit co worker " operator is
recommended.
Constraint satisfaction
Constraint satisfaction is the process of finding a solution to a set of constraints that impose conditions that
the variables must satisfy. A solution is therefore a set of values for the variables that satisfies all constraints.
Often used are constraints on a finite domain, to the point that constraint satisfaction problems are typically identified with
problems based on constraints on a finite domain.
Such problems are usually solved via search, in particular a form of backtracking or local search.
Constraint satisfaction problem
Constraint satisfaction problems (CSPs) are mathematical problems defined as a set of objects whose state must satisfy a
number of constraints or limitations.
CSPs represent the entities in a problem as a homogeneous collection of finite constraints over variables, which are solved
by constraint satisfaction methods.
A constraint satisfaction problem on such domain contains a set of variables whose values can only be taken from the domain,
and a set of constraints, each constraint specifying the allowed values for a group of variables.
A solution to this problem is an evaluation of the variables that satisfies all constraints.
A solution is a way for assigning a value to each variable in such a way that all constraints are satisfied by these values.
Examples of simple problems that can be modeled as a constraint satisfaction problem
Eight queens puzzle
Map coloring problem
logic puzzles
Formal definition
Formally, a constraint satisfaction problem is defined as a triple , where
is a set of variables,
Resolution of CSPs
Constraint satisfaction problems on finite domains are typically solved using a form of search.
The most used techniques are variants of backtracking, constraint propagation, and local search.
Backtracking is a recursive algorithm. It maintains a partial assignment of the variables. Initially, all variables are unassigned. At
each step, a variable is chosen, and all possible values are assigned to it in turn.
For each value, the consistency of the partial assignment with the constraints is checked; in case of consistency,
a recursive call is performed.
When all values have been tried, the algorithm backtracks.
In this basic backtracking algorithm, consistency is defined as the satisfaction of all constraints whose variables are all
assigned.
Constraint propagation techniques are methods used to modify a constraint satisfaction problem.
More precisely, they are methods that enforce a form of local consistency, which are conditions related to the consistency of
a group of variables and/or constraints.
Constraint propagation has various uses. First, it turns a problem into one that is equivalent but is usually simpler to solve.
Second, it may prove satisfiability or unsatisfiability of problems.
Local search methods are incomplete satisfiability algorithms. They may find a solution of a problem, but they may fail even if
the problem is satisfiable.
They work by iteratively improving a complete assignment over the variables.
At each step, a small number of variables are changed value, with the overall aim of increasing the number of constraints
satisfied by this assignment.
Example 1: The n-Queen problem: The local condition is that no two queens attack each other, i.e. are on the same row, or
column, or diagonal.
Example 2: A cryptography problem: In the following pattern
SEND
MOR
E
=========
MONEY
Example 4: A map coloring problem: We are given a map, i.e. a planar graph, and we are told to color it using three colors,
green, red, and blue, so that no two neighboring countries have the same color.
Alpha-Beta Pruning
Alpha-beta pruning is a modified version of the minimax algorithm. It is an optimization technique for the
minimax algorithm.
As we have seen in the minimax search algorithm that the number of game states it has to examine are
exponential in depth of the tree. Since we cannot eliminate the exponent, but we can cut it to half. Hence
there is a technique by which without checking each node of the game tree we can compute the correct
minimax decision, and this technique is called pruning. This involves two threshold parameter Alpha and
beta for future expansion, so it is called alpha-beta pruning. It is also called as Alpha-Beta Algorithm.
Alpha-beta pruning can be applied at any depth of a tree, and sometimes it not only prune the tree leaves
but also entire sub-tree.
The two-parameter can be defined as:
1. 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 -∞.
2. 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 algorithm
slow. Hence by pruning these nodes, it makes the algorithm fast.
α>=β
Knowledge representation and reasoning (KR, KRR) is the part of Artificial intelligence which concerned
with AI agents thinking and how thinking contributes to intelligent behavior of agents.
It is responsible for representing information about the real world so that a computer can understand and
can utilize this knowledge to solve the complex real world problems such as diagnosis a medical condition
or communicating with humans in natural language.
It is also a way which describes how we can represent knowledge in artificial intelligence. Knowledge
representation is not just storing data into some database, but it also enables an intelligent machine to learn
from that knowledge and experiences so that it can behave intelligently like a human.
What to Represent:
Following are the kind of knowledge which needs to be represented in AI systems:
Object: All the facts about objects in our world domain. E.g., Guitars contains strings, trumpets are brass
instruments.
Events: Events are the actions which occur in our world.
Performance: It describe behavior 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).
1. Logical Representation
2. Semantic Network Representation
3. Frame Representation
4. Production Rules
Example: Following are some statements which we need to represent in the form of nodes and arcs.
Statements:
1. Jerry is a cat.
2. Jerry is a mammal
3. Jerry is owned by Priya.
4. Jerry is brown colored.
5. All Mammals are animal.
Frame Representation
A frame is a record like structure which consists of a collection of attributes and its values to describe an entity in
the world. Frames are the AI data structure which divides knowledge into substructures by representing
stereotypes situations. It consists of a collection of slots and slot values. These slots may be of any type and sizes.
Slots have names and values which are called facets.
Facets: The various aspects of a slot is 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 much useful. Frames system 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.
5+9 =14
11 + 9 = 17
It is raining
It is cold
Come here
Stand up
X is less than 5
It is coldCOLD
Propositional logic has very limited expressive power e.g. Search a candle in all locality shops has a clear
meaning to search all shops in the locality for candle. But propositional logic will require separate
statement for each shop
Propositions could be deceptive or extremely difficult to draw a meaningful conclusion e.g. IRFANMAN
and INZMAMMAN produce totally different assertion
Propositional logic assumes world is all full of facts so constitute wffs accordingly
Variables: x,y,z,..
A predicate with one argument shows property of the bracketed argument or object e.g. teacher(Mukesh)
A predicate with two arguments relates the arguments with each other e.g. Brother(Mukesh, Suresh