48
UNIT I Overview of A.I: Introduction to AI, Importance of AI, AI and its related field, AI techniques, Problems, problem space and search: Defining the problem as a state space search, Production system and its characteristics, Popular AI Problems- water Jug Problem, Missionaries-Cannibal Problem, 8 Puzzle Problem. A branch of Computer Science named Artificial Intelligence pursues creating the computers or machines as intelligent as human beings. What is Artificial Intelligence? According to the father of Artificial Intelligence, John McCarthy, it is “The science and engineering of making intelligent machines, especially intelligent computer programs”. Artificial Intelligence is a way of making a computer, a computer-controlled robot, or a software think intelligently, in the similar manner the intelligent humans think. AI is accomplished by studying how human brain thinks and how humans learn, decide, and work while trying to solve a problem, and then using the outcomes of this study as a basis of developing intelligent software and systems. AI is a study which makes the computers to do things which are, at the moment, at the hands of human beings. Views of AI fall into four categories: Thinking Humanly(The Cognitive approach) Acting Humanly(The Turing Test approach) Thinking Rationally(The Laws of Thought approach) Acting Rationally(The Rational Agent approach) Systems that think like humans ―The exciting new effort to make computers think Machines with minds, in the full and literal sense. (Haugeland,1985) The cognitive modeling approach We need to get inside actual working of the human mind: (a) Through introspection trying to capture our own thoughts as they go by; (b) Through psychological experiments Allen Newell and Herbert Simon, who developed GPS,the ―General Problem Solver tried to trace the reasoning steps to traces of human subjects solving the same problems The interdisciplinary field of cognitive science brings together computer models from AI and experimental techniques from psychology to try to construct precise and testable theories of the workings of the human mind. About GPS: It was a computer program created in 1957 by Simon and Newell to build a Universal Problem Solver Machine. GPSwas based on Simon and Newell’s theoretical work on logic machines.

UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Embed Size (px)

Citation preview

Page 1: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

UNIT I Overview of A.I: Introduction to AI, Importance of AI, AI and its related field, AI techniques, Problems, problem space and search: Defining the problem as a state space search, Production system and its characteristics, Popular AI Problems- water Jug Problem, Missionaries-Cannibal Problem, 8 Puzzle Problem.

A branch of Computer Science named Artificial Intelligence pursues creating the computers or machines as

intelligent as human beings.

What is Artificial Intelligence?

According to the father of Artificial Intelligence, John McCarthy, it is “The science and engineering of making intelligent machines, especially intelligent computer programs”. Artificial Intelligence is a way of making a computer, a computer-controlled robot, or a software think intelligently, in the similar manner the intelligent humans think. AI is accomplished by studying how human brain thinks and how humans learn, decide, and work while trying to solve a problem, and then using the outcomes of this study as a basis of developing intelligent software and systems. AI is a study which makes the computers to do things which are, at the moment, at the hands of human beings. Views of AI fall into four categories:

Thinking Humanly(The Cognitive approach)

Acting Humanly(The Turing Test approach)

Thinking Rationally(The Laws of Thought approach)

Acting Rationally(The Rational Agent approach)

Systems that think like humans

―The exciting new effort to make computers think

… Machines with minds, in the full and literal sense.‖(Haugeland,1985) The cognitive modeling approach

We need to get inside actual working of the human mind: (a) Through introspection – trying to capture our own thoughts as they go by; (b) Through psychological experiments Allen Newell and Herbert Simon, who developed GPS,the ―General Problem Solver tried to trace the reasoning steps to traces of human subjects solving the same problems The interdisciplinary field of cognitive science brings together computer models from AI and experimental techniques from psychology to try to construct precise and testable theories of the workings of the human mind. About GPS: It was a computer program created in 1957 by Simon and Newell to build a Universal Problem Solver Machine. GPSwas based on Simon and Newell’s theoretical work on logic machines.

Page 2: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

GPS in principal can solve any formalized symbolic problems, such as theorems proof and geometric problems such as chess playing. GPS solved many simple problems, such as the Tower of Hanoi, that could be sufficiently formalized, but GPS could not solve any real world problems.

Systems that think rationally

―The study of mental faculties through the use of computer models. (Charniak and McDermont, 1985) The “laws of thought approach” The Greek philosopher Aristotle was one of the first to attempt to codify ―right thinking that is irrefutable reasoning processes. His syllogism provided patterns for argument structures that always yielded correct conclusions when given correct premises—for example, Socrates is a man; all men are mortal; therefore Socrates is mortal. These laws of thought were supposed to govern the operation of the mind; their study initiated a field called logic. Systems that act like humans

The art of creating machines that performs functions that require intelligence when performed by People. (Kurzweil, 1990)

The Turing Test approach o Test proposed by Alan Turing in 1950 o The computer is asked questions by a human interrogator.

The computer passes the test if a human interrogator, after posing some written questions, cannot tell whether the written responses come from a person or not. Programming a computer to pass, the computer need to possess the following capabilities:

Natural language processing to enable it to communicate successfully in English. Knowledge representation to store what it knows or hears

Automated reasoning to use the stored information to answer questions and to draw new conclusions.

Machine learning to adapt to new circumstances and to detect and extrapolate patterns

i.e. in short we can say to pass the complete Turing Test, the computer will need

Computer vision to perceive the objects, and

Robotics to manipulate objects and move about

Page 3: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Systems that act rationally

“Computational intelligence is the studyof the design of intelligent agents. (Poole et al., 1998)

The rational agent approach An agent is something that acts. Computer agents are not mere programs, but they are expected to have the following attributes also: (a) Operating under autonomous control, (b) Perceiving their environment, (c) Persisting over a prolonged time period, (d) Adapting to change.

Arational agentis one that acts so as to achieve the best outcome.

Philosophy of AI While exploiting the power of the computer systems, the curiosity of human, lead him to wonder, “Can a machine think and behave like humans do?” Thus, the development of AI started with the intention of creating similar intelligence in machines that we find and regard high in humans. Goals of AI

To Create Expert Systems −the systems which exhibit intelligent behavior, learn, demonstrate, explain, and advice its users.

To Implement Human Intelligence in Machines −Creating systems that understand, think, learn, and behave like humans.

What Contributes to AI? Artificial intelligence is a science and technology based on disciplines such as Computer Science, Biology, Psychology, Linguistics, Mathematics, and Engineering. A major thrust of AI is in the development of computer functions associated with human intelligence, such as reasoning, learning, and problem solving. Out of the following areas, one or multiple areas can contribute to build an intelligent system.

