0% found this document useful (0 votes)
98 views28 pages

Artificial Intelligence

The document discusses problem solving using search algorithms in artificial intelligence. It explains that problem solving involves defining an initial state, operators to modify the state, and a goal state. It then describes breadth-first search and depth-first search algorithms. Breadth-first search systematically explores all nodes at each depth level from the start node, while depth-first search follows branches as deep as possible before backtracking. Both algorithms are used to traverse state spaces represented as graphs or trees to find solutions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
98 views28 pages

Artificial Intelligence

The document discusses problem solving using search algorithms in artificial intelligence. It explains that problem solving involves defining an initial state, operators to modify the state, and a goal state. It then describes breadth-first search and depth-first search algorithms. Breadth-first search systematically explores all nodes at each depth level from the start node, while depth-first search follows branches as deep as possible before backtracking. Both algorithms are used to traverse state spaces represented as graphs or trees to find solutions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 28

‫الذكاء أالصطناعي‬

‫الملزمة الثانية‬ ‫المرحلة الثالثة‬


Almustaqbal university college
‫م أحمد عدنان المحنا‬.‫م‬

1. Problem Solving using Search


The focus of much AI research has been on solving problems.
Much of the point of the AI research was to understand “how” to
solve the problem, not just to get a solution. So seemingly simple
problems—puzzles, games, stacking blocks—were the focus of AI
programs. And one of the first areas of work, general problem-
solving methods, highlighted a major barrier to artificial
intelligence software. How do you represent a problem so that the
computer can solve it? Even before that, how do you define the
problem with enough precision so that you can figure out how to
represent it?

Steps of solving the problem are:-


a- Clearly and succinctly define what it is we are
trying to do.
b- Clarifying of how to represent our problem “representation” so
that we can solve it using search techniques.
c- Which search techniques are best to solve the problem?
We explore one of the primary problem representations, the state-space
approach.

Example : Suppose that the problem we want to solve deals with playing
and winning a game. This game could be a simple one such as tic-
tac-toe or a more complex one such as checkers, chess, or
backgammon

To solve each problem in AI, we need these Steps:-


 initial state, which in the case of tic-tac-toe could be a 3 by 3
matrix filled with spaces (or empty markers).
 Operators (Control Strategy) : This can be used to modify the

current state, thereby creating a new state. In our case, this would
be a player marking an empty space with either an X or an O.
The combination of the initial state and the set of operators make up
the state space of the problem. The sequence of states produced by the
valid application of operators from the initial state is called the path in
the state space.
 State space search characterizes problem solving as the process of
finding a solution path form the start state to a goal

 goal state: A goal may describe a state, such as winning board in


tic-tac-toe.
In tic-tac-toe a goal state is when any row, column, or diagonal
consists of all Xs or Os. In this simple example, we can check the
tic-tac-toe board to see if either player has won by explicitly testing
for our goal condition. In more complicated problems, defining the
goal test may be a substantial problem in itself.

In many search problems, we are not only interested in reaching a goal


state, we would like to reach it with the lowest possible cost (or the
maximum profit). Thus, we can compute a cost as we apply operators and
transition from state to state. This path cost or cost function is usually
denoted by g. Given a problem which can be represented by a set of states
and operators and then solved using a search algorithm, we can compare
the quality of the solution by measuring the path cost. In the case of tic-
tac-toe we have a limited search space.

However, for many real-world problems the search space can grow very
large, so we need algorithms to deal with that.

 it causes motion or traversal of the state space, and


 it does so in a controlled or systematic manner
 Random search may work in some problems, but in general, we

need to search in an organized, methodical way. If we have a


systematic search strategy that does not use information about the
problem to help direct the search, it is called brute-force,
uninformed, or blind search. The only difference between the
different brute-force search techniques is the order in which nodes
are expanded. But even slight changes in the order can have a
significant impact on the behavior of the algorithm.
 Search algorithms which use information about the problem, such

as the cost or distance to the goal state, are called heuristic,


informed, or directed search. The primary advantage of heuristic
search algorithms is that we can make better choices concerning
which node to expand next. This substantially improves the
efficiency of the search algorithms.

