21cs502 Ai Unit-I Notes Short 42 Pges
21cs502 Ai Unit-I Notes Short 42 Pges
UNIT I
ARTIFICIAL INTELLIGENCE AND INTELLIGENT AGENTS
Introduction to AI – Foundations of Artificial Intelligence - Intelligent Agents – Agents and
INTRODUCTION TO AI
Definition
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.
1
Four Categories of Definitions of Artificial Intelligence
To pass the Turing Test, the computer would need to process the following
capabilities:
o Natural Language Processing
o Knowledge Representation
o Automated Reasoning
o Machine Learning
2
The Total Turing Test is another step ahead of the Turing Test where a video signal
is also included so that the interrogator can test the perceptual abilities of the
interacting computer in addition to the verbal behaviors. The Total Turing Test
requires the following additional skills
o Computer Vision
o Robotics
2. Thinking humanly: The cognitive modeling approach
Thinking humanly means trying to understand and model how the human mind works.
The three ways are:
o Through introspection — trying to catch our own thoughts as they go by;
o Through psychological experiments — observing a person in action;
o Through brain imaging — observing the brain in action.
Example:General Problem Solver(GPS) to model human thinking and check whether
it can solve problems like a person by following the same reasoning steps as a human.
The intent of the program is not just to solve the problem correctly but to go
through the same series of steps as that of a human brain to solve it.
Think rationally is the ability to think with reason and draw sensible conclusions from
facts, logic and data.
It could be defined as thoughts based on facts and not emotions.
Example : Syllogisms
“All TVs use energy; Energy always generates heat; therefore, all TVs generate heat.”
These arguments initiated the field called logic. Notations for statements for all kinds of objects
were developed and interrelated between them to show logic.
Logical notation:
3
4.Acting rationally: The rational agent approach
A traditional computer program blindly executes the code that we write. Neither it acts on its
own nor it adapts to change itself based on the outcome.
The so-called agent program that we refer to here is expected to do more than the traditional
computer program. It is expected to create and pursue the goal, change state, and operate
autonomously.
An agent is a computer program that has the following attributes:
o Autonomous control
o Perceive environment
o Adapt to change
o Act and pursue goals
The rational agent approach to AI has a couple of advantage over other approaches:
1. A correct inference is considered a possible way to achieve rationality but is not always
required to achieve rationality.
2. It is a more manageable scientific approach to define rationality than others that are based
on human behavior or human thought.
….………………………………………………………………………………………………………………………..
FOUNDATIONS OF ARTIFICIAL INTELLIGENCE
4
Advantages of Artificial Intelligence
High Accuracy with less errors
High-Speed
High reliability
Digital Assistant
o No Original Creativity
5
Alan Turing proposed a test to check the machine’s ability to exhibit intelligent behavior
equivalent to human.
John McCarthy coined the word Artificial Intelligence at the Dartmouth Conference
Feigenbaum and others at Stanford began the Heuristic Programming Project (HPP) to
investigate the extent to which the new methodology of expert systems could be applied to
other areas of human expertise.
Expert systems were programmed that emulate the decision-making ability of a human
expert.
A boom of AI (1980-1987)
Expert systems were programmed that emulate the decision-making ability of a human
expert.
In the year 1997, IBM Deep Blue became the first computer program to beat a world chess
champion.
In the year 2002, AI entered home in the form of a vacuum cleaner.
In the year 2006, AI entered business world. Companies like Facebook, Twitter and Amazon
also started using AI.
Future AI
6
Robotic Vehicles
Driverless Cars
Autonomous Planning and Scheduling
Speech Recognition
Games
Spam Fighting
Logistics Planning
Robotics etc.,
INTELLIGENT AGENTS
AGENTS and ENVIRONMENTS
What is an Agent?
7
An Agent can be one of the following:
Agent
On screen
AI TERMINOLOGY
1) PERCEPT
the term percept refers to the agent’s perceptual inputs at any given instant
examples
Structure of an AI Agent
8
Example
A rational agent is one that does the right thing. It is the ability of a system for being reasonable,
sensible and having good sense of judgment.
9
NATURE OF ENVIRONMENTS
An environment in artificial intelligence is the surrounding of the agent. The agent takes input
from the environment through sensors and delivers the output to the environment through
actuators.
PEAS DESCRIPTION:
To design a rational agent, we must specify the task environment called as PEAS.
o P - Performance
o E – Environment
o A – Actuators
o S – Sensors
The PEAS description for various agents are as follows:
10
TYPES OF TASK ENVIRONMENT / PROPERTIES OF TASK ENVIRONMENT
11
6. Discrete vs. Continuous
Discrete : The environment consists of finite number of percepts and actions
o Example : Chess
Continuous : The environment in which the actions are performed cannot be numbered/
o Example: Self Driving Cars
7. Known vs. Unknown
Known : The result for all actions are known
o Example: Cards
Unknown: The agent make a decision and act by learning how it works
o Example: Video Games
12
1. SIMPLE REFLEX AGENTS
They use a model of the world to choose their actions. They maintain an internal
state.
o Model − knowledge about “how the things happen in the world”.
o Internal State − It is a representation of unobserved aspects of current
state depending on percept history.
Updating the state requires the information about −
o How the world evolves.
o How the agent’s actions affect the world.
13
3. GOAL BASED AGENTS
They choose their actions in order to achieve goals.
Goal-based approach is more flexible than reflex agent since the knowledge
supporting a decision is explicitly modeled, thereby allowing for modifications.
Goal − It is the description of desirable situations.
14
5. LEARNING AGENT
A learning agent in AI is the type of agent that can learn from its past experiences,
or has learning capabilities.
It starts to act with basic knowledge and then is able to act and adapt automatically
through learning.
A learning agent has mainly four conceptual components, which are:
1. Learning element: It is responsible for making improvements by learning
from the environment
2. Critic: The learning element takes feedback from the critic which describes
how well the agent is doing with respect to a fixed performance standard.
3. Performance element: It is responsible for selecting external action
4. Problem generator: This component is responsible for suggesting actions that
will lead to new and informative experiences.
Hence, learning agents are able to learn, analyze performance, and look for new
ways to improve the performance
15
PROBLEM-SOLVING AGENTS
The problem-solving agent performs precisely by defining problems and its several solutions.
A problem-solving agent is a goal-driven agent and focuses on satisfying the goal.
Goal Formulation: It is the first and simplest step in problem-solving. It organizes the
steps/sequence required to formulate one goal out of multiple goals as well as actions to achieve
that goal. Goal formulation is based on the current situation and the agent’s performance measure.
Problem Formulation: It is the most important step of problem-solving which decides what actions
should be taken to achieve the formulated goal. There are following five components involved in
problem formulation:
Initial State: It is the starting state or initial step of the agent towards its goal.
Path cost: It assigns a numeric cost to each path that follows the goal. The problem-solving agent
selects a cost function, which reflects its performance measure. Remember, an optimal solution
has the lowest path cost among all the solutions.
State Space: Initial state, actions, and transition model together define the state-space of the
problem implicitly. State-space of a problem is a set of all states which can be reached from the
initial state followed by any sequence of actions. The state-space forms a directed map or graph
where nodes are the states, links between the nodes are actions, and the path is a sequence of
states connected by the sequence of actions.
Search: It identifies all the best possible sequence of actions to reach the goal state from the
current state. It takes a problem as an input and returns solution as its output.
Solution: It finds the best algorithm out of various algorithms, which may be proven as the best
optimal solution.
Execution: It executes the best optimal solution from the searching algorithms to reach the goal
state from the current state.
16
PROBLEM SOLVING APPROACH TO TYPICAL AI PROBLEMS
Problems are the issues which come across any system. A solution is needed to solve that particular
problem.
17
Two types of Problem Approaches:
1. Toy Problems
It is a concise and exact description of the problem which is used by the
researchers to compare the performance of algorithms.
Examples : 8 puzzle problem, N queens problem, Tic Tac Toe and Towers of
Hanoi
2. Real World Problems
It is real-world based problems which require solutions.
Unlike a toy problem, it does not depend on descriptions, but we can have a
general formulation of the problem.
Example: Route finding problem, Travelling Salesman Problem
EXAMPLE PROBLEMS
8 PUZZLE PROBLEM
Our objective is to convert the current (Start) state into goal state by sliding digits into the
blank space.
States: It describes the location of each numbered tiles and the blank tile.
Initial State: We can start from any state as the initial state.
Actions: Here, actions of the blank space is defined, i.e., either left, right, up or down
18
Transition Model: It returns the resulting state as per the given state and actions.
Path cost: The path cost is the number of steps in the path where the cost of each step is 1.
Solution:
N QUEENS PROBLEM
Actions: Place ‘n’ queens on n x n chessboard so that no two queens attack each other. Two Queens are
said to attack each other if they are placed in same row/column/diagonal.
Goal Test: Identify if all n queens are placed on the board such that no queens attack each other
Path Cost: Each step costs 1, so that path cost is the number of steps in the path to reach the goal
Solution:
4x4 chessboard
Since, we have to place 4 queens such as q1, q2, q3 and q4 on the chessboard, such that no two
queens attack each other. In such a conditional each queen must be placed on a different row,
i.e., we put queen "i" on row "i."
Backtracking method is used to generate the necessary solution. If the rule is violated and there
is no chance of placing a queen, backtracking is done and alternate possibilities are explored.
State Space Tree represents represents all the possible states of the problem.
20
SOLUTION FOR 4 QUEENS PROBLEM USING
BACKTRACKING
21
WATER JUG PROBLEM
Problem:
Given two jugs, a 4-gallon one and a 3-gallon one, a pump which has unlimited water
which you can use to fill the jug, and the ground on which water may be poured.
Neither jug has any measuring markings on it.
How can you get exactly 2 gallons of water in the 4-gallon jug?
Solution:
State Representation and Initial State : We will represent a state of the problem as a tuple
(x, y) where x represents the amount of water in the 4-gallon jug and y represents the
amount of water in the 3-gallon jug. Note 0 < x < 4, and 0 < y < 3.
Our initial state: (0,0)
Goal state: (2,y) where 0 <y <3.
Operators :We must design a set of operators that will take us from one state to
another:
1. Empty a jug
2. Fill a jug
3. Pour some water from one jug to another
Production Rules:
22
One Possible Solution for Water Jug Problem
0 0 Initial state
1 0 3 Fill 3 gal jug (Rule 2)
2 3 0 Pour all water from 3 gal jug to 4 gal jug(Rule 9)
3 3 3 Fill 3 gal jug (Rule 2)
4 4 2 Pour some water from the 3 gallon jug to
fill the 4 gallon jug (Rule 7)
5 0 2 Empty the 4 gallon jug (Rule 5)
6 2 0 Pour all water from 3 gal jug to 4 gal
jug(Rule 9)
Problem Formulation
• States: The state is determined by both the agent location and the dirt locations. The
agent is in one of two locations, each of which might or might not contain dirt. Thus, there
are 2 × 22 = 8 possible world states.
23
• Initial state: Any state can be designated as the initial state.
• Actions: In this simple environment, each state has just three actions: Left, Right, and
Suck.
•Transition model: The actions have their expected effects, except that moving Left in the
leftmost square, moving Right in the rightmost square, and Sucking in a clean square have
no effect.
• Goal test: This checks whether all the squares are clean.
• Path cost: Each step costs 1, so the path cost is the number of steps in the path.
24
SEARCH ALGORITHMS
Search: Search is the process of examination of states to find the path from the initial state/root
state to goal state. A search problem can have three main factors:
1. Search Space: Search space represents a set of possible solutions, which a system
may have.
25
Iterative Deepening Depth First Search
Uniform Cost Search
Bidirectional Search
• Completeness: Defines whether the algorithm guaranteed to find a solution when there is one.
• Space complexity: Defines how much memory is needed to perform the search.
Order of Traversal:
26
Example:
Which solution would BFS find to move from node S to node G if run on the graph below?
Solution. The equivalent search tree for the above graph is as follows. As BFS traverses the tree
“shallowest node first”, it would always pick the shallower branch until it reaches the solution (or
it runs out of nodes, and goes to the next branch). The optimized traversal is shown in blue arrows
27
Breadth First Search - Pseudocode :
BreadthFirstSearch(graph, start):
Depth-first search always expands the deepest node in the current frontier of the search
tree.
The search proceeds immediately to the deepest level of the search tree, where the nodes
have no successors.
As those nodes are expanded, they are dropped from the frontier, so then the search backs
ups to the next deepest node that still has unexplored successors.
Implemented using Stack.
Order of Traversal:
28
Example:
Which solution would DFS find to move from node S to node G if run on the graph below?
Solution:
The equivalent search tree for the above graph is as follows. As DFS traverses the tree “deepest
node first”, it would always pick the deeper branch until it reaches the solution (or it runs out of
nodes, and goes to the next branch). The traversal is shown in blue arrows.
Solution:
29
Depth First Search - Pseudocode:
DepthFirstSearch(graph, start):
Similar to DFS with a predetermined limit. Solves the drawback of infinite path in DFS
In this technique, the node at the depth limit will be treated as it has no successor nodes
further.
When goal is reached, the algorithm terminates.
Sometimes, DLS may be incomplete because, the goal node may not occur within the given
depth limit.
Example:
30
Performance Evaluation of DLS:
1. Completeness: The solution may or may not be obtained. So DLS is not Complete Search.
2. Optimal : Not Optimal
3. Time Complexity: O(bl) , b – no. of nodes, l- depth of the tree(given)
4. Space Complexity: O(bl) , b – no. of nodes, l- depth of the tree(given)
depth_limit=d
DepthLimitedSearch(graph, start):
31
Example:
Iteration 1:
Iteration 2:
Iteration 3:
32
Performance Evaluation of Iterative Deepening DFS:
IterativeDeepeningDFS(graph,start):
for depth = 0 to do
Example:
Which solution would UCS find to move from node S to node G if run on the graph below?
33
Solution:
The equivalent search tree for the above graph is as follows. Cost of each node is the cumulative
cost of reaching that node from the root. Based on UCS strategy, the path with least cumulative
cost is chosen.
34
while priority_queue is not empty:
Example:
35
Performance Evaluation of Bidirectional Search:
forward_current = forward_queue.dequeue()
if forward_current in backward_visited:
backward_current = backward_queue.dequeue()
if backward_current in forward_visited:
forward_visited.add(forward_current)
backward_visited.add(backward_current)
36
PART - A
Artificial Intelligence is defined as the study and design of intelligent agents, where an
intelligent agent is a system that perceives the environment and takes actions.
Knowledge is required for intelligence. Knowledge Base and electricity are required to
generate output.
No human is an expert. We may get better s Expert systems are made which aggregate many
olutions from other humans. person’s experience and ideas.
But without engineers they would have no outlet to test their Artificial Intelligence on.
Science and Engineering go hand in hand, they both benefit each other. While the engineers
build the machines, the scientists are writing code for their AI.
It is the process of deciding what actions and states to consider given a certain goal. A goal
may be set in stone, but how you achieve it can vary.
37
(5) Define Artificial Intelligence in terms of rational acting.
A field of study that seeks to explain and emulate intelligent behaviors in terms of
computational processes.
The study of the computations that make it possible to perceive, reason and act
One person will be an interrogator ( i.e.) questioner, will be asking questions to one person
and one machine.
Interrogator knows them just as A and B. so it has to identify which is the person and machine.
The goal of the machine is to make Interrogator believe that it is the person’s answer.
If machine succeeds by fooling Interrogator, the machine acts like a human. Programming a
computer to pass Turing test is very difficult.
(8) What are the capabilities, computer should possess to pass Turing test?
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.
(10) What are the capabilities computers needs to pass total Turing test?
Computer vision - to perceive objects.
38
(12) What is an agent function? Differentiate an agent function and an agent program.
An agent’s behavior is described by the agent function that maps any given percept sequence
to an action.
(13) What are the factors that a rational agent should depend on at any given time?
The performance measure that defines degree of success.
Ever thing that the agent has perceived so far. We wil cal this complete perceptual history
the percept sequence.
An Agent is anything that can be viewed as perceiving (i.e.) understanding its environment
through sensors and acting upon that environment through actuators.
39
(16) Define Ideal Rational Agent
For each possible percept sequence, an ideal rational agent should do whatever action is
expected to maximize its performance measure on the basis of the evidence provided by the
percept sequence & whatever built in knowledge that the agent has.
For example: IF the heating element glows AND the bread is always dark THEN the toaster
thermostat is broken
When the problem situation matches the IF part of a rule, the action specified by the THEN
part of the rule is performed.
Learning/reasoning
Reactivity
Autonomy
Goal-oriented
Communication
Cooperation
Mobility
Character
Online search is a good idea in dynamic or semi dynamic domains and stochastic domains.
Online search is a necessary idea for an exploration problem, where the states and actions are
unknown to the agent.
knowledge about the problem, so as to create a program for solving a problem is caled as
operationalization.
40
(21) List the major components in problem formulation in AI.
The four components are:
1. Initial state.
2. State Space
4. Path Cost
Autonomous Control
Episodic vs sequential
Static vs dynamic.
Goal-based agents
Utility-based agents
Learning agent
41
(26) What are utility based agents?
Goals alone are not really enough to generate high-quality behavior in most environments.
For example, there are many action sequences that will get the taxi to its destination (thereby
achieving the goal) but some are quicker, safer, more reliable, or cheaper than others.
A utility function maps a state (or a sequence of states) onto a real number, which describes
the associated degree of happiness.
Depth-first Search
Bidirectional Search
42