Page 4: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Programming Without and With AI The programming without and with AI is different in following ways –

Programming Without AI Programming With AI

A computer program without AI can answer the specific questions it is meant to solve.

A computer program with AI can answer the generic questions it is meant to solve.

Modification in the program leads to change in its structure.

AI programs can absorb new modifications by putting highly independent pieces of information together. Hence you can modify even a minute piece of information of program without affecting its structure.

Modification is not quick and easy. It may lead to affecting the program adversely.

Quick and Easy program modification.

The domain of artificial intelligence is huge in breadth and width. While proceeding, we consider the broadly common and prospering research areas in the domain of AI –

Speech and VoiceRecognition These both terms are common in robotics, expert systems and natural language processing. Though these terms are used interchangeably, their objectives are different.

Speech Recognition Voice Recognition

The speech recognition aims at understanding and

comprehending WHAT was spoken.

The objective of voice recognition is to

recognize WHO is speaking.

It is used in hand-free computing, map, or menu

navigation.

It is used to identify a person by analyzing its tone,

voice pitch, and accent, etc.

Page 5: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Machine does not need training for Speech

Recognition as it is not speaker dependent.

This recognition system needs training as it is

person oriented.

Speaker independent Speech Recognition systems

are difficult to develop.

Speaker dependent Speech Recognition systems are

comparatively easy to develop.

Working of Speech and Voice Recognition Systems

The user input spoken at a microphone goes to sound card of the system. The converter turns the analog signal

into equivalent digital signal for the speech processing. The database is used to compare the sound patterns to

recognize the words. Finally, a reverse feedback is given to the database.

This source-language text becomes input to the Translation Engine, which converts it to the target language text.

They are supported with interactive GUI, large database of vocabulary, etc.

Real Life Applications of AI Research Areas

There is a large array of applications where AI is serving common people in their day-to-day lives .AI has been

dominant in various fields such as −

Gaming − AI plays crucial role in strategic games such as chess, poker, tic-tac-toe, etc., where machine

can think of large number of possible positions based on heuristic knowledge.

Natural Language Processing − It is possible to interact with the computer that understands natural

language spoken by humans.

Expert Systems − There are some applications which integrate machine, software, and special

information to impart reasoning and advising. They provide explanation and advice to the users.

Vision Systems − These systems understand, interpret, and comprehend visual input on the computer.

For example,

o A spying aeroplane takes photographs, which are used to figure out spatial information or map of the areas.

o Doctors use clinical expert system to diagnose the patient. o Police use computer software that can recognize the face of criminal with the stored portrait

made by forensic artist.

Speech Recognition − Some intelligent systems are capable of hearing and comprehending the

language in terms of sentences and their meanings while a human talks to it. It can handle different

accents, slang words, noise in the background, change in human’s noise due to cold, etc.

Page 6: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Handwriting Recognition − The handwriting recognition software reads the text written on paper by a

pen or on screen by a stylus. It can recognize the shapes of the letters and convert it into editable text.

Intelligent Robots − Robots are able to perform the tasks given by a human. They have sensors to

detect physical data from the real world such as light, heat, temperature, movement, sound, bump, and

pressure. They have efficient processors, multiple sensors and huge memory, to exhibit intelligence. In

addition, they are capable of learning from their mistakes and they can adapt to the new environment.

Sr.No. Research Areas Example

1 Expert Systems

Examples − Flight-tracking systems, Clinical systems.

Page 7: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

2. Natural Language Processing

Examples: Google Now feature, speech recognition, Automatic voice output.

3 Neural Networks

Examples − Pattern recognition systems such as face recognition, character recognition, handwriting recognition.

4 Robotics

Examples − Industrial robots for moving, spraying, painting, precision checking, drilling, cleaning, coating, carving, etc.

5 Fuzzy Logic Systems

Examples − Consumer electronics, automobiles, etc.

Task Classification of AI

The domain of AI is classified into Formal tasks, Mundane tasks, and Expert tasks.

Page 8: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Task Domains of Artificial Intelligence

Mundane (Ordinary) Tasks Formal Tasks Expert Tasks

Perception

Computer Vision

Speech, Voice

Mathematics

Geometry

Logic

Integration and Differentiation

Engineering

Fault Finding

Manufacturing

Monitoring

Natural Language Processing

Understanding

Language Generation

Language Translation

Games

Go

Chess (Deep Blue)

Ckeckers

Scientific Analysis

Common Sense Verification Financial Analysis

Reasoning Theorem Proving Medical Diagnosis

Planing Creativity

Robotics

Locomotive

Humans learn mundane (ordinary) tasks since their birth. They learn by perception, speaking, using language, and locomotives. They learn Formal Tasks and Expert Tasks later, in that order.

For humans, the mundane tasks are easiest to learn. The same was considered true before trying to implement mundane tasks in machines. Earlier, all work of AI was concentrated in the mundane task domain.

Later, it turned out that the machine requires more knowledge, complex knowledge representation, and complicated algorithms for handling mundane tasks. This is the reason why AI work is more prospering in the Expert Tasks domain now, as the expert task domain needs expert knowledge without common sense, which can be easier to represent and handle.

What is AI Technique?

Page 9: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Artificial Intelligence research during the last three decades has concluded that Intelligence requires knowledge. In the real world , to compensate overwhelming quality, knowledge possesses less desirable properties.−

Its volume is huge, next to unimaginable.

It is not well-organized or well-formatted. It differs from data by being organized in a way that corresponds to its application

It keeps changing constantly.

It is complicated.

It is difficult to characterize correctly.

AI Technique is a manner to organize and use the knowledge efficiently in such a way that −

It should be perceivable by the people who provide it, even though for many programs bulk of the data

that comes automatically from readings.

It should be easily modifiable to correct errors and reflect changes in real conditions.

It should be useful in many situations though it is incomplete or inaccurate.

In many AI domains, how the people understand the same people must supply the knowledge to a

program.

It can be used to help overcome its own sheer bulk by helping to narrow the range of possibilities that

must be usually considered.

AI techniques elevate the speed of execution of the complex program it is euipped with. In order to characterize

an AI technique let us consider initially OXO or tictac-toe and use a series of different approaches to play the

game.

The programs increase in complexity, their use of generalizations, and the clarity of their knowledge and the