2. Characteristics of Search Algorithms :

 An algorithm is optimal if it will find the best solution from

among several possible solutions.


 A strategy is complete if it guarantees that it will find a
solution if one exists.
 The complexity of the algorithm, in terms of time
complexity (how long it takes to find a solution)
 space complexity (how much memory it requires)
Example: Having an optimal search algorithm that runs
forever has little practical value. Nor does having a complete
algorithm that is a memory hog, if it runs out of memory just
before it finds the solution.
Example : 8 puzzle game

• states: locations of tiles


• Initial state: any state
• actions: move blank left, right, up, down
• goal test: goal state (given)
• path cost: 1 per move

3. Search Strategies

In this section we examine two basic search techniques used to solve


problems in AI, breadth-first search and depth-first search. Later we will
explore enhancements to these algorithms, but first we need to make sure
we understand how these basic approaches work. We will work through
several examples, but the steps of these two algorithms are :-

 Breadth-First Search

The breadth-first search algorithm searches a state-space by constructing


a hierarchical tree structure consisting of a set of nodes and links. The
algorithm defines a way to move through the tree structure, examining the
values at nodes in a controlled and systematic way, so that we can find a
node which offers a solution to the problem we have represented using
the tree-structure.
The algorithm follows:

1. Create a queue and add the first Node to it.


2. Loop :
• If the queue is empty, quit.
• Remove the first Node from the queue. If it is not a goal state
• If the Node contains the goal state, then exit with the Node as the
solution.
• For each child of the current Node: Add the new state to the
back of the queue.

 Depth-First Search

Depth-first search is another way to systematically traverse a tree


structure to find a goal or solution node. Instead of completely searching
each level of the tree before going deeper, the depth-first algorithm
follows a single branch of the tree down as many levels as possible until
we either reach a solution or a dead end. The algorithm follows:

1. Create a queue and add the first SearchNode to it.


2. Loop:
• If the queue is empty, quit.
• Remove the first SearchNode from the queue.
• If the SearchNode contains the goal state, then exit with the
SearchNode as the solution.
• For each child of the current SearchNode: Add the new state to
the front of the queue.
‫م أحمد المحنا‬.‫م‬
‫الذكاء االصطناعي‬
‫الملزمة الثالثة‬ ‫المرحله الثالثة‬
Almustaqbal university college

Problem Solving using Search


The breadth-first algorithm spreads out in a uniform manner from the
start node. From the start, it looks at each node one edge away. Then it
moves out from those nodes to all nodes two edges away from the start.
This continues until either the goal node is found or the entire tree is
searched.
Characteristics of breadth-first algorithm
Breadth-first search is complete; It will find a solution if one exists.
 But it is neither optimal in the general case (it won’t find the best solution, just
the first one that matches the goal state),
 It doesn’t have good time or space complexity (it grows exponentially in time
and memory consumption).
Example
A map like the one in Figure below can be naturally represented by a graph data
structure, where the cities names are the nodes, and the major roadways between
cities are the links or edges of the graph. So, from a programming perspective, our
problem is to traverse a graph data structure in a systematic way until we either find
the goal city or exhaust all possibilities. Hopefully having the entire state-space
shown on a map will make understanding the operations of the search algorithms
easier. In more complex problems, all we have is the single start state and a set of
operators which are used to generate more and more new states. The search
algorithms work the same way, but conceptually, we are growing or expanding the
graph, instead of having it specified at the start. Map of midwestern U.S. cities is
illustrated below:-

The breadth-first algorithm spreads out in a uniform manner from the start node. From
the start, it looks at each node one edge away. Then it moves out from those nodes to
all nodes two edges away from the start. This continues until either the goal node is
found or the entire tree is searched.
‫م أحمد المحنا‬.‫م‬
‫الذكاء االصطناعي‬
‫الملزمة الثالثة‬ ‫المرحله الثالثة‬
Almustaqbal university college

