AI Lecture Notes Chapter 3 To 6
AI Lecture Notes Chapter 3 To 6
Chapter Three
Problem Solving :
Goal based Agents
Kedir Genna (MSc.)
Contents
1. What is a
Problem
Problem solving?
2. Problem Solving by Searching
3. Problem Formulation
4. Search Strategies
5. Avoiding Repeated States
6. Constraint Satisfaction Search
What is Problem
Problem is a collection of information that the agent will use to decide
what to do
Problems have the general form: given such-and-such information,
find x.
Problems are the issues which comes across any system.
• The problem-solving agent preforms precisely by defining problems and its several
solutions.
We assume that action costs are additive; that is, the total cost of a
path is the sum of the individual action costs.
Search Strategies
Searching algorithms are one of the most important areas of AI.
Two types
Uninformed (unguided) and Informed (little guided).
Search Strategies
The first three components of problem formulation (initial state,
actions and transition models) defines the problems’ state space.
III. Goal test: is a function which observe the current state and returns weather the goal state is achieved or not.
Search tree forms various paths from the initial state, trying to find a
path that reaches a goal state.
Each node in the search tree corresponds to a state in the state space
and the edges in the search tree correspond to actions.
The root of the tree corresponds to the initial state of the problem.
Path Cost: is a function which assign a numeric value cost to each path.
Solution: is a action sequence which leads from the start node to the goal
node.
The search tree describes paths between these states, reaching towards
the goal.
The search tree may have multiple paths to (and thus multiple nodes for)
any given state, but each node in the tree has a unique path back to the
root (as in all trees).
We can EXPAND the node, by considering the available ACTIONS for that
state, using the RESULT function to see where those actions lead to, and
GENERATING a new node (called a child node or successor node) for each
of the resulting states.
For instance Awaday is child node of a parent Harar.
Each child node has Harar as its parent node.
Suppose we choose to expand Babile first. We call this the Frontier of the search
tree. We say that any state that has had a node generated for it has been reached
(whether or not that node has been expanded)
The FRONTIER separates two regions of the state-space graph: an interior region
where every state has been expanded, and an exterior region of states that have not
yet been reached.
The following properties are essential search algorithms properties to compare the efficiency of
these algorithms.
time complexity: how many operations are needed? Is a measure of time for an algorithm to
complete its task.
space complexity: maximum number of nodes in memory. Is the maximum storage space
required at any point during the search, as the complexity of the problem.
d
m
b G
• Generally, searching strategies can be classified in to two as uninformed and informed search strategies
1. Breadth-first Search
•Expand shallowest unexpanded node,
•i.e. expand all nodes on a given level of the search tree before moving to
the next level
•Implementation: fringe/open list is a first-in-first-out (FIFO) Queue, i.e.,
•new successors go at end of the queue.
-Is A a goal state?
•Expand: -fringe = [B,C] ,Is B a goal state?
•Expand: fringe=[C,D,E],Is C a goal state?
•Expand: fringe=[D,E,F,G],is D a goal state?
• Pop nodes from the front of the queue
•Then return the final path
•{A,C,G} The solution path is recovered by following the back pointers
starting at the goal state
•Properties:
•Takes space: keeps every node in memory
•Optimal and complete: guarantees to find solution
•Properties:
• This strategy finds the cheapest solution provided the cost of a path must never decrease as
we go along the path
• Takes space since it keeps every node in memory
3. Depth-first Search
•Expand one of the node at the deepest level of the tree.
•It is called the depth-first search because it starts from the root
node and follows each path to its greatest depth node before
moving to the next path.
•Implementation: DFS uses a stack data structure for its
implementation.
•Pop nodes from the top of the stack
•Properties
•Incomplete and not optimal: fails in infinite-depth spaces,
spaces with loops.
• Modify to avoid repeated states along the path
•Takes less space (Linear): Only needs to remember up to the
depth expanded,
4. Depth-Limited Search
• Search depth-first, but terminate a path either if a goal state is found, or if the
maximum depth allowed is reached.
• Avoids the problem of search never terminating by imposing a hard limit on the
depth of any search path
•However, it is still not complete(the goal depth may be greater than the limit allowed.
6. Bidirectional Search
Simultaneously search both forward from the initial state to the goal and
backward from the goal to the initial state, and stop when the two
searches meet somewhere in the middle
Requires an explicit goal state and invertible operators (or backward chaining).
Decide what kind of search is going to take place in each half using BFS, DFS,
uniform cost search, etc.
Start Goal
• Difficulties
• Do you really know solution? Unique?
• Cannot reverse operators
• Memory requirements may be important: Record all paths to check
they meet
• Memory intensive
• b is branching factor,
• d is depth of the shallowest solution,
• m is the maximum depth of the search tree,
• l is the depth limit
A B C
3 9
7 4
5
D E G
Informed Search
•Search efficiency would improve greatly if there is a way to order
the choices so that the most promising are explored first.
•This requires domain knowledge of the problem.
•Add domain specific knowledge to select what is the best one to
continue searching along the path
•Define a heuristic function, h(n) that estimates the goodness of a node
n, based on domain specific information that is computable from the
current state description.
•Heuristics is knowledge about the domain that helps to undertake
focused search.
……Informed Search
• Informed search algorithms attempt to use extra domain knowledge to inform the
search, in an attempt to reduce search time.
• A particular class of informed search algorithms is known as best-first
search.
• In best-first search, we use a heuristic function to estimate which of the
nodes in the fringe is the “best” node for expansion.
• This heuristic function, h(n), estimates the cost of the cheapest path from
node n to the goal state. In other words, it tells us which of the nodes in
the fringe it think is “closest” to the goal.
• best-first search algorithms examples are :-
• greedy best-first and A* search.
That means the agent prefers to choose the action which is assumed to
be best after every action
f(n)= h(n)
# of nodes tested 1, S
h=8
expanded 1 1 8
5
A B C
h=8 h=4 h=3
Expanded Node OPEN list 9 4
3
(S:8) 7 5
f(n)= h(n)
# of nodes tested 2, expanded 2
S
h=8
Expanded Node OPEN list
1 8
(S:8) 5
A B C
S (C:3,B:4,A:8) h=4
h=8 h=3
C not goal (G:0,B:4,A:8) 9 4
3
7 5
D G
E
h= h=0
h=
S (C:3,B:4,A:8) A B C
h=8 h=4 h=3
C (G:0,B:4,A:8)
G goal (B:4.A:8) 9 4
3
7 5
D G
E
* Fast but not optimal h= h=
h=0
Path: S,C,G
Cost: 13
A* Search
Idea: avoid expanding paths that are already expensive
Evaluation function f(n) = g(n) + h(n) where
g(n) = cost so far to reach n
h(n) = estimated cost from n to goal
f(n) = estimated total cost of path through n to goal
It tries to minimizes the total path cost to reach into the
goal at every node N.
……. A* Search
example
Heuristic
• Given the following tree structure, show the content of the
open list and closed list generated by A* best first search S G -------------- 90
algorithm A G -------------- 70
B G -------------- 70
S
70
35
40
C G -------------- 60
A B C D G -------------- 55
25 10 62 45
18 21 E G -------------- 30
D E F G1 H F G -------------- 35
15 20 5 H G ---------------10
I G3 J I G ---------------- 20
J G ---------------- 8
G1,G2,G3 G ------------ 0
Admissible heuristic
A heuristic h(n) is admissible if for every node n,
h(n) ≤ h*(n), where h*(n) is the true cost to reach the goal state
from n.
An admissible heuristic never overestimates the cost to reach the
goal, i.e., it is optimistic
Example: hSLD(n) (never overestimates the actual road distance)
Theorem: If h(n) is admissible, A* using TREE-SEARCH is
optimal
C 9 3 12 6 A B C
h=8 h=4 h=3
D 6
10 5
E 12 4
6
8
G 12/11/15 0 12/11/15 0 D E
G
h= h=0
h=
Exercise
• Consider the following state space.
• There are five locations, identified by the letters A to E, and the
numbers shown are the step costs to move between them.
• Also shown is the value of a heuristic function for each state:
• the straight-line distance to reach E.
• The initial state of the problem is A, and the goal is to reach E
……. Exercise
1. Draw the search tree that would result after each iteration
of greedy best-first search. Is the solution optimal?
2. Draw the search tree that would result after each iteration
of A* search. Is the solution optimal
Chapter Four
Knowledge Based Agents
Kedir Genna (MSc.)
Contents
1. Logical Agents
2. Propositional Logic
3. Inference in Propositional Logic
4. Predicate (First-order) Logic
5. Inference in first-order logic
6. Knowledge Representation
7. Knowledge based system
Knowledge-based Agents
An intelligent agent needs knowledge about the real world for taking decisions and
reasoning to act efficiently.
Knowledge-based agents are those agents who have the capability of
Maintaining an internal state of knowledge,
Reason over that knowledge,
Update their knowledge after observations and take actions.
These agents can represent the world with some formal representation and act
intelligently.
………Knowledge-based Agents
A knowledge-based agent is an agent that consists of two parts:
a knowledge base and an inference engine
The inference engine is consists of algorithms that take the contents of the
knowledge base and infer (i.e. deduce) new knowledge about the world.
……
• The agent receives precepts from the environment they will be converted
into sentences and added to the KB
• When the agent needs to make an action, we must ask the KB what the
optimal action will be at that time
• There must be some way of telling the KB a new piece of information;
• and there must be some way of asking the KB some question about the environment
Logic as KR
Knowledge can also be represented by the symbols of logic, which is the
study of the rules of exact reasoning.
…….
Logic is a declarative language to assert sentences and deduce from
sentences.
Components of a formal logic
Syntax: what expressions/structures are allowed in the language. Describes how to
make sentences
E.g. red(mycar) is ok, but mycar(grey or green) is not.
Semantics: express what sentences mean, in terms of a mapping to real
world.
Semantics relate sentences to reality.
E.g. red(mycar) means that my car is red.
Proof Theory: how we can draw new conclusions from existing statements in the logic.
It is a means of carrying our reasoning using a set of rules.
Reasoning: is the process of constructing new sentences from existing facts in the
KB.
……
Logic accepted rules for making precise statements.
Logic
Represents knowledge precisely
Helps to extract information (inference)
Logical arguments
•An argument is a sequence of statements.
These connectives are also called logical operators which connects two sentences.
The propositions and connectives are the basic elements of the propositional logic.
A proposition formula which is always true is called tautology, and it is also called a valid sentence.
Statements which are questions, commands, or opinions are not propositions such as "Where is
Rohini", "How are you", "What is your name", are not propositions.
4. if the lectures are active, then the text is not readable: AR
6. if the lectures are active, then if the text is not readable, Kebede will not pass the exam:
A(R P )
Unit Resolution A B, B A
Resolution A B, B C AC
Hypothetical Syllogism PQ, QR PR
In the case of modus ponens, if A is true and A B is true, then conclude B is true.
Formal Proofs
• A proof is a sequence of sentences, where each sentence is either a
premise or a sentence derived from earlier sentences in the proof by one
of the rules of inference.
•The last sentence is the theorem (also called goal or query) that we want to
prove.
Example1: The “weather problem”. Proof whether it is raining or not.
1. Q Premise “It is humid”
2. Q P Premise “If it is humid, it is hot”
3. (PQ) R Premise “If it’s hot & humid, it’s raining”
4. P Modus Ponens(1,2) “It is hot”
5. PQ And Introduction(1,4) “It is hot and humid”
6. R Modus Ponens(3,5) “It is raining”
1. CB
2. BI
3. IS
4. (C S) (B C)
5. C
6. CI 1,2 (Hypothetical Syllogism)
7. CS 6,3 (Hypothetical Syllogism)
8. B C 7,4 (Modus Ponens)
9. B 8,5 (Modus Tollens)
………
• First, we assigned symbols to the above clues:
PL cannot handle even a domain with small worlds. The problem is that there are just too many
propositions to handle since it only has one representational device: the proposition
In PL, the world consists of just facts. It is hard to :
• Identify individuals: E.g., Mary, 3
• Describe properties of (or logical relations between) individuals. E.g. Belete is taller than Gelaw
• Generalize for a given universe. (We cannot represent relations like ALL, some, or none.)
• E.g., all triangles have 3 sides, All the girls are intelligent, Some apples are sweet.
Example: Prove that “my dog Buchi is Nice, given that “all dogs are Nice.”
•This requires to get at the structure and meanings of statements (where first order logic (FOL) is
useful).
…….FOL: Quantifiers
These are the symbols that permit to determine or identify the range and scope of
the variable in the logical expression.
There are two types of quantifier:
Universal Quantifier, (for all, everyone, everything)
Existential quantifier, (for some, at least one).
All men drink coffee.
∀x men(x) → drink (x, coffee).
It will be read as: There are all x where x is a men who drink coffee.
Some boys are intelligent.
∃x: boys(x) ∧ intelligent(x)
It will be read as: There are some x where x is a boy who is intelligent.
The main connective for universal quantifier ∀ is implication →.
The main connective for existential quantifier ∃ is and ∧.
155
Inference in FOL
• Inference in First-Order Logic is used to deduce new facts or sentences
from existing sentences.
……..
• Universal Generalization:
• Universal generalization is a valid inference rule which states that if premise P(c) is true for any
arbitrary element c in the universe of discourse, then we can have a conclusion as ∀ x P(x).
• Example: Let's represent, P(c): "A byte contains 8 bits", so for ∀ x P(x) "All bytes contain
8 bits.", it will also be true.
•Universal Elimination: If "x P(x) is true, then P(c) is true, where c is a constant in
the domain of x.
Example: "x eats(x, IceCream).
Using the substitution (x/Helen) we can infer eats(Helen, Icecream).
• The variable symbol can be replaced by any constant symbol or function symbol.
• Existential Introduction: If P(c) is true, then $x P(x) is inferred.
Example: eats(John, IceCream) we can infer $x eats(x, icecream).
• Existential Elimination: From $x P(x) infer P(c).
Example: $x eats(Sol, x) infer eats(Sol, Pizza)
Chapter Five
Learning Agents
Kedir Genna (MSc.)
Contents
1.Factors for Designing Learning Agents
2.Learning from Examples/Observations
3.Knowledge in Learning
What is learning?
•In the psychology literature, learning is considered one of
the keys to human intelligence.
•what learning is? Learning is:
• memorizing something
• Knowing facts through observation and exploration
• improving motor and/or cognitive skills through practice
• The idea behind learning is that percepts should not only be used for
acting now, but also for improving the agent’s ability to act in the
future.
……What is learning
Some Examples of learning are :
…….
In Machine Learning: learning is a two step process.
• Model construction: The training set is used to create the model.
The model is represented as classification rules, decision trees, or
mathematical formulae
• A training set is a set of problem instances (described as a set of
properties and their values), together with a classification of the
instance.
• Model evaluation and usage: the test set is used to see how well
it works for classifying future or unknown objects
• Test set is a set of instances and their classifications used to test the
accuracy of a learned hypothesis.
Classification
Algorithms
Training
Data
Classifier
model
Testing
Data Unseen Data
(Jeff, Professor, 4)
NA M E RA NK Y EA RS T EN UR ED
Tom Assistant P rof 2 no Tenured?
M erlisa A ssociate P rof 7 no
G eorge Professor 5 yes
Joseph Assistant P rof 7 yes
167
Learning methods
• There are various learning methods. Popular learning techniques include
the following.
• K Nearest Neighbors:
• Decision tree : divide decision space into piecewise constant regions.
• Neural networks: partition by non-linear boundaries
• Bayesian network: a probabilistic model.
Chapter Six
Communicating, Perceiving and Acting
Kedir Genna (MSc.)
Contents
1.Natural Language Processing
2.Natural Language for Communication
3.Perception
……
CL is an interdisciplinary field dealing with the statistical and/or
rule-based modeling of natural language from a computational
perspective.
Speech Technology relates to the technologies designed to
duplicate and respond to the human voice.
to aid the voice-disabled, the hearing-disabled, the blind, and to
communicate with computers without a keyboard, to market goods or
services by telephone and to enhance game software
Consists of speech recognition, speech synthesis, speaker recognition,
speaker verification
……
Linguistics:
What are suitable description levels for language?
What are the rules of a language?
How meaning is established and communicated?
What have languages in common? How do they differ?
How languages can be learnt?