extensibility of their approach. In this way they move towards being representations of AI techniques.

BRANCHES OF AI

A list of branches of AI is given below. However some branches are surely missing,because no one has identified

them yet. Some of these may be regarded as concepts or topics rather than full branches.

Logical AI

In general the facts of the specific situation in which it must act, and its goals are all represented by sentences of some mathematical logical language. The program decides what to do by inferring that certain actions are appropriate for achieving its goals.

Page 10: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Search Artificial Intelligence programs often examine large numbers of possibilities – for example, moves in a chess game and inferences by a theorem proving program. Discoveries are frequently made about how to do this more efficiently in various domains.

Pattern Recognition When a program makes observations of some kind, it is often planned to compare what it sees with a pattern. For example, a vision program may try to match a pattern of eyes and a nose in a scene in order to find a face. More complex patterns are like a natural language text, a chess position or in the history of some event. These more complex patterns require quite different methods than do the simplepatterns that have been studied the most.

Representation Usually languages of mathematical logic are used to represent the facts about the world.

Inference Others can be inferred from some facts. Mathematical logical deduction is sufficient for some purposes, but new methods of non-monotonic inference have been added to the logic since the 1970s. The simplest kind of non-monotonic reasoning is default reasoning in which a conclusion is to be inferred by default. But the conclusion can be withdrawn if there is evidence to the divergent. For example, when we hear of a bird, we infer that it can fly, but this conclusion can be reversed when we hear that it is a penguin. It is the possibility that a conclusion may have to be withdrawn that constitutes the non-monotonic character of the reasoning. Normal logical reasoning is monotonic, in that the set of conclusions can be drawn from a set of premises, i.e. monotonic increasing function of the premises. Circumscription is another form of non-monotonic reasoning.

Common sense knowledge and Reasoning This is the area in which AI is farthest from the human level, in spite of the fact thatit has been an active research area since the 1950s. While there has been considerableprogress in developing systems of non-monotonic reasoning and theories of action,Yet more new ideas are needed.

Learning from experience There are some rules expressed in logic for learning. Programs can only learn what facts or behavior their formalisms can represent, and unfortunately learning systemsare almost all based on very limited abilities to represent information. Planning Planning starts with general facts about the world (especially facts about the effectsof actions), facts about the particular situation and a statement of a goal. From these, planning programs generate a strategy for achieving the goal. In the most common cases, the strategy is just a sequence of actions.

Epistemology This is a study of the kinds of knowledge that are required for solving problems in the world.

Ontology Ontology is the study of the kinds of things that exist. In AI the programs and sentences deal with various kinds of objects and we study what these kinds are and what their basic properties are. Ontology assumed importance from the 1990s. Heuristics A heuristic is a way of trying to discover something or an idea embedded in a program. The term is used variously in AI. Heuristic functions are used in some approaches to search or to measure how far a node in a search tree

Page 11: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

seems to be froma goal. Heuristic predicates that compare two nodes in a search tree to see if one is better than the other, i.e. constitutes an advance toward the goal, and may be more useful.

Genetic programming Genetic programming is an automated method for creating a working computer program from a high-level problem statement of a problem. Genetic programming starts from a high-level statement of ‘what needs to be done’ and automatically creates a computer program to solve the problem. It is being developed by John Koza’s group.

UNDERLYING ASSUMPTION OF AI

Newell and Simon presented the Physical Symbol System Hypothesis, which liesin the heart of the research in Artificial Intelligence. A physical symbol system consists of a set of entities called symbols, which are physical patterns that can occur as components of another entity called anexpression or symbol structure. A symbol structure is a collection of instances or tokens of symbols related in some physical way. At any instant, the system willcontain a collection of these symbol structures. In addition, the system also containsa collection of processes that operate on expressions to produce other expressions;processes of creation, modification, reproduction and destruction. A physical symbol system is a machine that produces an evolving collection of symbol structures.

Physical Symbol System Hypothesis A physical symbol system has the necessary and sufficient attributes for general intelligent action. It is only a hypothesis and there is no way to prove it other thanon empirical validation. Evidence in support of the physical symbol system hypothesis has come not only from the areas such as game playing but also from the areas such as visual perception. We will discuss the visual perception area later. The importance of the physical symbol system hypothesis is twofold. It is the major theory of human intelligence and also forms the basic belief that, it is possibleto build programs that can execute intelligent tasks now

performed by people.

Problems, Its Definition as State Space Search PROBLEM OF BUILDING A SYSTEM 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.

Page 12: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

1. Choose the best solving techniques for the problem to solve a solution. Problem solving is a process of generating solutions from observed data.

a ‘problem’ is characterized by a set of goals,

a set of objects, and

a set of operations. These could be ill-defined and may evolve during problem solving.

A ‘problem space’ is an abstract space.

o A problem space encompasses all valid states that can be generated by the application of any combination of operators on any combination of objects.

o The problem space may contain one or more solutions. A solution is a combination of operations and objects that achieve the goals.

A ‘search’ refers to the search for a solution in a problem space. o Search proceeds with different types of ‘search control strategies’.

o The depth-first search and breadth-first search are the two common search strategies.

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:

1. Define a state space that contains all the possible configurations of the relevant objects, including some impossible ones.

2. Specify one or more states that describe possible situations, from which the problem-solving process may start. These states are called initial states.

3. Specify one or more states that would be acceptable solution to the problem. These states are called goal states.

4. Specify a set of rules that describe the actions (operators) available. 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:

Search is fundamental to the problem-solving process.

Search is a general mechanism that can be used when a more direct method is not known.

Search provides the framework into which more direct methods for solving subparts of a problem can be embedded. A very large number of AI problems are formulated as search problems.

Problem space

A problem space is represented by a directed graph, where nodes represent search state and paths represent the operators applied to change the state. To simplify search algorithms, it is often convenient to logically and programmatically represent a problem space as a tree. A tree usually decreases the complexity of a search at a cost. Here, the cost is due to duplicating some nodes on the tree that were linked numerous times in the graph, e.g. node B and node D. 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.

Page 13: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Graph Trees

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. A special-purpose method is tailor-made for a particular problem, often exploits very specific features of the situation in which the problem is embedded. A general-purpose method is applicable to a wide variety of problems. One General-purpose technique used in AI is ‘means-end analysis’: a step-by-step, or incremental, reduction of the difference between current state and final goal.

DEFINING PROBLEM AS A STATE SPACE SEARCH 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.