Let’s walk through an example to see how breadth-first search could find a city on our
map.
1- Our search begins in Rochester (Start State), and we want to know if we can
get to Wausau (Goal State) from there.
2- The Rochester node is placed on the queue in step 1 in previous algorithm.
Next we enter our search loop at step 2. Queue=[ Rochester]
3- We remove Rochester, the first node from the queue. Rochester does not
contain our goal state (Wausau) so we expand it by taking each child node in
Rochester, and adding them to the back of the queue. Queue= [ Sioux Falls,
Minneapolis, LaCrosse, and Dubuque ].
4- We remove the first node from the queue (Sioux Falls) and test it to see if it is
our goal state. It is not, so we expand it, adding Fargo and Rochester to the
end of our queue, which now contains [Minneapolis, LaCrosse, Dubuque,
Fargo, and Rochester].

5- We remove Minneapolis, the goal test fails, and we expand that node, adding
St.Cloud, Wausau, Duluth, LaCrosse, and Rochester to the search queue,
now holding [ LaCrosse, Dubuque, Fargo, Rochester, St.Cloud, Wausau,
Duluth, LaCrosse, and Rochester ].

6- We test LaCrosse and then expand it, adding Minneapolis, GreenBay,


Madison, Dubuque, and Rochester to the list, which has now grown to
[ Dubuque, Fargo, Rochester, St.Cloud, Wausau, Duluth, LaCrosse,
Rochester, Minneapolis, GreenBay, Madison, Dubuque, and Rochester].
We remove Dubuque and add Rochester, LaCrosse, and Rockford to the
search queue.
‫م أحمد المحنا‬.‫م‬
‫الذكاء االصطناعي‬
‫الملزمة الثالثة‬ ‫المرحله الثالثة‬
Almustaqbal university college

7- At this point, we have tested every node which is one level in the tree away
from the start node (Rochester). Our search queue contains the following
nodes: [Fargo, Rochester, St.Cloud, Wausau, Duluth, LaCrosse,
Rochester, Minneapolis, GreenBay, Madison, Dubuque, Rochester,
Rochester, LaCrosse, and Rockford].
8- We remove Fargo, which is two levels away from Rochester, and add Grand
Forks, St. Cloud, and Sioux Falls.
9- Then we test and expand Rochester (Rochester to Minneapolis to Rochester is
two levels away from our start). Next is St. Cloud; again we expand that node.
10- Finally, we get to Wausau; our goal test succeeds and we declare success.
11- Our search order was Rochester, Sioux Falls, Minneapolis, LaCrosse,
Dubuque, Fargo, Rochester, St. Cloud, and Wausau as shown below:-

Note that this trace could have been greatly simplified by keeping track of nodes
which had been tested and expanded. This would have cut down on our time and
space complexity.
Characteristics of Depth First Search

The depth-first algorithm searches from the start or root node all the way
down to a leaf node. If it does not find the goal node, it backtracks up the tree
and searches down the next untested path until it reaches the next leaf.
If you imagine a large tree, the depth-first algorithm may spend a large amount
of time searching the paths on the lower left when the answer is really in the
lower right.
Depth-first search is a brute-force method, it will blindly follow this search
pattern until it comes across a node containing the goal state, or it searches the
entire tree.
Depth-first search has lower memory requirements than breadth-first search,
It is neither complete nor optimal.
‫م أحمد المحنا‬.‫م‬
‫الذكاء االصطناعي‬
‫الملزمة الثالثة‬ ‫المرحله الثالثة‬
Almustaqbal university college

Example

Let’s walk through a simple example of how depth-first search would work if we
started in Rochester and wanted to see if we could get to Wausau.

Initial State= (Rochester) and Final-State (Wausau)

