Artificial - Intelegence-1 - Autosaved
Artificial - Intelegence-1 - Autosaved
Artificial Intelligence
• AI is one of the newest sciences.
• Work started in earnest soon after World War II, and the
name itself was coined in 1956, Along with molecular biology.
• AI is regularly cited as the "field I would most like to be in" by
scientists in other disciplines.
• Definitions of artificial
• intelligence according to eight textbooks are shown in Figure
1.1. These definitions vary along two main dimensions.
• Roughly, the ones on top are concerned with
thought processes and reasoning, whereas the ones
on the bottom address behavior.
• The definitions on the left measure success in terms
of fidelity to human performance, whereas the ones
on the right
Thinking humanly: The Cognitive Modeling
• Reasons like humans do
– Programs that behave like humans
• Requires understanding of the internal activities of the
brain
– see how humans behave in certain situations and see if you
could make computers behave in that same way.
– Protocol analysis (think aloud) can help in understanding
how human beings solve a given problem
Example. write a program that plays chess.
– Instead of making the best possible chess-playing program,
you would make one that play chess like people do.
Acting humanly: The Turing Test
Can machines act like human do? Can machines
behave intelligently?
• Turing Test: Operational test for intelligent behavior
– do experiments on the ability to achieve human-level
performance,
– Acting like humans requires AI programs to interact with
people
• Suggested major components of AI: knowledge,
reasoning, language understanding, learning
How to make computers act like humans?
The following sub-fields are emerged
• Natural Language processing (enable computers communicate
in human language, English, Amharic, ..)
• Knowledge representation (schemes to store information, both
facts and inferences, before and during interrogation)
• Automated reasoning (use stored information to answer questions and
to draw new conclusions)
• Machine learning (adapt to new circumstances and accumulate
knowledge)
• Computer vision (recognize objects based on patterns in the
same way as the human visual system does)
• Robotics (produce mechanical device capable of controlled motion; which
enable computers to see, hear & take actions)
• Is AI equals human intelligence ?
Thinking Rationally: The Laws of Thought
• A system is rational if it thinks/does the right thing
through correct reasoning.
Medical No No No No No
Diagnosis
Taxi driving No No No No No
Environment
What the world
is like now
Environment
is like now
What my actions do
effectors
Environment
What my actions do
Goals
What action I
should do now
effectors
Environment
What it will be like
if I do action A
1 2 3 1 2 3
8 4 5 8 4
7 6 7 6 5
Assignment 2 August 20
Missionary-and-cannibal problem:
Three missionaries and three cannibals are on one
side of a river that they wish to cross. There is a
boat that can hold one or two people. Find an
action sequence that brings everyone safely to the
opposite bank (i.e. Cross the river). But you must
never leave a group of missionaries outnumbered
by cannibals on the same bank (in any place).
1. Identify the set of states and operators
2. Show using suitable representation the state space
of the problem
Knowledge and types of problems
• There are four types of problems:
–Single state problems (Type 1)
–Multiple state problems (Type 2)
–Exploration problems (Type 3)
–Contingency Problems (Type 4)
• This classification is based on the level of knowledge that
an agent can have concerning its action and the state of
the world
• Thus, the first step in formulating a problem for an agent
is to see what knowledge it has concerning
–The effects of its action on the environment
–Accessibility of the state of the world
• This knowledge depends on how it is connected to the
environment via its percepts and actions
Example: Vacuum world problem
To simplify the problem (rather than the full version),
let;
• The world has only two locations
– Each location may or may not contain dirt
– The agent may be in one location or the other
• Eight possible world states
• Three possible actions (Left, Right, Suck)
– Suck operator clean the dirt
– Left and Right operators move the agent from location to
location
• Goal: to clean up all the dirt
Clean House Task
Vacuum Cleaner state Space
Single state problem
• Fully observable: The world is accessible to the agent
– It can determine its exact state through its sensors
– The agent’s sensor knows which state it is in
• Deterministic: The agent knows exactly the effect of its actions
– It can then calculate exactly which state it will be in after any
sequence of actions
• Action sequence is completely planned
Example - Vacuum cleaner world
– What will happen if the agent is initially at state = 5 and
formulates action sequence - [Right, Suck]?
– Agent calculates and knows that it will get to a goal state
• Right {6}
• Suck {8}
Multiple state problems
• Partially observable: The agent has limited access to the world state
– It might not have sensors to get full access to the environment states or as
an extreme, it can have no sensors at all (due to lack of percepts)
• Deterministic: The agent knows exactly what each of its actions do
– It can then calculate which state it will be in after any sequence of actions
• If the agent has full knowledge of how its actions change the world,
but does not know of the state of the world, it can still solve the task
Example - Vacuum cleaner world
– Agent’s initial state is one of the 8 states: {1,2,3,4,5,6,7,8}
– Action sequence: {right, suck, left, suck}
– Because agent knows what its actions do, it can discover and reach to goal
state.
Right [2.4.6.8.] Suck {4,8}
Left {3,7} Suck {7}
Contingency Problems
• Partially observable: The agent has limited access to the world
state
• Non-deterministic: The agent is ignorant of the effect of its
actions
• Sometimes ignorance prevents the agent from finding a
guaranteed solution sequence.
• Suppose the agent is in Murphy’s law world
–The agent has to sense during the execution phase, since things
might have changed while it was carrying out an action. This
implies that
• the agent has to compute a tree of actions, rather than a linear
sequence of action
– Example - Vacuum cleaner world:
• action ‘Suck’ deposits dirt on the carpet, but only if there is no dirt
already. Depositing dirt rather than sucking returns from ignorance
about the effects of actions
Contingency Problems (cont…)
• Example - Vacuum cleaner world
– What will happen given initial state {1,3}, and action
sequence: [Suck, Right, Suck]?
{1,3} {5,7} {6,8} {8,6} (failure)
• Is there a way to solve this problem?
– Thus, solving this problem requires local sensing, i.e.
sensing the execution phase,
– Start from one of the states {1,3}, and take improved action
sequence [Suck, Right, Suck (only if there is dirt there)]
• Many problems in the real world are contingency
problems (exact prediction is impossible)
– For this reason many people keep their eyes open while
walking around or driving.
Exploration problem
• The agent has no knowledge of the environment
– World Partially observable : No knowledge of states
(environment)
• Unknown state space (no map, no sensor)
– Non-deterministic: No knowledge of the effects of its actions
– Problem faced by (intelligent) agents (like, newborn babies)
• This is a kind of problem in the real world rather than in a model,
which may involve significant danger for an ignorant agent. If the
agent survives, it learns about the environment
• The agent must experiment, learn and build the model of the
environment through its results, gradually, discovering
– What sort of states exist and What its action do
– Then it can use these to solve subsequent (future) problems
• 8-puzzle problem ??
Operators
• The set of possible actions available to the agent, i.e.
–which state(s) will be reached by carrying out the action in a particular
state
–A Successor function S(x)
• Is a function that returns the set of states that are reachable from a
single state by any single action/operator
• Given state x, S(x) returns the set of states reachable from x by any
single action
• Example:
–Coloring problem: Paint with black color
paint (color w, color b)
–Route finding problem: Drive through cities/places
drive (place x, place y)
–8-puzzle ??
Goal test function
• The agent execute to determine if it has reached the
goal state or not
– Is a function which determines if the state is a goal state
or not
• Example:
– Route finding problem: Reach Addis Ababa airport on
time
IsGoal(x, Addis_Ababa)
– Coloring problem: All rectangles black
IsGoal(rectangle[], n)
– 8-puzzle ??
Path cost function
• A function that assigns a cost to a path (sequence of
actions).
– Is often denoted by g. Usually, it is the sum of the costs of the
individual actions along the path (from one state to another state)
– Measure path cost of a sequence of actions in the state space.
For example, we may prefer paths with fewer or less costly
actions
• Example:
– Route finding problem:
• Path cost from initial to goal state
– Coloring problem:
• One for each transition from state to state till goal state is reached
– 8-puzzle?
Steps in problem solving
• Goal formulation
–is a step that specifies exactly what the agent is trying to achieve
–This step narrows down the scope that the agent has to look at
• Problem formulation
–is a step that puts down the actions and states that the agent has to
consider given a goal (avoiding any redundant states), like:
• the initial state
• the allowable actions etc…
• Search
–is the process of looking for the various sequence of actions that
lead to a goal state, evaluating them and choosing the optimal
sequence.
• Execute
–is the final step that the agent executes the chosen sequence of
actions to get it to the solution/goal
Assignment (End Class)
Consider one of the following problem:
– Missionary-and-cannibal problem
– Towers of Hanoi
– Tic-Tac-Toe
– Travelling sales person problem
– 8-queens
Poly
(b) After expanding poly generating a new state
Papyrus Hospital Abay-Mado
choosing one Hospital
option
• Informed search
– Greedy search
– A*-search
– Iterative improvement,
– Constraint satisfaction
– etc.
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: use queue data
structure to store the list:
–Expansion: put successors at the end of
queue
–Pop nodes from the front of the queue
•Properties:
–Takes space: keeps every node in memory
–Optimal and complete: guarantees to find
solution
Algorithm for Breadth first search
function BFS (problem){
open = (C_0); //put initial state C_0 in the List
closed = {}; /maintain list of nodes examined earlier
while (not (empty (open))) {
f = remove_first(open);
if IsGoal (f) then return (f);
closed = append (closed, f);
l = not-in-set (Successors (f), closed );
open = merge ( rest(open), l); //append to the list
}
return ('fail')
}
Uniform cost Search
•The goal of this technique is to find the shortest path to the goal
in terms of cost.
–It modifies the BFS by always expanding least-cost unexpanded
node
•Implementation: nodes in list keep track of total path length
from start to that node
–List kept in priority queue ordered by path cost
A
S S S
1 10 S
5 B 5
S G 0 A B C A B C A B C
1 5 15 5 15 15
G G G
15 5
11 11 10
C
•Properties:
–This strategy finds the cheapest solution provided the cost of a path
must never decrease as we go along the path
g(successor(n)) ≥ g(n), for every node n
–Takes space since it keeps every node in memory
Algorithm for Uniform Cost search
function uniform_cost (problem){
open = (C_0); //put initial state C_0 in the List
g(s) = 0;
closed = {}; /maintain list of nodes examined earlier
while (not (empty (open))) {
f = remove_first(open);
if IsGoal (f) then return (f);
closed = append (closed, f);
l = not-in-set (Successors (f), closed );
g(f,li) = g(f) + c(f,li);
open = merge(rest(open), l, g(f,li)); //keep the open list sorted in
ascending order by edge cost
}
return ('fail')
}
Depth-first search
•Expand one of the node at the deepest
level of the tree.
–Only when the search hits a non-goal dead end
does the search go back and expand nodes at
shallower levels
•Implementation: treat the list as stack
–Expansion: push successors at the top of stack
–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
Algorithm for Depth first search
function DFS (problem){
open = (C_0); //put initial state C_0 in the List
closed = {}; /maintain list of nodes examined earlier
while (not (empty (open))) {
f = remove_first(open);
if IsGoal (f) then return (f);
closed = append (closed, f);
l = not-in-set (Successors (f), closed );
open = merge ( rest(open), l); //prepend to the list
}
return ('fail')
}
Iterative Deepening Search (IDS)
• IDS solves the issue of choosing the best depth limit by trying all
possible depth limit:
–Perform depth-first search to a bounded depth d, starting at d = 1 and
increasing it by 1 at each iteration.
Example: for route finding problem we can take the diameter of the
state space. In our example, at most 9 steps is enough to reach any
node
• This search combines the benefits of DFS and BFS
–DFS is efficient in space, but has no path-length guarantee
–BFS finds min-step path towards the goal, but requires memory space
–IDS performs a sequence of DFS searches with increasing depth-cutoff until goal
is found
Limit=0 Limit=1 Limit=2
Algorithm for IDS
function IDS (problem){
open = (C_0); //put initial state C_0 in the List
closed = {}; /maintain list of nodes examined earlier
while (not reached maxDepth) {
while (not (empty (open))) {
f = remove_first(open);
if (IsGoal (f)) then return (f);
closed = append (closed, f);
l = not-in-set (Successors (f), closed);
if (depth(l) < maxDepth) then
open = merge (rest(open), l); //prepend to the list
}
}
return ('fail')
}
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
Bidirectional Search
• Advantages:
– Only need to go to half depth
– It can enormously reduce time complexity, but is not
always applicable
• Difficulties
– Do you really know solution? Unique?
– Cannot reverse operators
– Memory requirements may be important: Record all paths
to check they meet
• Memory intensive
1 2 3 1 2 3
7 8 4 8 4
6 5 7 6 5
83
1 2 3 GOAL 1 2 3
8 4 7 8 4
7 6 5 6 5
up
left right
1 2 3 1 2 3 1 2 3
7 8 4 7 8 4 7 4
6 5 6 5 6 8 5
84
8 Puzzle Heuristics
• Blind search techniques used an arbitrary
ordering (priority) of operations.
• Heuristic search techniques make use of
domain specific information - a heuristic.
• What heurisitic(s) can we use to decide which
8-puzzle move is “best” (worth considering
first).
85
Heuristic s Information /Manhattan Distance/
86
Heuristic For Sales Man Problem
• The straight line distance between the goal node and
different places in which the sales man person possibly can
pass through.
PEDA
Kebele 17
Newroad2 Siraamerar
Kebele8 Wisdom
Papyrus
Poly
Evaluation-function driven search
• A search strategy can be defined in terms of a node
evaluation function
• Evaluation function
– Denoted
– Defines the desirability of a node to be expanded next
• Evaluation-function driven search: expand the node
(state)
with the best evaluation-function value
• Implementation: priority queue with nodes in the
decreasing
order of their evaluation function value
Exercises Greedy Search
PEDA
Prepositional Logic
Knowledge-based agent
Any Knowledge base agent should have two important component
– Knowledge base
– Inference engine
Knowledge base (KB):
– A set of sentences that describe facts about the world in some
formal (representational) language. It is hard two represent all
general knowledge in one KB. Most of the time it is domain
specific
• Inference engine:
– A set of procedures that use the representational language to
infer new facts from known ones or answer a variety of KB
queries. Inferences typically require search. It is domain
independent
Example: MYCIN
• MYCIN: an expert system for diagnosis of bacterial infections
• Knowledge base represents
– Facts about a specific patient case
– Rules describing relations between entities in the bacterial
infection domain
• Inference engine:
– manipulates the facts and known relations to answer
diagnostic queries (consistent with findings and rules)
Knowledge representation
• The objective of knowledge representation is to express
the knowledge about the world in a computer
tractable form
• Key aspects of knowledge representation languages:
– Syntax: describes how sentences are formed in the
language
– Semantics: describes the meaning of sentences, what
is it. the sentence refers to in the real world
– Computational aspect: describes how sentences and
objects are manipulated in concordance with
semantically conventions
Many KB systems rely on some variant of logic
Logic
A formal language for expressing knowledge and ways of
reasoning.
Logic is defined by:
• A set of sentences: A sentence is constructed from a set of
primitives according to syntax rules.
• A set of interpretations: An interpretation gives a semantic to
primitives. It associates primitives with values.
• The valuation (meaning) function V
– Assigns a value (typically the truth value) to a given sentence
under some interpretation
V : sentence × interprétation → {True , False }
Example of logic
Language of numerical constraints:
• A sentence:
• An interpretation:
• Valuation (meaning) function V:
x+3≤z
x , z - variable symbols (primitives in the language)
x = 5, z = 2
Variables mapped to specific real numbers
V ( x + 3 ≤ z , I ) is False for I: x = 5, z = 2
is True for I: x = 5, z = 10
I:
Types of logic
• Different types of logics possible:
– Propositional logic
– First-order logic
– Temporal logic
– Numerical constraints logic
– Map-coloring logic
In the following:
• Propositional logic.
– Formal language for making logical inferences
– Foundations of propositional logic: George Boole (1854)
• Propositional logic P:
– defines a language for symbolic reasoning
• Proposition: a statement that is either true or false
• Examples of propositions:
– Abay is the largest river in Ethiopia.
– Ethiopia is in Europe.
– It rains outside.
– 2 is a prime number and 6 is a prime
– How are you? Not a proposition.
Propositional logic. Syntax
• Formally propositional logic P:
– Is defined by Syntax + interpretation + semantics of P
Syntax:
• Symbols (alphabet) in P:
– Constants: True, False
– Propositional symbols
Examples:
•P
• Abay is the largest river in Ethiopia.,
• It rains outside, etc.
– A set of connectives:
¬,∧ ,∨ ,⇒ ,⇔
Propositional logic. Syntax
Sentences in the propositional logic:
• Atomic sentences:
– Constructed from constants and propositional symbols
– True, False are (atomic) sentences
– or Light in the room is on, It rains outside are
(atomic) sentences
• Composite sentences:
– Constructed from valid sentences via connectives
– If are sentences then
or
are sentences
P,Q
A, B
¬A(A∧B)(A∨B)(A⇒B)(A⇔B)
(A∨B)∧(A∨¬B)
Propositional logic. Semantics.
• Entailment
• Knowledge base KB entails sentence if and only if is true in all
worlds where KB is true
Sound and complete inference.
Inference is a process by which conclusions are reached.
• We want to implement the inference process on a computer !!
Assume an inference procedure i that
• derives a sentence α from the KB :
Three approaches:
• Truth-table approach
• Inference rules
• Conversion to the inverse SAT problem
– Resolution-refutation
Truth-table approach
Problem:
• We need to check all possible interpretations for which the KB
is true (models of KB) whether α is true for each of them
Truth table:
• enumerates truth values of sentences for all possible
interpretations (assignments of True/False to propositional
symbols)
First Order Logic
• Representing knowledge with symbolic
representation has many draw backs, since
the representation doesn’t have any facility
that can represents objects and relations
between objects, variables and quantifiers in
addition to prepositions.
• FOL represents objects and relations between objects,
variables and quantifiers in addition to prepositions.
• Example
Every elephant is gray
• in prepositional logic we can represent with some
symbol either G or Q as far as the sentences have
either a true or false value. Or in prepositional logic we
can represent only facts. How ever in FOL the sentence
can be represented as :
– x elephant(x)gray(x).
There is a white dog
– x dog(X) white(X)
• It makes it possible to say that a certain property holds
of all objects, of some objects, or of no object.
• In predicates logic there are three additional notations.
• Terms: terms in first-order logic are used to represent
objects or individuals.
• Terms can be :
– a constant (designate specific object) For e.g. A, B, Smith,
Blue, john kebede etc,
– variable (designate unspecified object): x, y, z, etc, and
– Functions (designate a specific object related in a certain
way to another object, or, objects):Father Of, Colour Of,
sqrroot.
– Function can also return values
– Connectives retain connectives in prepositional logic
130
• Predicates: Predicates is defined as a relation
that binds two atoms have a value of true or
false. Used to relate one object with the other.
• A predicate can take arguments, which are
terms.
– A predicate with one argument expresses a property
of an object for e.g. Student(Bob).
– A predicate with two or more arguments expresses a
relation between objects for e.g .likes(Bob, Mary).
– Predicate with no arguments is just a simple
proposition logic.
131
Quantifiers: specify whether some or all objects
satisfy properties of relations between objects .
Two standard quantifier : Universal(For all
quantifier)
•For all quantifier
– =all quantifier and X stands for all X
– For e.g. x P(x) means “for all x, P of x is true”.
Example: Person Happy (Person)
– For all Person, Happy of person is true
– that means everyone is happy.
• Universal quantifier make statement about every
object
<variables><sentence>
Example
• Every one at Computer Science is smart.
X at(X,Computer Science) smart(X)
• All cats are mamal
X cat(X) mammal(X)
X sentence P is true iff P is true with X being each
possible object in a given universe.
• The above statement is equivalent to the
conjunction
At(Jonas, Computer Science)smart(Jonas)
At(alemu, Computer Science)smart(alemu)
At(abebe, Computer Science)smart(abebe)
At(aster, Computer Science)smart(aster) ……..
Common Mistakes to avoid
Typically is the main connective with Quantifier
Common Mistakes: The use of as the main connective with
• Example
Correct: x (StudiesAt(x;BDU))Smart(x))
“Everyone who studies at BDU is smart”
• Wrong: x (StudiesAt(x;BDU) ^ Smart(x))
• “Everyone studies at BDU and is smart”, i.e.,
• “Everyone studies at Koblenz and everyone is smart”
Existential Quantifier: Makes statement about
some object in the universe
• <variables><sentence>
• Existential Quantifier: if the statement is x
P(x) means
• “there exists at least one x for which P of x is
true”.
• Example: x Happy(x),
• If the universe of discourse is people, then this
means there is at least one happy person
136
Example: FOL Sentence
• For all X
– if (X is a rose)
– then there exists Y
• (X has Y) and (Y is a thorn)
• Every one at computer science Department is
smart.
x at(X,Computer Science) ^ samrt(X)
• Spot has sister who is cat
x sister(Spot,X) ^ cat(X)
x Sentence P is true if and only if P is true with X
being some possible object. x at(X,Computer
Science) ^ samrt(X) equivalent to the disjunction
At(jones, Computer Science) Samrt(Jones) ^
at(Kebede,Computer Science) smart(Kebede) ^……
Common mistakes to avoid
Note
^ is the main connective with
Common mistake Using ) as the main connective
with
Example
Correct: x (StudiesAt(x;computer science) ^ Smart(x))
“There is someone who studies computer science and
is smart”
Nested Quantifier
• The two quantifier may nested one over the other.
• Example for all Children Y and Parent X if X is a
parent of Y then Y is a child of X.
• XY parent(X,Y)child(Y,X)
• x Y loves(X,Y)
May be interpreted as . There is a person X who laves every one
of Y in the world
• Y X loves(Y,X)
Every one in the world have some x to love in the world
Property of Quantifier
• XY= YX
• X Y= Y X
• X Y is not equal to Y X
Eaxmples
• x yLoves(x; y)
• “There is a person who loves everyone in the world”
• y xLoves(x; y)
• “Everyone in the world is loved by at least one person”
Quantifier Duality
• xLikes(x,Bread) is the same as ¬ x¬Likes(x, Bread)
“Every body likes Bread” is equivalent to the expression
“there is no one who dislike Bread”
• xLikes(x,Injera) is the same as ¬¬Likes(x,Injera)
• “There is some one who likes injera is equivalent to the
expression “ not all person dislikes injera”
Sentence structure
• In the first order formal language the basic unit is
predicate(argument/terms) structure called sentence
of predicate facts.
• Terms refer to objects
• Example – likes(aster, chocolate)= mulu likes
chocolate
• Tall(abebe)= abebe is tall
• Terms or arguments can be any of constant symbols
such as Mulu variable symbol such as X function such
as Motherof(abebe), fatherof(fatherof(aster)
Example represent the following in
first order logic
• Everything in the garden is lovely.
• Every onle likes Cake
• Peter has some friends.
• John palys Piano or Violinn
• Some people Likes snake.
• Winston Didn’t write hamlet
• Aster has an engineer Brother.
• Every soldier has its own gun
Inference Rules
• All inference rules that works for Prepositional
logic also works for First Order Logic
First Order Logic Inference rules
• Variable substitutions
• Existential elimination.
xf(x)
__________
f (a )
– Substitutes a variable with a constant symbol that does not appear
elsewhere in the KB
x Kill(x,Victim) Kill(Murderer,Victim)
Inference with resolution rule
• Proof by refutation:
– Prove that KB , Ø a is unsatisfiable
– resolution is refutation-complete
• Main procedure (steps):
1. Convert KB , Ø a to CNF with ground terms and
universal variables only
2. Apply repeatedly the resolution rule while keeping
track and consistency of substitutions
3. Stop when empty set (contradiction) is derived or no
more new resolvents (conclusions) follow
Conversion to CNF