State Space Search

A state space represents a problem in terms of states and operators that change states. A state space consists of:

1. A representation of the states the system can be in. For example, in a board game, the board represents the current state of the game.

A set of operators that can change one state into another state. In a board game, the operators are the legal moves from any given state. Often the operators are represented as programs that change a state

Page 14: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

representation to represent the new state.

• An initial state.

• A set of final states; some of these may be desirable, others undesirable. This set is often represented implicitly by a program that detects terminal states.

The Water Jug Problem 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? OR “You are given two jugs, a 4-litre one and a 3-litre one. Neither has any measuring markers on it. There is a pump that can be used to fill the jugs with water. How can you get exactly 2 litres of water into 4-litre 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. i.e.

• State: (x, y) x = 0, 1, 2, 3, or 4 y = 0, 1, 2, 3

• Start state: (0, 0). • Goal state: (2, n) for any n. • Attempting to end up in a goal state.

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. 1. (x, y) (4, y) if x 4 2. (x, y) (x, 3) if y 3 3. (x, y) (x d, y) if x 0 4. (x, y) (x, y d) if y 0

5. (x, y) (0, y) if x 0 6. (x, y) (x, 0) if y 0 7. (x, y) (4, y (4 x)) if x y 4, y 0 8. (x, y) (x (3 y), 3) if x y 3, x 0 (x, y) (x y, 0) if x y 4, y 0 10. (x, y) (0, x y) if x y 3, x 0 11. (0, 2) (2, 0) 12. (2, y) (0, y)

Page 15: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Hence we can say:

1. current state = (0, 0) 2. Loop until reaching the goal state (2, 0)

- Apply a rule whose left side matches the current state - Set the new current state to be the resulting state (0, 0) (0, 3) (3, 0) (3, 3) (4, 2) (0, 2) (2, 0) The role of the condition in the left side of a rule restrict the application of the rule more efficient 1. (x, y) (4, y) if x 4 2. (x, y) (x, 3) if y 3 Special-purpose rules to capture special-case knowledge that can be used at some stage in solving a problem 11. (0, 2) (2, 0) 12. (2, y) (0, y) 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

Page 16: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Gallons in Four Jug Gallons in Three Jug Rules Applied

0 0 -

0 3 2

3 0 7

3 3 2

4 2 11

0 2 3

2 0 10

Fig. 2.3 One Solution to 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.

State Space Search: Playing Chess

• Each position can be described by an 8-by-8 array. • Initial position is the game opening position. • Goal position is any position in which the opponent does not have a legal move and his or her king is

under attack. • Legal moves can be described by a set of rules:

- Left sides are matched against the current state. - Right sides describe the new resulting state.

• State space is a set of legal positions. • Starting at the initial state. • Using the set of rules to move from one state to another. • Attempting to end up in a goal state.

State Space Search: Summary

1. Define a state space that contains all the possible configurations of the relevant objects. 2. Specify the initial states. 3. Specify the goal states. 4. Specify a set of rules:

What are unstated assumptions?

How general should the rules be?

How much knowledge for solutions should be in the rules?

2.4 PRODUCTION SYSTEMS

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.

Page 17: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

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. Example: Eight puzzle (8-Puzzle) 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:

1 2

3

2 3 4

8

4

8 6 2

7 6

5

7 5

Initial State Goal State

• State: 3 x 3 array configuration of the tiles on the board. • Operators: Move Blank square Left, Right, Up or Down.

– This is a more efficient encoding of the operators than one in which each of four possible moves for each of the 8 distinct tiles is used.

• Initial State: A particular configuration of the board. • Goal: A particular configuration of the board. • The state space is partitioned into two subspaces • NP-complete problem, requiring O(2^k) steps where k is the length of the solution path. • 15-puzzle problems (4 x 4 grid with 15 numbered tiles), and N-puzzles (N = n^2-1)

A portion of the state space of a 8-Puzzle problem This example can be solved by the operator sequence UP, RIGHT, UP, LEFT, DOWN.

Page 18: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Example: Missionaries and Cannibals 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:

BOAT position: original (T) or final (NIL) side of the river.

Number of Missionaries and Cannibals on the original side of the river.

Start is (T 3 3); Goal is (NIL 0 0). Operators:

(MM 2 0) Two Missionaries cross the river.

(MC 1 1) One Missionary and one Cannibal.

(CC 0 2) Two Cannibals.

(M 1 0) One Missionary.

(C 0 1) One Cannibal.

Page 19: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Cryptarithmetic

• Find an assignment of digits (0, ..., 9) to letters so that a given arithmetic expression is true. examples: SEND + MORE = MONEY and

FORTY Solution: 29786 + TEN 850 + TEN 850 ----- ----- SIXTY 31486 F=2, O=9, R=7, etc.

• Note: In this problem, the solution is NOT a sequence of actions that transforms the initial state into the goal state, but rather the solution is simply finding a goal node that includes an assignment of digits to each of the distinct letters in the given problem.

Page 20: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Remove 5 Sticks

• Given the following configuration of sticks, remove exactly 5 sticks in such a way that the remaining configuration forms exactly 3 squares.

Traveling Salesman Problem

• Given a road map of n cities, find the shortest tour which visits every city on the map exactly once and then return to the original city (Hamiltonian circuit)

• (Geometric version): – a complete graph of n vertices. – n!/2n legal tours – Find one legal tour that is shortest

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. Internal factors/ External factors

Time required to run Size of input to the algorithm Space (memory) required to run

Speed of the computer Quality of the compiler

Complexity is a measure of the performance of an algorithm. Complexity measures the internal factors, usually in time than space.

Computational complexity It is the measure of resources in terms of Time and Space.

Page 21: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

If A is an algorithm that solves a decision problem f, then run-time of A is the number of steps taken on

the input of length n. o Time Complexity T(n) of a decision problem f is the run-time of the ‘best’ algorithm A for f. o Space Complexity S(n) of a decision problem f is the amount of memory used by the ‘best’

algorithm A for f.

‘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. Example 1: Determine the Big-O of an algorithm: Calculate the sum of the n elements in an integer array a[0..n-1]. 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 sub problems.

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.