1. Starting with Rochester, we test and expand it, placing Sioux Falls, then
Minneapolis, then LaCrosse, then Dubuque at the front of the search queue
Queue=[ Dubuque, LaCrosse, Minneapolis, Sioux Falls ].
2. We remove Dubuque and test it; it fails, so we expand it adding Rochester to
the front, then LaCrosse, then Rockford. Our search queue now looks like
[Rockford, LaCrosse, Rochester, LaCrosse, Minneapolis, Sioux Falls].
3. We remove Rockford, and add Dubuque, Madison, and Chicago to the front
of the queue in that order, yielding Queue=[ Chicago, Madison, Dubuque,
LaCrosse, Rochester, LaCrosse, Minneapolis, Sioux Falls].
4. We test Chicago, and place Rockford, and Milwaukee on the queue.
5. We take Milwaukee from the front and add Chicago, Madison, and Green
Bay to the search queue. It is now Queue=[ Green Bay, Madison, Chicago,
Rockford, Chicago, Madison, Dubuque, LaCrosse, Rochester, LaCrosse,
Minneapolis, Sioux Falls].
6. We remove Green Bay and add Milwaukee, LaCrosse, and Wausau to the
queue in that order. Finally, Wausau is at the front of the queue and our goal
test succeeds and our search ends. Our search order was Rochester, Dubuque,
Rockford, Chicago, Milwaukee, Green Bay, and Wausau.
‫م أحمد المحنا‬.‫م‬
‫الذكاء االصطناعي‬
‫الملزمة الثالثة‬ ‫المرحله الثالثة‬
Almustaqbal university college

In this example, we again did not prevent tested nodes from being added to the search
queue. As a result, we had duplicate nodes on the queue. In the depth-first case, this
could have been disastrous. We could have easily had a cycle or loop where we tested
one city, then a second, then the first again, ad infinitum.

Example of Breadth First Search

Open: [A]
Closed[ ]
‫م أحمد المحنا‬.‫م‬
‫الذكاء االصطناعي‬
‫الملزمة الثالثة‬ ‫المرحله الثالثة‬
Almustaqbal university college

Open: [B,C]
Closed:[A]

Open:[C,D,E]
Closed:[A,B]

We continue in the same


procedure until we reach
the Goal [G]

Time Complexity
Space Complexity
‫م أحمد المحنا‬.‫م‬
‫الذكاء االصطناعي‬
‫الملزمة الثالثة‬ ‫المرحله الثالثة‬
Almustaqbal university college

Example 2: BFS (Breadth First Search)


Taken from http://iis.kaist.ac.kr/es/

Initial State Goal State:

How can we solve this problem?


1. We need to initiate the start (initial State) .
2. We need to use the control strategy.
3. Apply the initial state and control strategy to reach the Goal.

The solving of this problem is to consider the initial state as above:


‫م‪.‬م أحمد المحنا‬
‫الذكاء االصطناعي‬
‫الملزمة الثالثة‬ ‫المرحله الثالثة‬
‫‪Almustaqbal university college‬‬
‫م أحمد المحنا‬.‫م‬
‫الذكاء االصطناعي‬
‫الملزمة الثالثة‬ ‫المرحله الثالثة‬
Almustaqbal university college

Example3: Apply this example using Depth First Search with goal
[N]?
Artificial Intelligence (AI). Definition
Artificial Intelligence (AI) is the field of designing, studying and using
artificial Intelligence
Systems.
What is Intelligent System?
It is computer based system with human like intelligence.
Why we do Need Artificial Intelligence?
Compared to human intelligence, artificial intelligence (AI) is:
Fast.
Accurate.
Scalable. Once built for a small task, it can be extended to larger tasks.
Robust. Doesn't get tired. Commits fewer mistakes.
Absence of fear: in dangerous situations
Replaceable. Once lost or damaged it can easily be replaced by an exact
copy of itself.
Cheaper than recruiting human operators.
Safer: in training simulation, virtual reality.. etc
Main aspects of Artificial Intelligence (AI)
When can we describe a system as being intelligent? Or what are the
important characteristics
of an intelligent system? These are the main aspects with some examples:
Can learn. (Neural Networks, model estimation, parameter estimation from
data, adaptive
Systems)
Can understand. (Computer vision, pattern recognition, natural language
processing)
Solve problems (AI Math problem solver, Chess player)
Can reason (think). (Chess player-e.g IBM Deep Blue system, inference
engines)
Human like communication – Natural language processing. (Google
Now, automatic report writer) Autonomous -independent of human
operator (unmanned vehicles, robots, chess player ) Tolerate errors
in input (Google search engine, natural language processing)

Two main approaches to Artificial Intelligence


