AIML Module 1
AIML Module 1
Introduction:
attempt to build machines that like humans can think and act, able to learn and use
knowledge to solve problems on their own.
1) Game Playing
Deep Blue Chess program beat world champion Gary Kasparov
2) Speech Recognition
PEGASUS spoken language interface to American Airlines' EAASY SABRE reservation
system, which allows users to obtain flight information and make reservations over the
1
telephone. The 1990s has seen significant advances in speech recognition so that
limitedsystems are now successful.
3) Computer Vision
Face recognition programs in use by banks, government, etc. The ALVINN system from
CMU autonomously drove a van from Washington, D.C. to San Diego (all but 52 of 2,849
miles), averaging 63 mph day and night, and in all weather conditions. Handwriting
recognition, electronics and manufacturing inspection, photo interpretation, baggage
inspection, reverse engineering to automatically construct a 3D geometric model.
4) Expert Systems
Application-specific systems that rely on obtaining the knowledge of human experts in
anarea and programming that knowledge into a system.
a. Diagnostic Systems: MYCIN system for diagnosing bacterial infections of the
blood and suggesting treatments. Intellipath pathology diagnosis system (AMA
approved). Pathfinder medical diagnosis system, which suggests tests and
makesdiagnoses. Whirlpool customer assistance center.
b. System Configuration
DEC's XCON system for custom hardware configuration. Radiotherapy treatment planning.
c. Financial Decision Making
Credit card companies, mortgage companies, banks, and the U.S.
governmentemploy AI systems to detect fraud and expedite financial
transactions. For example, AMEX credit check.
d. Classification Systems
Put information into one of a fixed set of categories using several sources of
information. E.g., financial decision making systems. NASA developed a system for
classifying very faint areas in astronomical images into either stars or galaxies with
very high accuracy by learning from human experts' classifications.
5) Mathematical Theorem Proving
Use inference methods to prove new theorems.
6) Natural Language Understanding
AltaVista's translation of web pages. Translation of Catepillar Truck manuals into 20 languages.
2
7) Scheduling and Planning
Automatic scheduling for manufacturing. DARPA's DART system used in Desert Storm and
Desert Shield operations to plan logistics of people and supplies. American Airlines rerouting
contingency planner. European space agency planning and scheduling of spacecraft
assembly,integration and verification.
8) Artificial Neural Networks:
9) Machine Learning
Applications of AI:
AI algorithms have attracted close attention of researchers and have also been applied
successfully to solve problems in engineering. Nevertheless, for large and complex problems,
AI algorithms consume considerable computation time due to stochastic feature of the search
approaches
Building AI Systems:
1) Perception
Intelligent biological systems are physically embodied in the world and experience the
world through their sensors (senses). For an autonomous vehicle, input might be images
from a camera and range information from a rangefinder. For a medical diagnosis
3
system, perception is the set of symptoms and test results that have been obtained and
input to thesystem manually.
2) Reasoning
Inference, decision-making, classification from what is sensed and what the internal "model" is of
the world. Might be a neural network, logical deduction system, Hidden Markov Model
induction,heuristic searching a problem space, Bayes Network inference, genetic algorithms, etc.
Includes areas of knowledge representation, problem solving, decision theory, planning, game
theory, machine learning, uncertainty reasoning, etc.
3) Action
Biological systems interact within their environment by actuation, speech, etc. All behavior is
centered around actions in the world. Examples include controlling the steering of a Mars rover or
autonomous vehicle, or suggesting tests and making diagnoses for a medical diagnosis system.
Includes areas of robot actuation, natural language generation, and speech synthesis.
The definitions of AI:
4
c) "The art of creating machines that d) "A field of study that seeks to explain
performfunctions that require and emulate intelligent behavior in
intelligence when performed by people" terms of computational processes"
(Kurzweil, 1990) (Schalkoff, 1 990)
"The branch of computer science
"The study of how to make that is concerned with the
computersdo things at which, at the automation of intelligent
moment, people are better" (Rich behavior"
and Knight, 1 (Luger and Stubblefield, 1993)
99 1 )
The definitions on the top, (a) and (b) are concerned with reasoning, whereas those on the
bottom, (c) and (d) address behavior. The definitions on the left, (a) and (c) measure success
interms of human performance, and those on the right, (b) and (d) measure the ideal concept
of intelligence called rationality
Intelligent Systems:
In order to design intelligent systems, it is important to categorize them into four
categories(Luger and Stubberfield 1993), (Russell and Norvig, 2003)
1. Systems that think like humans
2. Systems that think rationally
3. Systems that behave like humans
4. Systems that behave rationally
Human- Rationall
Like y
5
Cognitive Science: Think Human-Like
b. Focus is not just on behavior and I/O, but looks like reasoning process.
c. Goal is not just to produce human-like behavior but to produce a sequence of steps of
thereasoning process, similar to the steps followed by a human in solving the same task.
a. The study of mental faculties through the use of computational models; that it is,
thestudy of computations that make it possible to perceive reason and act.
b. Focus is on inference mechanisms that are probably correct and guarantee an optimal solution.
c. Goal is to formalize the reasoning process as a system of logical rules and procedures
ofinference.
b. Focus is on action, and not intelligent behavior centered around the representation of the world
6
o The machine tries to fool the interrogator to believe that it is the
human, and the person also tries to convince the interrogator that it is
the human.
A human agent has eyes, ears, and other organs for sensors and hands, legs,
mouth,and other body parts for actuators.
A robotic agent might have cameras and infrared range finders for sensors
andvarious motors foractuators.
A software agent receives keystrokes, file contents, and network packets as
7
sensoryinputs and acts on the environment by displaying on the screen, writing
files, and sending network packets.
Percept:
We use the term percept to refer to the agent's perceptual inputs at any given instant.
Percept Sequence:
An agent's percept sequence is the complete history of everything the agent has ever perceived.
Agent function:
Mathematically speaking, we say that an agent's behavior is described by the agent
functionthat maps any given percept sequence to an action.
Agent program
Internally, the agent function for an artificial agent will be implemented by an agent
program. It is important to keep these two ideas distinct. The agent function is an
abstract
Fig 2.1.6: Partial tabulation of a simple agent function for the example: vacuum-cleaner world shown in the
Fig2.1.5
Fig 2.1.6(i): The REFLEX-VACCUM-AGENT program is invoked for each new percept
(location, status) and returns an action each time
A Rational agent is one that does the right thing. we say that the right action is the one that
willcause the agent to be most successful. That leaves us with the problem of deciding how
and when to evaluate the agent's success.
We use the term performance measure for the how—the criteria that determine how
successfulan agent is.
9
Ex-Agent cleaning the dirty floor
Performance Measure-Amount of dirt collected
When to measure-Weekly for better results
ENVIRONMENTS:
The Performance measure, the environment and the agents actuators and sensors comes under
the heading task environment. We also call this as
PEAS(Performance,Environment,Actuators,Sensors)
10
Environment-Types:
11
5. Discrete vs. continuous:
If there are a limited number of distinct, clearly defined percepts and actions we
saythat the environment is discrete. Otherwise, it is continuous.
The job of AI is to design the agent program: a function that implements the agent mapping
from percepts to actions. We assume this program will run on some sort of ARCHITECTURE
computing device, which we will call the architecture.
The architecture might be a plain computer, or it might include special-purpose hardware for
certain tasks, such as processing camera images or filtering audio input. It might also include
software that provides a degree of insulation between the raw computer and the agent
program,so that we can program at a higher level. In general, the architecture makes the
percepts from the sensors available to the program, runs the program, and feeds the
program's action choices to the effectors as they are generated.
The relationship among agents, architectures, and programs can be summed up as
follows:agent = architecture + program
12
Agent programs:
Intelligent agents accept percepts from an environment and generates actions. The
earlyversions of agent programs will have a very simple form (Figure 2.4)
Each will use some internal data structures that will be updated as new percepts arrive.
These data structures are operated on by the agent's decision-making procedures to
generate anaction choice, which is then passed to the architecture to be executed
Types of agents:
Agents can be grouped into four classes based on their degree of perceived intelligence and capability :
Simple Reflex Agents
13
Model-Based Reflex Agents
Goal-Based Agents
Utility-Based Agents
Simple reflex agents:
Simple reflex agents ignore the rest of the percept history and act only on the basis
ofthe current percept.
The agent function is based on the condition-action rule.
If the condition is true, then the action is taken, else not. This agent function only succeeds
whenthe environment is fully observable.
14
Goal-based agents:
Utility-based agents:
A utility-based agent is an agent that acts based not only on what the goal is, but the best way to reach
thatgoal.
The Utility-based agent is useful when there are multiple possible alternatives, and an agent has
tochoose in order to perform the best action.
The term utility can be used to describe how "happy" the agent is.
15
Problem Solving Agents:
Problem solving agent is a goal-based agent.
Problem solving agents decide what to do by finding sequence of actions that lead to desirable states.
Goal Formulation:
It organizes the steps required to formulate/ prepare one goal out of multiple goals available.
Problem Formulation:
It is a process of deciding what actions and states to consider to follow goal
formulation.The process of looking for a best sequence to achieve a goal is called
Search.
A search algorithm takes a problem as input and returns a solution in the form of action sequences.
Once the solution is found the action it recommends can be carried out. This is called Execution
phase.Well Defined problems and solutions:
A problem can be defined formally by 4 components:
The initial state of the agent is the state where the agent starts in. In this case, the initial state can be
16
described as In: Arad
The possible actions available to the agent, corresponding to each of the state the agent
residesin.
For example, ACTIONS(In: Arad) = {Go: Sibiu, Go: Timisoara, Go: Zerind}.
Actions are also known as operations.
A description of what each action does.the formal name for this is Transition model,Specified by
thefunction Result(s,a) that returns the state that results from the action a in state s.
We also use the term Successor to refer to any state reachable from a given state by a single
action.For EX:Result(In(Arad),GO(Zerind))=In(Zerind)
Together the initial state,actions and transition model implicitly defines the state space of the
problemState space: set of all states reachable from the initial state by any sequence of actions
The goal test, determining whether the current state is a goal state. Here, the goal state is
{In:Bucharest}
The path cost function, which determine the cost of each path, which is reflecting in
theperformance measure.
we define the cost function as c(s, a, s’), where s is the current state and a is the action performed by
theagent to reach state s’.
17
Example –
8 puzzle problem
Initial State
Goal State
States: a state description specifies the location of each of the eight tiles in one of the
ninesquares. For efficiency, it is useful to include the location of the blank.
Actions: blank moves left, right, up, or down.
Transition Model: Given a state and action, this returns the resulting state. For example if
weapply left to the start state the resulting state has the 5 and the blank switched.
Goal test: state matches the goal configuration shown in fig.
Path cost: each step costs 1, so the path cost is just the length of the path.
18
State Space Search/Problem Space Search:
The state space representation forms the basis of most of the AI methods.
Formulate a problem as a state space search by showing the legal problem states, the
legal operators, and the initial and goal states.
A state is defined by the specification of the values of all attributes of interest in the world
An operator changes one state into the other; it has a precondition which is the value of
certain attributes prior to the application of the operator, and a set of effects, which
arethe attributes altered by the operator
The initial state is where you start
The goal state is the partial description of the solution
19
Example: 8-queens problem
Search strategies:
Search: Searching is a step by step procedure to solve a search-problem in a given search space. A
search problem can have three main factors:
Search Space: Search space represents a set of possible solutions, which a system may
have.Start State: It is a state from where agent begins the search.
Goal test: It is a function which observe the current state and returns whether the goal state is
achievedor not.
20
Properties of Search Algorithms
Which search algorithm one should use will generally depend on the
problemdomain. There are four important factors to consider:
2. Optimality – Is the solution found guaranteed to be the best (or lowest cost) solution if
3. Time Complexity – The upper bound on the time required to find a solution, as a function
Searching
Many traditional search algorithms are used in AI applications. For complex problems, the traditional
algorithms are unable to find the solution within some practical time and space limits. Consequently,
many special techniques are developed; using heuristic functions. The algorithms that use heuristic
21
functions are called heuristic algorithms. Heuristic algorithms are not really intelligent; they appear to
be intelligent because they achieve better performance.
Heuristic algorithms are more efficient because they take advantage of feedback from the data to
directthe search path.
Uninformed search
Also called blind, exhaustive or brute-force search, uses no information about the problem to guide
thesearch and therefore may not be very efficient.
Informed Search:
Also called heuristic or intelligent search, uses information about the problem to guide the search, usually
guesses the distance to a goal state and therefore efficient, but the search may not be always possible.
One simple search strategy is a breadth-first search. In this strategy, the root node is
expanded first, then all the nodes generated by the root node are expanded next, and
thentheir successors, and so on.
In general, all the nodes at depth d in the search tree are expanded before the nodes at depth d
+ 1.
BFS illustrated:
22
Step 1: Initially frontier contains only one node corresponding to the source state A.
Figure 1
Frontier: A
Step 2: A is removed from fringe. The node is expanded, and its children B and C are generated.
They are placed at the back of fringe.
Figure 2
Frontier: B C
Step 3: Node B is removed from fringe and is expanded. Its children D, E are generated and
Step 4: Node C is removed from fringe and is expanded. Its children D and G are added to
theback of fringe.
23
Figure 4
Frontier: D E D G
Step 5: Node D is removed from fringe. Its children C and F are generated and added to the
backof fringe.
Figure 5
Frontier: E D G C F
Figure 6
Frontier: D G C F
24
Figure 7
Frontier: G C F B F
Step 8: G is selected for expansion. It is found to be a goal node. So the algorithm returns
thepath A C G by following the parent pointers of the node corresponding to G. The
algorithm terminates.
25
BFS will provide a solution if any solution exists.
If there are more than one solutions for a given problem, then BFS will provide the minimal
solutionwhich requires the least number of steps.
Disadvantages:
Requires the generation and storage of a tree whose size is exponential the depth of
theshallowest goal node.
The breadth first search algorithm cannot be effectively used unless the search space
isquite small.
Applications Of Breadth-First Search Algorithm
GPS Navigation systems: Breadth-First Search is one of the best algorithms used to find neighboring
locations by using the GPS system.
Broadcasting: Networking makes use of what we call as packets for communication. These packets
follow a traversal method to reach various networking nodes. One of the most commonly used
traversal
26
DFS illustrated:
Figure 1
FRINGE: A
Step 2: A is removed from fringe. A is expanded and its children B and C are put in front of
fringe.
Figure 2
FRINGE: B C
Step 3: Node B is removed from fringe, and its children D and E are pushed in front of fringe.
Figure 3
27
FRINGE: D E C
Step 4: Node D is removed from fringe. C and F are pushed in front of fringe.
Figure 4
FRINGE: C F E C
Step 5: Node C is removed from fringe. Its child G is pushed in front of fringe.
Figure 5
Figure 5
FRINGE: G F E C
Step 6: Node G is expanded and found to be a goal node.
Figure 6
28
FRINGE: G F E C
Note that the time taken by the algorithm is related to the maximum depth of the search tree. If the
search tree has infinite depth, the algorithm may not terminate. This can happen if the search space is
infinite. It can also happen if the search space contains cycles. The latter case can be handled by
checking for cycles in the algorithm. Thus Depth First Search is not complete.
Advantages:
It combines the benefits of BFS and DFS search algorithm in terms of fast search and
memoryefficiency.
Disadvantages:
The main drawback of IDDFS is that it repeats all the work of the previous phase.
29
Iterative deepening search L=1
Complete: Yes
Time: O(bd)
Space: O(bd)
Conclusion:
30
We can conclude that IDS is a hybrid search strategy between BFS and DFS inheriting
their advantages.
IDS is faster than BFS and DFS.
Itissaidthat “IDSisthepreferreduniformedsearchmethodwhen thereisalargesearchspace and the
depthof the solution is not known
might not always find the best solution but is guaranteed to find a good solution
inreasonable time. By sacrificing completeness it increases efficiency.
Useful in solving tough problems which
o could not be solved any other way.
o solutions take an infinite time or very long time to compute.
Source state
1 3 2
31
6 5 4
8 7
destination state
1 2 3
4 5 6
7 8
Then the Manhattan distance would be sum of the no of moves required to move
eachnumber from source state to destination state.
Number in 8 1 2 3 4 5 6 7 8
puzzle
No. of moves 0 2 1 2 0 2 2 0
to reach
destination
Source state
1 3 2
6 5 4
8 7
Destination state
1 2 3
4 5 6
7 8
Here just calculate the number of tiles that have to be changed to reach goal
stateHere 1,5,8 need not be changed
2,3,4,6,7 should be changed, so the heuristic value will be 5(because 5 tiles have to be changed)
Hill climbing algorithm is a local search algorithm which continuously moves in the
direction of increasing elevation/value to find the peak of the mountain or best solution
tothe problem. It terminates when it reaches a peak value where no neighbor has a
higher value.
32
It is also called greedy local search as it only looks to its good immediate neighbor
stateand not beyond that.
Hill Climbing is mostly used when a good heuristic is available.
In this algorithm, we don't need to maintain and handle the search tree or graph as it
onlykeeps a single current state.
Local Maximum: Local maximum is a state which is better than its neighbor states, but there is also another state which is
higher than it.
Global Maximum: Global maximum is the best possible state of state space landscape. It has the highest value of objective
function.
Flat local maximum: It is a flat space in the landscape where all the neighbor states of current states have the same value.
33
Problems in Hill Climbing Algorithm:
34
A hill-climbing algorithm that never makes “downhill” moves towards states with lower value
(or higher cost) is guaranteed to be incomplete, because it can stuck on a local maximum. In
contrast, a purely random walk –that is, moving to a successor chosen uniformly at random
from the set of successors – is complete, but extremely inefficient. Simulated annealing is an
algorithm that combines hill-climbing with a random walk in some way that yields both
efficiency and completeness.
simulated annealing algorithm is quite similar to hill climbing. Instead of picking the best
move, however, it picks the random move. If the move improves the situation, it is always
accepted. Otherwise, the algorithm accepts the move with some probability less than 1.
The
probability decreases exponentially with the “badness” of the move – the amount E by which
the evaluation is worsened. The probability also decreases as the "temperature" T goes down: "bad
moves are more likely to be allowed at the start when temperature is high, and they become more
unlikely as T decreases. One can prove that if the schedule lowers T slowly enough, the algorithm will
find a global optimum with probability approaching 1.
Simulated annealing was first used extensively to solve VLSI layout problems. It has been applied widely
to factory scheduling and other large-scale optimization tasks.
OPEN is a priority queue of nodes that have been evaluated by the heuristic function but
35
whichhave not yet been expanded into successors. The most promising nodes are at the front.
CLOSED are nodes that have already been generated and these nodes must be stored because
agraph is being used in preference to a tree.
Algorithm:
• If it has been generated before change the parent if this new path is
betterand in that case update the cost of getting to any successor
nodes.
Example:
36
1. It is not optimal.
2. It is incomplete because it can start down an infinite path and never return to try
otherpossibilities.
3. The worst-case time complexity for greedy search is O (bm), where m is the
maximumdepth of the search space.
4. Because greedy search retains all nodes in memory, its space complexity is the same
asits time complexity
A* Algorithm
The A* search algorithm (pronounced "Ay-star") is a tree search algorithm that finds a path
from a given initial node to a given goal node (or one passing a given goal test). It employs a
"heuristic estimate" which ranks each node by an estimate of the best route that goes through
37
thatnode. It visits the nodes in order of this heuristic estimate.
Similar to greedy best-first search but is more accurate because A* takes into account the
nodes that have already been traversed.
g is a measure of the distance/cost to go from the initial node to the current node
Thus fis an estimate of how long it takes to go from the initial node to the solution
Algorithm:
save n in CLOSED
a) If m € [OPEN U
CLOSED] Set g(m) =
g(n) + c(n , m) Set f(m)
= g(m) + h(m)
Insert m in OPEN
b) If m € [OPEN U CLOSED]
Move m to OPEN.
Description:
38
A* begins at a selected node. Applied to this node is the "cost" of entering this node
(usually zero for the initial node). A* then estimates the distance to the goal node
from the current node. This estimate and the cost added together are the heuristic
which is assigned to the path leading to this node. The node is then added to a priority
queue, oftencalled "open".
The algorithm then removes the next node from the priority queue (because of the way
a priority queue works, the node removed will have the lowest heuristic). If the queue is
empty, there is no path from the initial node to the goal node and the algorithm stops. If
the node is the goal node, A* constructs and outputs the successful path and stops.
If the node is not the goal node, new nodes are created for all admissible adjoining
nodes;the exact way of doing this depends on the problem at hand. For each successive
node, A* calculates the "cost" of entering the node and saves it with the node. This cost
is calculated from the cumulative sum of costs stored with its ancestors, plus the cost of
the operation which reached this new node.
The algorithm also maintains a 'closed' list of nodes whose adjoining nodes have been
checked. If a newly generated node is already in this list with an equal or lower cost, no
further processing is done on that node or with the path associated with it. If a node in
the closed list matches the new one, but has been stored with a higher cost, it is
removed from the closed list, and processing continues on the new node.
Next, an estimate of the new node's distance to the goal is added to the cost to form the
heuristic for that node. This is then added to the 'open' priority queue, unless an identical node
is found there.
Once the above three steps have been repeated for each new adjoining node, the original node
taken from the priority queue is added to the 'closed' list. The next node is then popped from
the priority queue and the process is repeated
39
The heuristic costs from each city to Bucharest:
40
41
A* search properties:
The algorithm A* is admissible. This means that provided a solution exists, the first
solutionfound by A* is an optimal solution. A* is admissible under the following
conditions:
A* is also complete.
Sometimes a problem is not embedded in a long set of action sequences but requires picking the
best option from available choices. A good general-purpose problem solving technique is to list
the constraints of a situation (either negative constraints, like limitations, or positive elements
that you want in the final solution). Then pick the choice that satisfies most of the constraints.
Formally speaking, a constraint satisfaction problem (or CSP) is defined by a set of variables,
X1;X2; : : :
;Xn, and a set of constraints, C1;C2; : : : ;Cm. Each variable Xi has anonempty domain Di of
possible values. Each constraint Ci involves some subset of tvariables and specifies the allowable
combinations of values for that subset. A state of theproblem is defined by an assignment of
values to some or all of the variables, {Xi = vi;Xj =vj ; : : :} An assignment that does not violate any
constraints is called a consistent or
legalassignment. A complete assignment is one in which every variable is mentioned, and a
solution to a CSP is a complete assignment that satisfies all the constraints. Some CSPs also
require a solution that maximizes an objectivefunction.
1. Initial state: the empty assignment fg, in which all variables are unassigned.
2. Successor function: a value can be assigned to any unassigned variable, provided that it
doesnot conflict with previously assigned variables.
42
3. Goal test: the current assignment is complete.
4. Path cost: a constant cost for every step
Examples:
The task of coloring each region red, green or blue in such a way that no
neighboringregions have the same color.
We are given the task of coloring each region red, green, or blue in such a way that
theneighboring regions must not have the same color.
To formulate this as CSP, we define the variable to be the regions: WA, NT, Q, NSW, V, SA, and
T. The domain of each variable is the set {red, green, blue}. The constraints require
neighboring regions to have distinct colors: for example, the allowable combinations
forWA and NT are the pairs
{(red,green),(red,blue),(green,red),(green,blue),(blue,red),(blue,green)}. (The constraint
can also be represented as the inequality WA ≠ NT). There aremany possible solutions,
43
such as {WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = red}.Map
of Australia showing each of its states and territories
Constraint Graph: A CSP is usually represented as an undirected graph, called
constraint graph where the nodes are the variables and the edges are the
binaryconstraints.
problemas follows:
> Initial state : the empty assignment {},in which all variables are unassigned.
> Successor function: a value can be assigned to any unassigned variable, provided
that it does not conflict with previously assigned variables.
> Goal test: the current assignment is complete.
> Path cost: a constant cost(E.g.,1) for every step.
44