Page 22: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

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. The general classes of engineering problems such as planning, classification, diagnosis, monitoring and design are generally knowledge intensive and use a large amount of heuristics. Depending on the type of problem, the knowledge representation schemes and control strategies for search are to be adopted. Combining heuristics with the two basic search strategies have been discussed above. There are a number of other general-purpose search techniques which are essentially heuristics based. Their efficiency primarily depends on how they exploit the domain-specific knowledge to abolish undesirable paths. Such search methods are called ‘weak methods’, since the progress of the search depends heavily on the way the domain knowledge is exploited. A few of such search techniques which form the center of many AI systems are briefly presented in the following sections.

Problem Decomposition Suppose to solve the expression is: + ∫(X³ + X² + 2X + 3sinx) dx

∫(X³ + X² + 2X + 3sinx) dx

∫x³dx ∫x²dx ∫2xdx ∫3sinxdx

x4 /4 x³/3 2∫xdx 3∫sinxdx

x² – 3cosx

This problem can be solved by breaking it into smaller problems, each of which we can solve by using a small collection of specific rules. Using this technique of problem decomposition, we can solve very large problems very easily. This can be considered as an intelligent behavior.

2.5.2 Can Solution Steps isignored? 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:

Page 23: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

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

Is the Problem Universe Predictable?

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.

• For certain-outcome problems, planning can used to generate lead to a solution. • For uncertain-outcome problems, a sequence of generated operators rate a sequence of operators that is

guaranteed to can only have a good probability of leading to a solution. • Plan revision is made as the plan is carried out and the necessary feedback is provided.

Is Good Solution Absolute or Relative? Consider the problem of answering questions based on a database of simple facts such as the following:

1. Siva was a man.

2. Siva was a worker in a company.

3. Siva was born in 1905.

4. All men are mortal.

5. All workers in a factory died when there was an accident in 1952.

6. No mortal lives longer than 100 years. Suppose we ask a question: ‘Is Siva alive?’ By representing these facts in a formal language, such as predicate logic, and then using formal inference methods we can derive an answer to this question easily. There are two ways to answer the question shown below: Method I:

1. Siva was a man.

2. Siva was born in 1905.

3. All men are mortal.

4. Now it is 2008, so Siva’s age is 103 years.

5. No mortal lives longer than 100 years. Method II:

1. Siva is a worker in the company.

2. All workers in the company died in 1952.

Answer: So Siva is not alive. It is the answer from the above methods. We are interested to answer the question; it does not matter which path we follow. If we followone path

Page 24: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

successfully to the correct answer, then there is no reason to go back and check another path to lead the solution. Example 2: Method 1: 1. Marcus was a man. 2. Marcus was a Pompeian. 3. Marcus was born in 40 A.D. 4. All men are mortal. 5. All Pompeians died when the volcano erupted in 79 A.D. 6. No mortal lives longer than 150 years. 7. It is now 2004 A.D. Method 2: 1. Marcus was a man. 2. Marcus was a Pompeian. 3. Marcus was born in 40 A.D. 4. All men are mortal. 5. All Pompeians died when the volcano erupted in 79 A.D. 6. No mortal lives longer than 150 years. 7. It is now 2004 A.D. Is Marcus alive?

Hence: 1. Marcus was a man. 2. Marcus was a Pompeian. 3. Marcus was born in 40 A.D. 4. All men are mortal. 5. All Pompeians died when the volcano erupted in 79 A.D. 6. No mortal lives longer than 150 years. 7. It is now 2004 A.D. Is Marcus alive? Is the solution a state or a path? Different reasoning paths lead to the answer. It does not matter which path we follow. Or The Travelling Salesman Problem We have to try all paths to find the shortest one.

• Any-path problems can be solved using heuristics that suggest good paths to explore. • For best-path problems, much more exhaustive search will be performed.

Finding a consistent intepretation

“The bank president ate a dish of pasta salad with the fork”.

– “bank” refers to a financial situation or to a side of a river?

– “dish” or “pasta salad” was eaten?

– Does “pasta salad” contain pasta, as “dog food” does not contain “dog”?

– Which part of the sentence does “with the fork” modify?

What if “with vegetables” is there?

Page 25: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

No record of the processing is necessary. OR The Water Jug Problem The path that leads to the goal must be reported.

• A path-solution problem can be reformulated as a state-solution problem by describing a state as a partial path to a solution.

• The question is whether that is natural or not. What is the role of knowledge Playing Chess Knowledge is important only to constrain the search for a solution. Reading Newspaper Knowledge is required even to be able to recognize a solution. Does the task require human-interaction?

• Solitary problem, in which there is no intermediate communication and no demand for an explanation of the reasoning process.

• Conversational problem, in which intermediate communication is to provide either additional assistance to the computer or additional information to the user.

Problem Classification • There is a variety of problem-solving methods, but there is no one single way of solving all problems. • Not all new problems should be considered as totally new. Solutions of similar problems can be exploited.

CHARACTERISTICS OF PRODUCTION SYSTEMS

Production systems provide us with good ways of describing the operations that can be performed in a search for a solution to a problem. At this time, two questions may arise:

1. Can production systems be described by a set of characteristics? And how can they be easily implemented?

2. What relationships are there between the problem types and the types of production systems well suited for solving the problems?

To answer these questions, first consider the following definitions of classes of production systems:

1. A monotonic production system is a production system in which the application of a rule never prevents

the later application of another rule that could also have been applied at the time the first rule was selected.

2. A nonmonotonic production system is one in which this is not true.

3. A partially communicative production system is a production system with the property that if the

application of a particular sequence of rules transforms state P into state Q, then any combination of those rules that is allowable also transforms state P into state Q.

4. A commutative production system is a production system that is both monotonic and partially

commutative.

Page 26: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Table 2.1 Four Categories of Production Systems

Production System Monotonic Non-monotonic

Partially Commutative Theorem Proving Robot Navigation

Non-partially Commutative Chemical Synthesis Bridge

Is there any relationship between classes of production systems and classes of problems? For any solvable problems, there exist an infinite number of production systems that show how to find solutions. Any problem that can be solved by any production system can be solved by a commutative one, but the commutative one is practically useless. It may use individual states to represent entire sequences of applications of rules of a simpler, non-commutative system. In the formal sense, there is no relationship between kinds of problems and kinds of production systems since all problems can be solved by all kinds of systems. But in the practical sense, there is definitely such a relationship between the kinds of problems and the kinds of systems that lend themselves to describing those problems. 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.

DESIGN OF SEARCH PROGRAMS AND SOLUTIONS

