ai intro pesit
TRANSCRIPT
Artificial IntelligenceElective – 6th Semester
Autonomous Scheme under VTU
Instructor: Dr S.NatarajanProfessor and Key Resource Person
Department of Information Science and Engineering PES Institute of Technology
Bangalore
Most Renowned People
Alan Turing John McCarthy
Marvin Minsky
Book and Authors
Elaine Rich Kevin Knight
Shivashankar B Nair
Third edition Tata McGraw Hiil Rs
UNIT IPart I: Introduction: Concepts and definitions of AI, AI problems and
characteristics, AI Vs Natural Intelligence ( Turing Test), Applications of AI
Part II: Problems, Problem Spaces, Search: Defining the problem a State Space
Search Production System, Problem Characteristics, Production System Characteristics, Issues in the Design of Search Program, DFS,BFS
Part III: Heuristic Search Techniques: What is a Heuristics? Heuristic Function,
Search Techniques, Generate and Test, Hill Climbing, Best First Search, A* Algorithms
Part IV: Game Playing: AI in Games, Minimax Algorithm, Alpha Beta Pruning,
Examples
2020thth century centuryKarel Kapek writes “Rossum’s Universal Karel Kapek writes “Rossum’s Universal Robots”, coining the English word “robot”Robots”, coining the English word “robot”
Warren McCulloch and Walter Pitts lay Warren McCulloch and Walter Pitts lay partial groundwork for neural networkspartial groundwork for neural networks
Turing writes “Computing Machinery and Turing writes “Computing Machinery and Intelligence” – proposal of Turing testIntelligence” – proposal of Turing test
1956: John McCarthy coins phrase 1956: John McCarthy coins phrase “artificial intelligence”“artificial intelligence”
1952-62: Arthur Samuel writes the first 1952-62: Arthur Samuel writes the first AI game program to challenge a world AI game program to challenge a world champion, in part due to learning.champion, in part due to learning.
1950’s-60’s: Masterman et. al at 1950’s-60’s: Masterman et. al at Cambridge create semantic nets that Cambridge create semantic nets that do machine translation.do machine translation.
1961: James Slagle writes first 1961: James Slagle writes first symbolic integrator, SAINT, to solve symbolic integrator, SAINT, to solve calculus problems.calculus problems.
1963: Thomas Evan’s writes ANALOGY, 1963: Thomas Evan’s writes ANALOGY, which solves analogy problems like which solves analogy problems like the ones on IQ tests.the ones on IQ tests.
1965: J. A. Robinson invents Resolution 1965: J. A. Robinson invents Resolution Method using formal logic as its Method using formal logic as its representation language.representation language.
1965: Joseph Weizenbaum creates 1965: Joseph Weizenbaum creates ELIZA, one of the earliest “chatterbots”ELIZA, one of the earliest “chatterbots”
1967: Feigenbaum et. al create Dendral, 1967: Feigenbaum et. al create Dendral, the first useful knowledge-based agent the first useful knowledge-based agent that interpreted mass spectrographs.that interpreted mass spectrographs.
1969: Shakey the robot combines 1969: Shakey the robot combines movement, perception and problem movement, perception and problem solving.solving.
1971: Terry Winograd demonstrates a 1971: Terry Winograd demonstrates a program that can understand English program that can understand English commands in the word of blocks.commands in the word of blocks.
1972: Alain Colmerauer writes Prolog1972: Alain Colmerauer writes Prolog
1974: Ted Shortliffe creates MYCIN, the 1974: Ted Shortliffe creates MYCIN, the first expert system which showed the first expert system which showed the effectiveness of rule-based knowledge effectiveness of rule-based knowledge representation for medical diagnosis.representation for medical diagnosis.
1978: Herb Simon wins Nobel Prize for 1978: Herb Simon wins Nobel Prize for theory of bounded rationalitytheory of bounded rationality
1983: James Allen creates Interval 1983: James Allen creates Interval Calculus as a formal representation Calculus as a formal representation for events in time.for events in time.
1980’s: Backpropagation (invented 1980’s: Backpropagation (invented 1974) rediscovered and sees wide 1974) rediscovered and sees wide use in neural networksuse in neural networks
1985: ALVINN, “an autonomous land 1985: ALVINN, “an autonomous land vehicle in a neural network” navigates vehicle in a neural network” navigates across the country (2800 miles).across the country (2800 miles).
Early 1990’s: Gerry Tesauro creates TD-Early 1990’s: Gerry Tesauro creates TD-Gammon, a learning backgammon agent Gammon, a learning backgammon agent that vies with championship playersthat vies with championship players
1997: IBM Deep Blue defeats Garry 1997: IBM Deep Blue defeats Garry KasparovKasparov
The Future?The Future? Idea of Artificial Idea of Artificial
Intelligence is being Intelligence is being replaced by Artificial life, replaced by Artificial life, or anything with a form or or anything with a form or body. body.
The consensus among The consensus among scientists is that a scientists is that a requirement for life is that requirement for life is that it has an embodiment in it has an embodiment in some physical form, but some physical form, but this will change. Programs this will change. Programs may not fit this may not fit this requirement for life yet. requirement for life yet.
Definitions1. Intelligence: “ability to learn, understand and think” (Oxford dictionary)2. AI is the study of how to make computers make things which at the
moment people do better3. Making computational models of human behaviour4.4. Artificial Intelligence is the study of how to make real computers act like Artificial Intelligence is the study of how to make real computers act like
the ones in the movies.the ones in the movies.5. “To make computational models of human thought processes”6. “To build computational systems that behave intelligently”
Thinking humanly Thinking rationally
Acting humanly Acting rationally
Task Domains of AI • Mundane Tasks:
– Perception• Vision• Speech
– Natural Languages• Understanding• Generation• Translation
– Common sense reasoning– Robot Control
• Formal Tasks– Games : chess, checkers, Go, Sudoku etc– Mathematics: Geometry, logic, Proving properties of programs
• Expert Tasks:– Engineering ( Design, Fault finding, Manufacturing planning)– Scientific Analysis– Medical Diagnosis– Financial Analysis
Foundations of Artificial Intelligence 15
Thinking and Acting Humanly Thinking humanly: cognitive modeling
Develop a precise theory of mind, through experimentation and introspection, then write a computer program that implements it
Example: GPS - General Problem Solver (Newell and Simon, 1961) trying to model the human process of problem solving in general
Acting humanly "If it looks, walks, and quacks like a duck, then it is a duck” The Turing Test
interrogator communicates by typing at a terminal with TWO other agents. The human can say and ask whatever s/he likes, in natural language. If the human cannot decide which of the two agents is a human and which is a computer, then the computer has achieved AI
this is an OPERATIONAL definition of intelligence, i.e., one that gives an algorithm for testing objectively whether the definition is satisfied
Foundations of Artificial Intelligence 16
Thinking and Acting Rationally Thinking Rationally
Capture ``correct'' reasoning processes” A loose definition of rational thinking: Irrefutable reasoning process How do we do this
Develop a formal model of reasoning (formal logic) that “always” leads to the “right” answer Implement this model
How do we know when we've got it right? when we can prove that the results of the programmed reasoning are correct soundness and completeness of first-order logic
Acting Rationally Act so that desired goals are achieved The rational agent approach (this is what we’ll focus on in this course) Figure out how to make correct decisions, which sometimes means thinking rationally
and other times means having rational reflexes correct inference versus rationality reasoning versus acting; limited rationality
Turing’s Goal Alan Turing, Computing Machinery and Intelligence, 1950:
Can machines think? How could we tell?
“I propose to consider the question, ‘Can machines think?’ This should begin with definitions of the meaning of the terms ‘machine’ and ‘think’. The definitions might be framed so as to reflect so far as possible the normal use of the words, but this attitude is dangerous. If the meaning of the words ‘machine’ and ‘think’ are to be found by examining how they are commonly used it is difficult to escape the conclusion that the meaning and the answer to the question, ‘Can machines think?’ is to be sought in a statistical survey such as a Gallup poll. But this is absurd. Instead of attempting such a definition I shall replace the question by another, which is closely related to it and is expressed in relatively unambiguous words.” — Alan Turing, Computing machinery and intelligence, 1950
Turing’s “Imitation Game”
Interrogator B (a person) A (a machine)
Foundations of Artificial Intelligence 19
AI in Everyday Life?• AI techniques are used in many common applications
– Intelligent user interfaces– Search Engines– Spell/grammar checkers– Context sensitive help systems– Medical diagnosis systems– Regulating/Controlling hardware devices and processes (e.g, in automobiles)– Voice/image recognition (more generally, pattern recognition)– Scheduling systems (airlines, hotels, manufacturing)– Error detection/correction in electronic communication– Program verification / compiler and programming language design– Web search engines / Web spiders– Web personalization and Recommender systems (collaborative/content filtering)– Personal agents– Customer relationship management– Credit card verification in e-commerce / fraud detection– Data mining and knowledge discovery in databases– Computer games
Foundations of Artificial Intelligence 20
AI Spin-Offs Many technologies widely used today were the direct or indirect
results of research in AI: The mouse Time-sharing Graphical user interfaces Object-oriented programming Computer games Hypertext Information Retrieval The World Wide Web Symbolic mathematical systems (e.g., Mathematica, Maple, etc.) Very high-level programming languages Web agents Data Mining
Part IITo build a system to solve a problem
1. Define the problem precisely2. Analyse the problem3. Isolate and represent the task knowledge
that is necessary to solve the problem4. Choose the best problem-solving
techniques and apply it to the particular problem.
Defining the problem as State Space Search
• The state space representation forms the basis of most of the AI methods.
• Its structure corresponds to the structure of problem solving in two important ways:– It allows for a formal definition of a problem as the need to
convert some given situation into some desired situation using a set of permissible operations.
– It permits us to define the process of solving a particular problem as a combination of known techniques (each represented as a rule defining a single step in the space) and search, the general technique of exploring the space to try to find some path from current state to a goal state.
– Search is a very important process in the solution of hard problems for which no more direct techniques are available.
Example: Water Jug Problem
3 Gal4 Gal
Goal: 2 Gallons in the 4 Gal. Jug
UnlimitedWater
Production rules for Water Jug Problem
• The operators to be used to solve the problem can be described as follows:
Sl No Current state Next State Descritpion
1 (x,y) if x < 4 (4,y) Fill the 4 gallon jug
2 (x,y) if y <3 (x,3) Fill the 3 gallon jug
3 (x,y) if x > 0 (x-d, y) Pour some water out of the 4 gallon jug
4 (x,y) if y > 0 (x, y-d) Pour some water out of the 3-gallon jug
5 (x,y) if x>0 (0, y) Empty the 4 gallon jug
6 (x,y) if y >0 (x,0) Empty the 3 gallon jug on the ground
7 (x,y) if x+y >= 4 and y >0 (4, y-(4-x)) Pour water from the 3 –gallon jug into the 4 –gallon jug until the 4-gallon jug is full
Production rules8 (x, y) if x+y >= 3 and x>0 (x-(3-y), 3) Pour water from the 4-gallon jug
into the 3-gallon jug until the 3-gallon jug is full
9 (x, y) if x+y <=4 and y>0 (x+y, 0) Pour all the water from the 3-gallon jug into the 4-gallon jug
10 (x, y) if x+y <= 3 and x>0 (0, x+y) Pour all the water from the 4-gallon jug into the 3-gallon jug
11 (0,2) (2,0) Pour the 2 gallons from 3-gallon jug into the 4-gallon jug
12 (2,y) (0,y) Empty the 2 gallons in the 4-gallon jug on the ground
To solve the water jug problem• Required a control structure that
loops through a simple cycle in which some rule whose left side matches the current state is chosen, the appropriate change to the state is made as described in the corresponding right side, and the resulting state is checked to see if it corresponds to goal state.
• One solution to the water jug problem
• Shortest such sequence will have a impact on the choice of appropriate mechanism to guide the search for solution.
Gallons in the 4-gallon jug
Gallons in the 3-gallon jug
Rule applied
0 0 2
0 3 9
3 0 2
3 3 7
4 2 5 or 12
0 2 9 0r 11
2 0
Formal Description of the problem
1. Define a state space that contains all the possible configurations of the relevant objects.
2. Specify one or more states within that space that describe possible situations from which the problem solving process may start ( initial state)
3. Specify one or more states that would be acceptable as solutions to the problem. ( goal states)
4. Specify a set of rules that describe the actions ( operations) available.
Production SystemsA production system consists of:• 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 that rule is applied.
• One or more knowledge/databases that contain whatever information is appropriate for the particular task. Some parts of the database may be permanent, while other parts of it may pertain only to the solution of the current problem.
• A control strategy that specifies the order in which the rules will be compared to the database and a way of resolving the conflicts that arise when several rules match at once.
• A rule applier
Production systemIn order to solve a problem:• We must first reduce it to one for which a precise
statement can be given. This can be done by defining the problem’s state space ( start and goal states) and a set of operators for moving that space.
• The problem can then be solved by searching for a path through the space from an initial state to a goal state.
• The process of solving the problem can usefully be modelled as a production system.
Control Strategies
• How to decide which rule to apply next during the process of searching for a solution to a problem?
• The two requirements of good control strategy are that – it should cause motion.– It should be systematic
Breadth First Search
• Algorithm:1. Create a variable called NODE-LIST and set it to
initial state2. Until a goal state is found or NODE-LIST is empty
doa. Remove the first element from NODE-LIST and call it E. If
NODE-LIST was empty, quitb. For each way that each rule can match the state described
in E do:i. Apply the rule to generate a new stateii. If the new state is a goal state, quit and return this stateiii. Otherwise, add the new state to the end of NODE-LIST
BFS Tree for Water Jug problem
(0,0)
(4,0) (0,3)
(4,3) (0,0) (1,3) (4,3) (0,0) (3,0)
Breadth first search
Algorithm: Depth First Search
1. If the initial state is a goal state, quit and return success
2. Otherwise, do the following until success or failure is signaled:
a. Generate a successor, E, of initial state. If there are no more successors, signal failure.
b. Call Depth-First Search, with E as the initial state
c. If success is returned, signal success. Otherwise continue in this loop.
Depth first search
Backtracking• In this search, we pursue a singal branch of the tree until
it yields a solution or until a decision to terminate the path is made.
• It makes sense to terminate a path if it reaches dead-end, produces a previous state. In such a state backtracking occurs
• Chronological Backtracking: Order in which steps are undone depends only on the temporal sequence in which steps were initially made.
• Specifically most recent step is always the first to be undone.
• This is also simple backtracking.
Advantages of Depth-First Search
• DFS requires less memory since only the nodes on the current path are stored.
• By chance, DFS may find a solution without examining much of the search space at all.
Advantages of BFS
• BFS will not get trapped exploring a blind alley.
• If there is a solution, BFS is guaranteed to find it.
• If there are multiple solutions, then a minimal solution will be found.
TSP• A simple motion causing and systematic control structure
could solve this problem.• Simply explore all possible paths in the tree and return
the shortest path.• If there are N cities, then number of different paths
among them is 1.2….(N-1) or (N-1)!• The time to examine single path is proportional to N• So the total time required to perform this search is
proportional to N!• For 10 cities, 10! = 3,628,800• This phenomenon is called Combinatorial explosion.
Branch and Bound• Begin generating complete paths, keeping track
of the shortest path found so far.• Give up exploring any path as soon as its partial
length becomes greater than the shortest path found so far.
• Using this algorithm, we are guaranteed to find the shortest path.
• It still requires exponential time.• The time it saves depends on the order in which
paths are explored.
Heuristic Search• A Heuristic is a technique that improves the efficiency of a search
process, possibly by sacrificing claims of completeness.• Heuristics are like tour guides• They are good to the extent that they point in generally interesting
directions;• They are bad to the extent that they may miss points of interest to
particular individuals.• On the average they improve the quality of the paths that are
explored.• Using Heuristics, we can hope to get good ( though possibly
nonoptimal ) solutions to hard problems such asa TSP in non exponential time.
• There are good general purpose heuristics that are useful in a wide variety of problem domains.
• Special purpose heuristics exploit domain specific knowledge
Nearest Neighbour Heuristic• It works by selecting locally superior alternative at each
step.• Applying to TSP:
1. Arbitrarily select a starting city2. To select the next city, look at all cities not yet visited and
select the one closest to the current city. Go to next step.3. Repeat step 2 until all cities have been visited.
– This procedure executes in time proportional to N2
– It is possible to prove an upper bound on the error it incurs. This provides reassurance that one is not paying too high a price in accuracy for speed.
Heuristic Function• This is a function that maps from problem state
descriptions to measures of desirsability, usually represented as numbers.– Which aspects of the problem state are considered,– how those aspects are evaluated, and – the weights given to individual aspects are chosen in such a way
that • the value of the heuristic function at a given node in the
search process gives as good an estimate as possible of whether that node is on the desired path to a solution.
• Well designed heuristic functions can play an important part in efficiently guiding a search process toward a solution.
Example Simple Heuristic functions
• Chess : The material advantage of our side over opponent.
• TSP: the sum of distances so far• Tic-Tac-Toe: 1 for each row in which we
could win and in we already have one piece plus 2 for each such row in we have two pieces
Problem Characteristics• Inorder to choose the most appropriate method for a
particular problem, it is necessary to analyze the problem along several key dimensions:– Is the problem decomposable into a set of independent smaller
or easier subproblems?– Can solution steps be ignored or at least undone if they prove
unwise?– Is the problem’s universe predictable?– Is a good solution to the problem obvious without comparison to
all other possible solutions?– Is the desired solution a state of the world or a path to a state?– Is a large amount of knowledge absolutely required to solve the
problem or is knowledge important only to constrain the search?– Can a computer that is simply given the problem return the
solution or will the solution of the problem require interaction between the computer and a person?
Is the problem Decomposable?
• Whether the problem can be decomposed into smaller problems?
• Using the technique of problem decomposition, we can often solve very large problems easily.
Blocks World Problem
• Following operators are available:
• CLEAR(x) [ block x has nothing on it]-> ON(x, Table)
• CLEAR(x) and CLEAR(y) -> ON(x,y) [ put x on y]
C
A B
A
B
C
Start: ON(C,A)
Goal: ON(B,C) and ON(A,B)
ON(B,C)
ON(B,C) and ON(A,B)
ON(B,C)
ON(A,B)
CLEAR(A) ON(A,B)
CLEAR(A) ON(A,B)
Can Solution Steps be ignored or undone?
• Suppose we are trying to prove a math theorem.We can prove a lemma. If we find the lemma is not of any help, we can still continue.
• 8-puzzle problem• Chess: A move cannot be taken back.• Important classes of problems:
– Ignorable ( theorem proving)– Recoverable ( 8-puzzle)– Irrecoverable ( Chess)
• The recoverability of a problem plays an important role in determining the complexity of the control structure necessary for the problem’s solution.– Ignorable problems can be solved using a simple control structure that
never backtracks– Recoverable problems can be solved by a slightly more complicated
control strategy that does sometimes make mistakes– Irrecoverable problems will need to be solved by systems that expends
a great deal of effort making each decision since decision must be final.
Is the universe Predictable?• Certain Outcome ( ex: 8-puzzle)• Uncertain Outcome ( ex: Bridge, controlling a
robot arm)• For solving certain outcome problems, open loop
approach ( without feedback) will work fine.• For uncertain-outcome problems, planning can
at best generate a sequence of operators that has a good probability of leading to a solution. We need to allow for a process of plan revision to take place.
Is a good solution absolute or relative?
• Any path problem• Best path problem
• Any path problems can often be solved in a reasonable amount of time by using heuristics that suggest good paths to explore.
• Best path problems are computationally harder.
Is the solution a state or a path?
• Examples:– Finding a consistent interpretation for the sentence
“The bank president ate a dish of pasta salad with the fork”. We need to find the interpretation but not the record of the processing.– Water jug : Here it is not sufficient to report that we
have solved , but the path that we found to the state (2,0). Thus the a statement of a solution to this
problem must be a sequence of operations ( Plan) that produces the final state.
What is the role of knowledge?• Two examples:
– Chess: Knowledge is required to constrain the search for a solution– Newspaper story understanding: Lot of knowledge is required even to
be able to recognize a solution.• Consider a problem of scanning daily newspapers to decide which
are supporting the democrats and which are supporting the republicans in some election. We need lots of knowledge to answer such questions as:– The names of the candidates in each party– The facts that if the major thing you want to see done is have taxes
lowered, you are probably supporting the republicans– The fact that if the major thing you want to see done is improved
education for minority students, you are probably supporting the democrats.
– etc
Does the task require Interaction with a person?
• The programs require intermediate interaction with people for additional inputs and to provided reassurance to the user.
• There are two types of programs:– Solitary– Conversational:
• Decision on using one of these approaches will be important in the choice of problem solving method.
Problem Classification
• There are several broad classes into which the problems fall. These classes can each be associated with generic control strategy that is appropriate for solving the problems:– Classification : ex: medical diagnostics,
diagnosis of faults in mechanical devices– Propose and Refine: ex: design and planning
Production System Characteristics1. Can production systems, like problems, be described by a set of
characteristics that shed some light on how they can easily be implemented?
2. If so, what relationships are there between problem types and the types of production systems best suited to solving the problems?
• Classes of Production systems:– Monotonic Production System: 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.
– Non-Monotonic Production system– Partially commutative Production system: property that if application
of a particular sequence of rules transforms state x to state y, then permutation of those rules allowable, also transforms state x into state y.
– Commutative Production system
Monotonic Production Systems
• 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 applied.
• i.e., rules are independent.
Commutative Production system
• A partially Commutative production system has a property that if the application of a particular sequence of rules transform state x into state y, then any permutation of those rules that is allowable, also transforms state x into state y.
• A Commutative production system is a production system that is both monotonic and partially commutative.
Partially Commutative, Monotonic• These production systems are useful for solving
ignorable problems.• Example: Theorem Proving• They can be implemented without the ability to backtrack
to previous states when it is discovered that an incorrect path has been followed.
• This often results in a considerable increase in efficiency, particularly because since the database will never have to be restored, It is not necessary to keep track of where in the search process every change was made.
• They are good for problems where things do not change; new things get created.
Non Monotonic, Partially Commutative
• Useful for problems in which changes occur but can be reversed and in which order of operations is not critical.
• Example: Robot Navigation, 8-puzzle, blocks world
• Suppose the robot has the following ops: go North (N), go East (E), go South (S), go West (W). To reach its goal, it does not matter whether the robot executes the N-N-E or N-E-N.
Not partially Commutative• Problems in which irreversible change occurs• Example: chemical synthesis• The ops can be :Add chemical x to the pot, Change the temperature
to t degrees.• These ops may cause irreversible changes to the potion being
brewed.• The order in which they are performed can be very important in
determining the final output.• (X+y) +z is not the same as (z+y) +x • Non partially commutative production systems are less likely to
produce the same node many times in search process.• When dealing with ones that describe irreversible processes, it is
partially important to make correct decisions the first time, although if the universe is predictable, planning can be used to make that less important.
Four Categories of Production System
Monotonic NonMonotonic
Partially Commutative
Theorem proving
Robot Navigation
Not Partially Commutative
Chemical Synthesis
Bridge
Issues in the design of search programs
• The direction in which to conduct the search ( forward versus backward reasoning).
• How to select applicable rules ( Matching)• How to represent each node of the search
process ( knowledge representation problem)
64
An 8-Puzzle Problem Solved by the Hill Climbing Method