Statistical: its main fields are in statistical Pattern Recognition, Neural
Networks, and Belief
Networks, Time series prediction and Regression.
Rule Based: its main fields are in Knowledge Based systems, Decision
trees. Search
Strategies, Inference Engine and Natural Language Processing. It is usually
based on
Symbolic representation of the problem rather than statistical.
Both branches are important. Often, an intelligent system contains parts
from the two
Approaches. Usually the first part (front end) is statistical and the second
part (back end) is
Rule based.
Artificial Intelligence Applications

Computer Science: most developments to make computer smarter and


human like were
Originally achieved by AI. Main early achievements include:
GUI (Graphical User Interface), computer mouse, Object Oriented
Programming, Symbolic
Programming (such as Prolog, Lisp and Net Log), linked-lists, etc.

Manufacturing: automatic visual inspection, robotics, expert systems.

Telecommunications: optimization, system design.

Market and customers research: knowledge based system, inference


engines, Pattern
Recognition.

Toys and games: IBM Deep Blue chess player system. Beat the world
champion in chess!
Computer games: most computer games have some elements of AI
Aviation: rule based expert systems, computer vision.

Robotics: scene analysis, inference engine, computer vision.


Medicine and Biology: expert system diagnostics, robotic surgery, DNA
code, image
processing diagnostics, pattern recognition in clinical trials.
Automatic Translation: natural language processing,
Security Systems: Biometrics (face, fingerprints and iris recognition),
motion detection.
Military: automatic target recognition, navigation, early warning

How can we know if a Machine Has Intelligence?


The Turing Test
Was proposed by Alan Turing in 1950.
It is a test to decide whether a machine can think or not, or whether it is
intelligent or not.
A subject (person) is asked to talk to someone behind a screen by text only
(typing). If after
The end of the conversation the subject cannot tell if the other side is a
machine or a real
Person then that machine has intelligence.
To pass the Turing test the intelligent machine has to have at least the
following skills
Natural language processing
Knowledge representation
Automated reasoning: thinking based on the stored knowledge
Machine learning: able to learn
It is controversial test because passing the test is not enough to prove the
intelligence. It only
Gives the impression that the system is intelligent.

Different Fields within Artificial Intelligence

AI is a very wide field and may contain many specialized subjects. Here is
a list of some of
The sub-fields of artificial intelligence:
Pattern Recognition
Neural Networks
Computer Vision
Speech Recognition
Robotics
Natural Language Processing
Knowledge based systems
Data Mining
Concept Mining
Game Theory
Fuzzy Logic
What is learning?
Learning here means to acquire new skill that was not in the system
originally. In general it
Means trying to approximate a mathematical model or the underlying
function that produces
Specific output in response to certain input.
The model or function can be learned through different ways:
1. through direct memory: direct memory association or look-up table. This
is simplest
Kinds of learning. However it is the most expensive in terms of resources
but easiest
In design. Example: learning a mathematical operation such as adding or
multiplying
By memorizing as many of the input-output pairs. Another example is to
search for
The word in a dictionary in a look-up table manner. That is for each word
there is only
One meaning or set of meanings. This is called learning the examples
2. Through Learning the actual rule and applying it directly. For example
learning the
Multiplication rule of two numbers is to add the first number to itself as
many times as
The second number. A. B = A + A + A … . (B times). This is called
Learning by
Explicit rules
3. Learning the model through generalization of individual examples. This
is learning
From examples or experience and it is the essence of Statistical learning.
Understanding in Artificial Intelligence
Understanding is a complex process. It consists of many elements and
prerequisites. It
Generally means turning incoming information into the context of the
internal knowledge
Base of the system, so that it means something. In other words,
understanding is to make the
Incoming sensory information means something.
Figure 1 Process of Understanding in an Intelligent System