Solutions can be good in different ways. They can be good in terms of time or storage or in difficulty of the algorithm. In case of the travelling salesman problem, finding the best path can lead to a significant amount of computation. The solution of such problems is only possible by using heuristics. In this type of problem, a path is found of a distance of 8850 miles and another one of 7750. It is clear that the second is better than the first but is it the best? Infinite time may be needed and usually heuristics are used to find a very good path in finite time.

Design of Search Programs

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

The tree can be searched forward from the initial node to the goal state or backwards from the goal

state to the initial state.

To select applicable rules, it is critical to have an efficient procedure for matching rules against states.

How to represent each node of the search process? This is the knowledge representation problem or

Page 27: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

the frame problem. In games, an array suffices; in other problems, more complex data structures are

needed.

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. 4. 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:

X 0

0

X X

• Operators:Change an empty cell to X or O.

Start State:Board empty; X’s turn.

• Terminal States:Three X’s in a row; Three O’s in a row; All cells full.

Search Tree

The sequence of states formed by possible moves is called a search tree. Each level of the tree is called a ply.

Page 28: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

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.

Choose an appropriate search technique: ■ How large is the search space? ■ How well structured is the domain? ■ What knowledge about the domain can be used to guide the search?

Additional Problems

The additional problems are given below.

The Monkey and Bananas Problem The monkey is in a closed room in which there is a small table. There is a bunch of bananas hanging from the ceiling but the monkey cannot reach them. Let us assume that the monkey can move the table and if the monkey stands on the table, the monkey can reach the bananas. Establish a method toinstruct the monkey on how to capture the bananas.

a) Task Environment A. Information

Set of places {on the floor, place1, place2, under the bananas}

B. Operators CLIMB

Pretest the monkey is in the table’s place Move the monkey on the table WALK Variable x is the set of places Move the monkey’s place becomes x. MOVE TABLE Variable x is the set of places Pretest the monkey’s place is in the set of places The monkey’s place is in the table’s place Move the monkey’s place becomes x. The table’s place becomes x. GET BANANAS Pretest the table’s place is under the bananas The monkey’s place is on the table Move the contents of the monkey’s hand are the bananas

C. Differences

Page 29: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

d1 is the monkey’s place d2 is the table’s place d3 are the contents of the monkey’s hand

D. Differences ordering

d3 is harder to reduce than d2 which is harder to reduce than d1. Specific Task. Goal transform initial object to desired object Objects. Initial the monkey’s place is place1 the table’s place is place2 The contents of the monkey’s hand is empty. Desired the contents of the monkey’s hand are the bananas.

Page 30: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

8 Queen Problem

Decision Trees

Example I: The n-queens problem

How can we place n queens on an nn chessboard so that no two queens can capture each other?

A queen can move any number of squares horizontally, vertically, and diagonally.

Here, the possible target squares of the queen Q are marked with an x.

Let us consider the 4-queens problem.

Question: How many possible configurations of 44 chessboards containing 4 queens are there?

Answer: There are 16!/(12!4!) = (13141516)/(234) = 13754 = 1820 possible configurations.

Shall we simply try them out one by one until we encounter a solution?

No, it is generally useful to think about a search problem more carefully and discover constraints on the

problem’s solutions.

Such constraints can dramatically speed up the search process.

Obviously, in any solution of the n-queens problem, there must be exactly one queen in each column of

the board.

Otherwise, the two queens in the same column could capture each other.

Therefore, we can describe the solution of this problem as a sequence of n decisions:

Decision 1: Place a queen in the first column.

Decision 2: Place a queen in the second column.

.

.

.

Page 31: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Decision n: Place a queen in the n-th column.

There are problems that require us to perform an exhaustive search of all possible sequences of

decisions in order to find the solution.

We can solve such problems by constructing the complete decision tree and then find a path from its

root to a leave that corresponds to a solution of the problem (breadth-first search often requires the

construction of an almost complete decision tree).

In many cases, the efficiency of this procedure can be dramatically increased by a technique called

backtracking (depth-first search).

Idea: Start at the root of the decision tree and move downwards, that is, make a sequence of decisions,

until you either reach a solution or you enter a situation from where no solution can be reached by any

further sequence of decisions.

In the latter case, backtrack to the parent of the current node and take a different path downwards

from there. If all paths from this node have already been explored, backtrack to its parent.

Continue this procedure until you find a solution or establish that no solution exists (there are no more

paths to try out).

Page 32: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

1. Place n queens on an n by n chess board so that no two of them are on the same row, column, or

diagonal

Suppose you have to make a series of decisions, among various choices, where

You don’t have enough information to know what to choose

Each decision leads to a new set of choices

Some sequence of choices (possibly more than one) may be a solution to your problem

Backtracking is a methodical way of trying out various sequences of decisions, until you find one

that “works”

Page 33: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

The Eight Queens Problem

a) Five queens that cannot attack each other, but that can attack all of column 6; b) backtracking to column 5 to try

another square for the queen; c) backtracking to column 4 to try another square for the queen and then considering

column 5 again

UNIT – II Blind Search- Depth First Search, Breadth Firth Search.Heuristic search techniques: Generate and test, hill climbing- Simple Hill Climbing, Steepest Ascent hill Climbing, best first search. Search Strategies /Algorithms Searching is the universal technique of problem solving in AI. There are some single-player games such as tile

games, Sudoku, crossword, etc. The search algorithms help you to search for a particular position in such games. 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. A Hierarchical representation of most search algorithms is illustrated below. The representation begins with two types of search: Uninformed search algorithms or Brute-force algorithms or Blind Search Algorithm search through the search space all possible candidates for the solution checking whether each candidate satisfies the problem’s statement. Uninformed search strategies use only the information available in the problem definition. It uses no information about the problem to guide the search and therefore may not be very efficient.

Different Types of Uninformed Search Strategies are : Uninformed Search Strategies

– Breadth-First search – Depth-First search – Depth-First Iterative Deepening search. – Depth-limited search – Uniform-Cost search

Page 34: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

– Iterative deepening search – Bidirectional – Branch and Bound

Informed search algorithms or Intelligent Search Algorithm 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. It 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.

1. Heuristic algorithms are not really intelligent; they appear to be intelligent because they achieve better performance.

2. Heuristic algorithms are more efficient because they take advantage of feedback from

the data to direct the search path.

3. A good heuristic will make an informed search dramatically out perform 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.

4. 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).

Different Types of Uninformed Search Strategies are: Informed Search Strategies

– Best-first search – Greedy best-first search – Heuristics – Local search algorithms – Hill-climbing search – Simulated annealing search – Local beam search – Genetic algorithms – Algorithm A Search – Algorithm A* Search

Characteristics or Strategies of Search Strategies:

– 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.

Page 35: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

– A search strategy is defined by picking the order of node expansion

– Strategies are evaluated along the following dimensions: o Completeness: does it always find a solution if one exists? o Time complexity: number of nodes generated o Space complexity: maximum number of nodes in memory o Optimality: does it always find a least-cost solution?

– Time and space complexity are measured in terms of o b: maximum branching factor of the search tree o d: depth of the least-cost solution o m: maximum depth of the state space (may be ∞)

Search Terminology

Problem Space − It is the environment in which the search takes place. (A set of states and set of

operators to change those states)

Problem Instance − It is Initial state + Goal state.

Problem Space Graph − It represents problem state. States are shown by nodes and operators are shown

by edges.

Depth of a problem − Length of a shortest path or shortest sequence of operators from Initial State to

goal state.

Space Complexity − The maximum number of nodes that are stored in memory.

Time Complexity − The maximum number of nodes that are created.

Admissibility − A property of an algorithm to always find an optimal solution.

Branching Factor − The average number of child nodes in the problem space graph.

Depth − Length of the shortest path from initial state to goal state.

Uninformed Search Strategies

Brute-Force Search Strategies

They are most simple, as they do not need any domain-specific knowledge. They work fine with small number of

possible states.

Requirements − – State description – A set of valid operators – Initial state – Goal State description

– Single Agent Pathfinding Problems

– The games such as 3X3 eight-tile, 4X4 fifteen-tile, and 5X5 twenty four tile puzzles are single-agent-path-

finding challenges. They consist of a matrix of tiles with a blank tile. The player is required to arrange the

tiles by sliding a tile either vertically or horizontally into a blank space with the aim of accomplishing

some objective.

Page 36: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

– The other examples of single agent pathfinding problems are Travelling Salesman Problem, Rubik’s Cube,

and Theorem Proving.

1. 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.

It generates one tree at a time until the solution is found. It can be implemented using FIFO queue data structure.

This method provides shortest path to the solution.

If branching factor (average number of child nodes for a given node) = b and depth = d, then number of nodes at

level d = bd.

The total no of nodes created in worst case is b + b2 + b3 + … + bd.

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.Since each level of nodes is saved for

creating next one, it consumes a lot of memory space. Space requirement to store nodes is

exponential.

2. Its complexity depends on the number of nodes. It can check duplicate nodes.

Expand shallowest unexpanded node

Page 37: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Implementation:

fringe is a FIFO queue, i.e., new successors go at end.

1. 2.

2. 4. Properties of BFS: Complete? Yes (if b is finite) Time?1+b+b2+b3+… +bd + b(bd-1) = O(bd+1) Space?O(bd+1) (keeps every node in memory) Optimal? Yes (if cost = 1 per step)

Space is the bigger problem (more than time) Complexity of Breadth-First Search

• Time Complexity – assume (worst case) that there is 1 goal leaf at the RHS at depth d so BFS will generate

= b + b2+ ..... + bd + bd+1 - b = O (bd+1)

Page 38: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Space Complexity

– how many nodes can be in the queue (worst-case)? – at depth d there are bd+1 unexpanded nodes in the Q = O (bd+1)

Examples of Time and Memory Requirements for Breadth-First Search

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.

It is implemented in recursion with LIFO stack data structure. It creates the same set of nodes as Breadth-First

method, only in the different order.

As the nodes on the single path are stored in each iteration from root to leaf node, the space requirement to store nodes is linear. With branching factor b and depth as m, the storage space is bm. Algorithm Depth-first search applies operators to each newly generated state, trying to drive directly toward the goal.

• If the starting state is a goal state, quit and return success. • Otherwise, do the following until success or failure is signalled:

– Generate a successor E to the starting state. If there are no more successors, then signal failure. – Call Depth-first Search with E as the starting state.

If success is returned signal success; otherwise, continue in the loop.

Page 39: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Advantages

• Low storage requirement: linear with tree depth. • Easily programmed: function call stack does most of the work of maintaining state of the search.

Disadvantages

• May find a sub-optimal solution (one that is deeper or more costly than the best solution). • Incomplete: without a depth bound, may not find a solution even if one exists. • This algorithm may not terminate and go on infinitely on one path. The solution to this issue is to choose a

cut-off depth. If the ideal cut-off is d, and if chosen cut-off is lesser than d, then this algorithm may fail. If chosen cut-off is more than d, then execution time increases.

• Its complexity depends on the number of paths. It cannot check duplicate nodes.

Expand deepest unexpanded node

1. 2.

2. 4.

3. 4.

4. 5.

Page 40: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

5. 6.

6. 7.

Properties of DFS

Complete? No: fails in infinite-depth spaces, spaces with loops

Modify to avoid repeated states along path

complete in finite spaces Time?O(bm): terrible if m is much larger than d but if solutions are dense, may be much faster than breadth-first

Space?O(bm), i.e., linear space!

Optimal? No

Complexity of Depth-First Search

• Time Complexity

– maximum tree depth = m – assume (worst case) that there is 1 goal leaf at the RHS at depth d so DFS will generate O (bm)

• Space Complexity – how many nodes can be in the queue (worst-case)? – at depth m we have b nodes – and b-1 nodes at earlier depths – total = b + (m-1)*(b-1) = O(bm)

Page 41: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

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 b extra.

3. If the estimated depth is too shallow, the search fails to find a solution; all that computer time is wasted.

Iterative deepening search

It performs depth-first search to level 1, starts over, executes a complete depth-first search to level 2, and continues in such way till the solution is found.

It never creates a node until all lower nodes are generated. It only saves a stack of nodes. The algorithm ends

when it finds a solution at depth d. The number of nodes created at depth d is bd and at depth d-1 is bd-1.

Iterative deepening search l =0

Page 42: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Iterative deepening search l =1

Iterative deepening search l =2

Iterative deepening search l =3

Page 43: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Properties of Deepening Search:

Complete? Yes

– Time?(d+1)b0 + d b1 + (d-1)b2 + … + bd = O(bd) – Space?O(bd) – Optimal? Yes, if step cost = 1

Bidirectional Search It searches forward from initial state and backward from goal state till both meet to identify a common state. The path from initial state is concatenated with the inverse path from the goal state. Each search is done only up to half of the total path. • Idea