Sensory information can take different forms. The most important kinds of
sensory information are visual and audio. Other sensory information can be
of wide range of physical nature such as voltage, pressure, temperature and
so on. All these kinds of information need to be processed by the intelligent
system. It is then divided into smaller parts; each part is identified as
meaningful entity and together with other parts constitutes an idea or a
situation that requires certain action (Figure 1).
For example, visual information is turned into images, each image is
divided into a number of individual objects. Each object is then turned into
a meaningful entity such as human, tree, chair, bird and so on. Meaningful
objects are combined and turned into some idea or concept. For instance,
the picture can be understood as pleasing scene of a garden, a dangerous
situation involving a speeding car, fire or other kind of risks, or just a
neutral situation that requires no action. The same can be applied to audio
data. The overall series of data is identified as meaningful speech or
sounds. If it is speech then it has to be divided into smaller parts, each
means something as a word. Then individual words are linked together and
a complete meaning of a sentence is made and understood.
An important part of this process is called Pattern Recognition. The role of
pattern recognition is to process the incoming raw data acquired by the
sensors such as the camera or microphone in the case of machine intelligent
system, or the eye or ear in the case of humans, and identify or recognize
meaningful parts.
In general there are two approaches in pattern recognition. The first
approach is Statistical Pattern Recognition which relies on the statistical
information in the data to decide on how detected objects are classified or
identified. For example, the data that represents a human face can vary
significantly. An image of a person can be different from another image of
the same person. However, there are some statistically common aspects
that characterize the images of the same person. The system uses this
statistical information and reaches a decision about the identity of a person
in the image. The same thing can be said about the way certain word is
pronounced. The word “hello” can sound differently by different speakers
or even by the same speaker at different times.

Figure 2 the same person can have many different pictures


The other approach is called Syntactical Pattern Recognition. In this
approach, rather than statistical information, the system uses certain rules
to decide on the identity of objects. For example, the identity of human face
can be characterized by the existence of dimples, square chin, certain shape
of the lips or eyes and so on. It is a descriptive method rather than
statistical.
A central aspect in the statistical pattern recognition is the fact that the
same knowledge unit or object can be represented by a wide range of
incoming data values. For example, in the case of human face, the light
density can change significantly from picture to picture of the same person,
or the ratio between the width and height of the face can change with the
angle of view of the camera and so on (Figure 2 )
The fact that this approach relies on statistical information suggests that we
need to have some background information about random process and
probability.

Introduction to Probability
The Random Variable (RV)
A random variable is a variable that is impossible to know its value without
conducting an experiment. Or it is a variable that is impossible to predict its
future value to 100% certainty. Random variable is often associated with
chance. For example, tossing a coin has two outcomes: head or tail.
Throwing a dice results in having 1, 2, 3, 4, 5 or 6. Random variables can
be discrete or continuous:
Discrete: can have one of a limited number of specific values. For
example, it can be the outcome of throwing a dice, tossing a coin, or the
colour of a ball taken blindly from a box full of balls of different colours.
Continuous: can have an infinite number of values in a continuous range.
For example the height of a person in a population is continuous random
variable since it can take any value between minimum (say 100 cm) and
maximum (e.g 220cm). The same can be said about the temperature in a
certain town, or the weight of an apple, the contamination level in river
water and so on.
Random Process
It is the process that generates or produces random variables. For example,
throwing a dice is a random process. Tossing a coin is another example.
The weather in certain country is a random process. All these examples
generate random variables. In the case of a dice the random variable is the
outcome of the dice throwing. In the case of weather, the random variables
can be the temperature, pressure, wind speed and so on.

What is Probability?
It is a measure of the chance that something can happen. It reflects the
degree of uncertainty in the outcome of a random process.
Example1: probability of getting the number 2 in a dice throwing is 1/6 or
0.133. It means that if the dice is thrown 100 times the expected number of
times that we get the number 2 is about 13 times out of 100 trials.
Example 2: the probability that the maximum temperature in Iraq is
between 35-40C during the month of April is around 0.7. In July the
probability drops to less than 0.02.
Department of Computer Engineering Techniques (Stage: 3)
Artificial Intelligence (Lecture 4)
MSc. Ahmed Adnan Hadi

Heuristic Search

The Traveling Salesman Problem (TSP), where a salesman makes a complete tour of
the cities on his route, visiting each city exactly once, while traveling the shortest
possible distance, is an example of a problem which has a combinatorial
explosion. As such, it cannot be solved using breadth-first or depth-first search for
problems of any realistic size. Unfortunately, there are many problems which have
this form and which are essentially intractable (they can’t be solved). In these cases,
finding the best possible answer is not computationally feasible, and so we have to
settle for a good answer. In this section we discuss several heuristic search methods
which attempt to provide a practical means for approaching these kinds of search
problems.