– simultaneously search forward from S and backwards from G – stop when both “meet in the middle” – need to keep track of the intersection of 2 open sets of nodes

• What does searching backwards from G mean – need a way to specify the predecessors of G

• this can be difficult, • e.g., predecessors of checkmate in chess?

– what if there are multiple goal states? – what if there is only a goal test, no explicit list?

• Complexity – time complexity at best is: O(2 b(d/2)) = O(b (d/2)) – memory complexity is the same

Uniform Cost Search

Sorting is done in increasing cost of the path to a node. It always expands the least cost node. It is identical to Breadth First search if each transition has the same cost. It explores paths in the increasing order of cost.

• Optimality: path found = lowest cost

– Algorithms so far are only optimal under restricted circumstances – Let g(n) = cost from start state S to node n

• Uniform Cost Search: – Always expand the node on the fringe with minimum cost g(n)

Page 44: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

– Note that if costs are equal (or almost equal) will behave similarly to BFS

Optimality of Uniform Cost Search?

• Assume that every step costs at least e > 0

• Proof of Completeness:

Given that every step will cost more than 0, and assuming a finite branching factor, there is a finite

number of expansions required before the total path cost is equal to the path cost of the goal state. Hence, we

will reach it in a finite number of steps.

• Proof of Optimality given Completeness:

– Assume UCS is not optimal.

– Then there must be a goal state with path cost smaller than the goal state which was found

(invoking completeness)

– However, this is impossible because UCS would have expanded that node first by definition.

– Contradiction.

Complexity of Uniform Cost

• Let C* be the cost of the optimal solution

• Assume that every step costs at least e > 0

• Worst-case time and space complexity is:

O( b [1 + floor(C*/e)]

)

Why? floor(C*/e) ~ depth of solution if all costs are approximately equal

Disadvantage − There can be multiple long paths with the cost ≤ C*. Uniform Cost search must explore them all.

Comparison of Various Algorithms Complexities Of Blind Algorithms

Page 45: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Let us see the performance of algorithms based on various criteria −

Criterion Breadth

First

Depth

First

Bidirectional Uniform

Cost

Interactive

Deepening Depth

Limited

Time bd bm bd/2 bd bd bl

Space bd bm bd/2 bd bd bl

Optimality Yes No Yes Yes Yes No

Completeness Yes No Yes Yes Yes No

Informed (Heuristic) Search Strategies

To solve large problems with large number of possible states, problem-specific knowledge needs to be added to

increase the efficiency of search algorithms.

Heuristic Evaluation Functions

They calculate the cost of optimal path between two states. A heuristic function for sliding-tiles games is

computed by counting number of moves that each tile makes from its goal state and adding these number of

moves for all tiles.

Pure Heuristic Search

It expands nodes in the order of their heuristic values. It creates two lists, a closed list for the already expanded

nodes and an open list for the created but unexpanded nodes.

In each iteration, a node with a minimum heuristic value is expanded, all its child nodes are created and placed in

the closed list. Then, the heuristic function is applied to the child nodes and they are placed in the open list

according to their heuristic value. The shorter paths are saved and the longer ones are disposed.

A * Search

It is best-known form of Best First search. It avoids expanding paths that are already expensive, but expands most

promising paths first.

f(n) = g(n) + h(n), where

Page 46: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

g(n) the cost (so far) to reach the node

h(n) estimated cost to get from the node to the goal

f(n) estimated total cost of path through n to goal. It is implemented using priority queue by increasing

f(n).

Greedy Best First Search

It expands the node that is estimated to be closest to goal. It expands nodes based on f(n) = h(n). It is

implemented using priority queue.

Disadvantage − It can get stuck in loops. It is not optimal.

Local Search Algorithms

They start from a prospective solution and then move to a neighboring solution. They can return a valid solution

even if it is interrupted at any time before they end.

Hill-Climbing Search

It is an iterative algorithm that starts with an arbitrary solution to a problem and attempts to find a better

solution by changing a single element of the solution incrementally. If the change produces a better solution, an

incremental change is taken as a new solution. This process is repeated until there are no further improvements.

function Hill-Climbing (problem), returns a state that is a local maximum.

inputs: problem, a problem

local variables: current, a node

neighbor, a node

current<-Make_Node(Initial-State[problem])

loop

do neighbor <- a highest_valued successor of current

if Value[neighbor] ≤ Value[current] then

return State[current]

current<- neighbor

end

Disadvantage − This algorithm is neither complete, nor optimal.

Page 47: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Local Beam Search

In this algorithm, it holds k number of states at any given time. At the start, these states are generated randomly.

The successors of these k states are computed with the help of objective function. If any of these successors is

the maximum value of the objective function, then the algorithm stops.

Otherwise the (initial k states and k number of successors of the states = 2k) states are placed in a pool. The pool

is then sorted numerically. The highest k states are selected as new initial states. This process continues until a

maximum value is reached.

functionBeamSearch( problem, k), returns a solution state.

start with k randomly generated states

loop

generate all successors of all k states

if any of the states = solution, then return the state

else select the k best successors

end

Simulated Annealing

Annealing is the process of heating and cooling a metal to change its internal structure for modifying its physical

properties. When the metal cools, its new structure is seized, and the metal retains its newly obtained properties.

In simulated annealing process, the temperature is kept variable.

We initially set the temperature high and then allow it to ‘cool' slowly as the algorithm proceeds. When the

temperature is high, the algorithm is allowed to accept worse solutions with high frequency.

Start

Initialize k = 0; L = integer number of variables;

From i→ j, search the performance difference ∆.

If ∆ <= 0 then accept else if exp(-/T(k)) > random(0,1) then accept;

Repeat steps 1 and 2 for L(k) steps.

k = k + 1;

Repeat steps 1 through 4 till the criteria is met.

End

Page 48: UNIT I - · PDF file · 2016-01-30UNIT I Overview of A.I: Introduction to AI, Importance of AI, ... Examples − Flight-tracking systems, Clinical systems. 2. ... Planing Creativity

Travelling Salesman Problem

In this algorithm, the objective is to find a low-cost tour that starts from a city, visits all cities en-route exactly

once and ends at the same starting city.

Start

Find out all (n -1)! Possible solutions, where n is the total number of cities.

Determine the minimum cost by finding out the cost of each of these (n -1)! solutions.

Finally, keep the one with the minimum cost.

end