What is the Heuristic Search ?

Heuristic search methods are characterized by this sense that we have limited time
and space in which to find an answer to complex problems and so we are willing
to accept a good solution. As such, we apply heuristics or rules of thumb as we are
searching the tree to try to determine the likelihood )‫ (احتمال‬that following one path or
another is more likely to lead to a solution. Note this is in stark contrast to brute-
force methods which chug along merrily regardless of whether a solution is anywhere
in sight.

Heuristic search methods use objective functions called heuristic functions to try to
gauge the value of a particular node in the search tree and to estimate the value of
following down any of the paths from the node.

Generate and Test Algorithm

The generate and test algorithm is the most basic heuristic search function. The steps
are:

1. Generate a possible solution, either a new state or a path through the


problem space.
2. Test to see if the new state or path is a solution by comparing it to a set of
goal states.
3. If a solution has been found, return success; else return to step 1.
Department of Computer Engineering Techniques (Stage: 3)
Artificial Intelligence (Lecture 4)
MSc. Ahmed Adnan Hadi

Example:-

Figure (1): Example of Generate and Test Algorithm

Question for Students: what is the difference between this algorithm and depth
first search algorithm?

Disadvantage of this algorithm

It may take an extremely long time. For small problems, generate and test can
be an effective algorithm, but for large problems, the undirected search
strategy leads to lengthy run times and is impractical.
The major weakness of generate and test is that we get no feedback on which
direction to search. We can greatly improve this algorithm by providing
feedback through the use of heuristic functions.

Hill climbing Algorithm

It is an improved generate-and-test algorithm, where feedback from the tests are used
to help direct the generation (and evaluation) of new candidate states. When a node
state is evaluated by the goal test function, a measure or estimate of the distance to the
goal state is also computed.

Pseudo-Code Algorithm

function HILL-CLIMBING(problem) returns a solution state


Department of Computer Engineering Techniques (Stage: 3)
Artificial Intelligence (Lecture 4)
MSc. Ahmed Adnan Hadi

inputs: problem, a problem


static: current, a node
next, a node
current <— MAKE-NODE(lNlTIAL-STATE[problem])
loop do
next— a highest-valued successor of current
if VALUE[next] < VALUE[current] then return current
current *—next
end

Example

In this example, (a) is initial State and (h) and (k) is final states and it says that the
numbers near the states are the heuristic values.
What are disadvantages of this algorithm?

One problem with hill climbing search in general is that the algorithm can get
caught in local minima or maxima. Because we are always going in the
direction of least cost, we can follow a path up to a locally good solution,
while missing the globally excellent solution available just a few nodes away.
Once at the top of the locally best solution, moving to any other node would
lead to a node with lower goodness.
Department of Computer Engineering Techniques (Stage: 3)
Artificial Intelligence (Lecture 4)
MSc. Ahmed Adnan Hadi

Another possibility is that a plateau or flat spot exists in the problem space.
Once the search algorithm gets up to this area all moves would have the same
goodness and so progress would be halted.
 It isn’t complete and can't guarantee to find the global maxima. The benefit, of
course, is that it requires a fraction of the resources. In practice and applied to
the right problems, it's a very effective solution.
 Hill Climbing don't generally backtrack, because it doesn’t keeping track of
state (it's local search) and you would be moving away from a maxima

In the example above :

 Hill climbing on the tree, we start a f  g and then what ?? finish(without


result). This is called a local minima

Solutions
A common way to avoid getting stuck in local maxima with Hill Climbing is to use
random restarts. In the example in above if G is a local maxima, the algorithm would
stop there and then pick another random node to restart from. So if J or C were
picked (or possibly A, B, or D) you would find the global maxima in H or K. it will find
the global maxima or something close; depending on time/resource limitations and
the problem space.
 Another solution to avoid getting trapped in suboptimal states, variations on
the hill climbing strategy have been proposed. One is to inject noise into the
evaluation function, with the initial noise level high and slowly decreasing
over time. This technique, called simulated annealing, allows the search
algorithm to go in directions which are not “best” but allow more complete
exploration of the search space.

You might also like